feat: 凍結されたユーザーの復旧に対応

This commit is contained in:
usbharu 2024-05-17 21:53:30 +09:00
parent c8294c4cb8
commit 84b038f472
4 changed files with 62 additions and 13 deletions

View File

@ -40,9 +40,13 @@ interface APUserService {
* @param targetActor 署名するユーザー * @param targetActor 署名するユーザー
* @return * @return
*/ */
suspend fun fetchPerson(url: String, targetActor: String? = null): Person suspend fun fetchPerson(url: String, targetActor: String? = null, idOverride: Long? = null): Person
suspend fun fetchPersonWithEntity(url: String, targetActor: String? = null): Pair<Person, Actor> suspend fun fetchPersonWithEntity(
url: String,
targetActor: String? = null,
idOverride: Long? = null,
): Pair<Person, Actor>
} }
@Service @Service
@ -51,7 +55,7 @@ class APUserServiceImpl(
private val transaction: Transaction, private val transaction: Transaction,
private val applicationConfig: ApplicationConfig, private val applicationConfig: ApplicationConfig,
private val apResourceResolveService: APResourceResolveService, private val apResourceResolveService: APResourceResolveService,
private val actorRepository: ActorRepository private val actorRepository: ActorRepository,
) : ) :
APUserService { APUserService {
@ -88,13 +92,17 @@ class APUserServiceImpl(
) )
} }
override suspend fun fetchPerson(url: String, targetActor: String?): Person = override suspend fun fetchPerson(url: String, targetActor: String?, idOverride: Long?): Person =
fetchPersonWithEntity(url, targetActor).first fetchPersonWithEntity(url, targetActor, idOverride).first
override suspend fun fetchPersonWithEntity(url: String, targetActor: String?): Pair<Person, Actor> { override suspend fun fetchPersonWithEntity(
url: String,
targetActor: String?,
idOverride: Long?,
): Pair<Person, Actor> {
val userEntity = actorRepository.findByUrl(url) val userEntity = actorRepository.findByUrl(url)
if (userEntity != null) { if (userEntity != null && idOverride == null) {
return entityToPerson(userEntity, userEntity.url) to userEntity return entityToPerson(userEntity, userEntity.url) to userEntity
} }
@ -104,7 +112,7 @@ class APUserServiceImpl(
val actor = actorRepository.findByUrlWithLock(id) val actor = actorRepository.findByUrlWithLock(id)
if (actor != null) { if (actor != null && idOverride == null) {
return person to actor return person to actor
} }
@ -123,13 +131,14 @@ class APUserServiceImpl(
followers = person.followers, followers = person.followers,
sharedInbox = person.endpoints["sharedInbox"], sharedInbox = person.endpoints["sharedInbox"],
locked = person.manuallyApprovesFollowers locked = person.manuallyApprovesFollowers
) ),
idOverride
) )
} }
private fun entityToPerson( private fun entityToPerson(
actorEntity: Actor, actorEntity: Actor,
id: String id: String,
) = Person( ) = Person(
type = emptyList(), type = emptyList(),
name = actorEntity.name, name = actorEntity.name,

View File

@ -26,7 +26,7 @@ interface UserService {
suspend fun createLocalUser(user: UserCreateDto): Actor suspend fun createLocalUser(user: UserCreateDto): Actor
suspend fun createRemoteUser(user: RemoteUserCreateDto): Actor suspend fun createRemoteUser(user: RemoteUserCreateDto, idOverride: Long? = null): Actor
suspend fun updateUser(userId: Long, updateUserDto: UpdateUserDto) suspend fun updateUser(userId: Long, updateUserDto: UpdateUserDto)

View File

@ -93,7 +93,7 @@ class UserServiceImpl(
return save return save
} }
override suspend fun createRemoteUser(user: RemoteUserCreateDto): Actor { override suspend fun createRemoteUser(user: RemoteUserCreateDto, idOverride: Long?): Actor {
logger.info("START Create New remote user. name: {} url: {}", user.name, user.url) logger.info("START Create New remote user. name: {} url: {}", user.name, user.url)
val deletedActor = deletedActorRepository.findByNameAndDomain(user.name, user.domain) val deletedActor = deletedActorRepository.findByNameAndDomain(user.name, user.domain)
@ -107,7 +107,7 @@ class UserServiceImpl(
val nextId = actorRepository.nextId() val nextId = actorRepository.nextId()
val userEntity = actorBuilder.of( val userEntity = actorBuilder.of(
id = nextId, id = idOverride ?: nextId,
name = user.name, name = user.name,
domain = user.domain, domain = user.domain,
screenName = user.screenName, screenName = user.screenName,

View File

@ -0,0 +1,40 @@
/*
* Copyright (C) 2024 usbharu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.usbharu.hideout.worker
import dev.usbharu.hideout.activitypub.service.objects.user.APUserService
import dev.usbharu.hideout.application.external.Transaction
import dev.usbharu.hideout.core.external.job.UpdateActorTask
import dev.usbharu.hideout.core.external.job.UpdateActorTaskDef
import dev.usbharu.owl.consumer.AbstractTaskRunner
import dev.usbharu.owl.consumer.TaskRequest
import dev.usbharu.owl.consumer.TaskResult
import org.springframework.stereotype.Component
@Component
class UpdateActorWorker(
private val transaction: Transaction,
private val apUserService: APUserService,
) : AbstractTaskRunner<UpdateActorTask, UpdateActorTaskDef>(UpdateActorTaskDef) {
override suspend fun typedRun(typedParam: UpdateActorTask, taskRequest: TaskRequest): TaskResult {
transaction.transaction {
apUserService.fetchPerson(typedParam.apId, idOverride = typedParam.id)
}
return TaskResult.ok()
}
}