diff --git a/hideout-core/build.gradle.kts b/hideout-core/build.gradle.kts index 7bce0576..16c35e50 100644 --- a/hideout-core/build.gradle.kts +++ b/hideout-core/build.gradle.kts @@ -260,6 +260,14 @@ detekt { autoCorrect = true } +configurations.matching { it.name == "detekt" }.all { + resolutionStrategy.eachDependency { + if (requested.group == "org.jetbrains.kotlin") { + useVersion(io.gitlab.arturbosch.detekt.getSupportedKotlinVersion()) + } + } +} + tasks.withType { exclude("**/generated/**") doFirst { diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/Constant.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/Constant.kt index 451e24d9..6c19c683 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/Constant.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/Constant.kt @@ -38,4 +38,4 @@ object Constant { ) ) ) -} \ No newline at end of file +} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/StringOrObject.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/StringOrObject.kt index b419bf79..3a9969db 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/StringOrObject.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/StringOrObject.kt @@ -41,14 +41,9 @@ open class StringOrObject { return result } - override fun toString(): String { - return "StringOrObject(contextString=$contextString, contextObject=$contextObject)" - } - - + override fun toString(): String = "StringOrObject(contextString=$contextString, contextObject=$contextObject)" } - class StringOrObjectDeserializer : JsonDeserializer() { override fun deserialize(p: JsonParser?, ctxt: DeserializationContext): StringOrObject { val readTree: JsonNode = p?.codec?.readTree(p) ?: return StringOrObject("") @@ -64,7 +59,6 @@ class StringOrObjectDeserializer : JsonDeserializer() { StringOrObject("") } } - } class StringORObjectSerializer : JsonSerializer() { diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APSendUndoServiceImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APSendUndoServiceImpl.kt index 576e9463..37326c0d 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APSendUndoServiceImpl.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APSendUndoServiceImpl.kt @@ -47,5 +47,4 @@ class APSendUndoServiceImpl( owlProducer.publishTask(deliverUndoTask) } - } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/config/ActivityPubConfig.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/config/ActivityPubConfig.kt index e77dd1d7..afe658a1 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/config/ActivityPubConfig.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/config/ActivityPubConfig.kt @@ -42,7 +42,6 @@ class ActivityPubConfig { @Bean @Qualifier("activitypub") fun objectMapper(): ObjectMapper { - val module = SimpleModule().addSerializer(StringOrObject::class.java, StringORObjectSerializer()) val objectMapper = jacksonObjectMapper() diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/config/SecurityConfig.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/config/SecurityConfig.kt index 22037168..e34fc87c 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/config/SecurityConfig.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/config/SecurityConfig.kt @@ -26,7 +26,6 @@ import com.nimbusds.jose.proc.SecurityContext import dev.usbharu.hideout.activitypub.domain.model.StringORObjectSerializer import dev.usbharu.hideout.activitypub.domain.model.StringOrObject import dev.usbharu.hideout.application.external.Transaction -import dev.usbharu.hideout.application.infrastructure.springframework.RoleHierarchyAuthorizationManagerFactory import dev.usbharu.hideout.core.domain.model.actor.ActorRepository import dev.usbharu.hideout.core.infrastructure.springframework.httpsignature.HttpSignatureFilter import dev.usbharu.hideout.core.infrastructure.springframework.httpsignature.HttpSignatureHeaderChecker @@ -204,7 +203,6 @@ class SecurityConfig { @Order(5) fun defaultSecurityFilterChain( http: HttpSecurity, - rf: RoleHierarchyAuthorizationManagerFactory, ): SecurityFilterChain { http { authorizeHttpRequests { diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/config/SpringConfig.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/config/SpringConfig.kt index b2178286..8f1b97ce 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/config/SpringConfig.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/application/config/SpringConfig.kt @@ -45,7 +45,7 @@ class SpringConfig { @ConfigurationProperties("hideout") data class ApplicationConfig( val url: URL, - val private:Boolean = true + val private: Boolean = true, ) @ConfigurationProperties("hideout.storage.s3") diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt index 6e11792e..2cd1d39b 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/Post.kt @@ -204,7 +204,6 @@ data class Post private constructor( ) return post } - } fun isPureRepost(): Boolean = @@ -214,11 +213,7 @@ data class Post private constructor( this.replyId == null && this.repostId != null - fun delete(): Post { - return copy(deleted = true) - } + fun delete(): Post = copy(deleted = true) - fun restore(): Post { - return copy(deleted = false) - } + fun restore(): Post = copy(deleted = false) } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostRepository.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostRepository.kt index b6ced0ac..561911f9 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostRepository.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/domain/model/post/PostRepository.kt @@ -18,7 +18,7 @@ package dev.usbharu.hideout.core.domain.model.post import org.springframework.stereotype.Repository -@Suppress("LongParameterList") +@Suppress("LongParameterList", "TooManyFunctions") @Repository interface PostRepository { suspend fun generateId(): Long diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/UpdateActorTask.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/UpdateActorTask.kt index 8416e8a3..5fc1a272 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/UpdateActorTask.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/job/UpdateActorTask.kt @@ -25,9 +25,8 @@ data class UpdateActorTask( val apId: String, ) : Task() - @Component data object UpdateActorTaskDef : TaskDefinition { override val type: Class get() = UpdateActorTask::class.java -} \ No newline at end of file +} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/PostResultRowMapper.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/PostResultRowMapper.kt index b912e929..b18690e3 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/PostResultRowMapper.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/PostResultRowMapper.kt @@ -26,7 +26,6 @@ import org.springframework.stereotype.Component @Component class PostResultRowMapper(private val postBuilder: Post.PostBuilder) : ResultRowMapper { override fun map(resultRow: ResultRow): Post { - return postBuilder.of( id = resultRow[Posts.id], actorId = resultRow[Posts.actorId], diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/DeletedActorRepositoryImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/DeletedActorRepositoryImpl.kt index 52398cf4..41bd924b 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/DeletedActorRepositoryImpl.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/DeletedActorRepositoryImpl.kt @@ -82,12 +82,12 @@ fun ResultRow.toDeletedActor(): DeletedActor = deletedActor(this) private fun deletedActor(singleOr: ResultRow): DeletedActor { return DeletedActor( - singleOr[DeletedActors.id], - singleOr[DeletedActors.name], - singleOr[DeletedActors.domain], - singleOr[DeletedActors.publicKey], - singleOr[DeletedActors.apId], - singleOr[DeletedActors.deletedAt] + id = singleOr[DeletedActors.id], + name = singleOr[DeletedActors.name], + domain = singleOr[DeletedActors.domain], + apiId = singleOr[DeletedActors.publicKey], + publicKey = singleOr[DeletedActors.apId], + deletedAt = singleOr[DeletedActors.deletedAt] ) } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/PostRepositoryImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/PostRepositoryImpl.kt index c2dbcd28..96180244 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/PostRepositoryImpl.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/PostRepositoryImpl.kt @@ -110,7 +110,8 @@ class PostRepositoryImpl( override suspend fun saveAll(posts: List) { Posts.batchUpsert( - posts, id, + posts, + id, ) { this[id] = it.id this[actorId] = it.actorId @@ -128,7 +129,8 @@ class PostRepositoryImpl( } val mediaIds = posts.flatMap { post -> post.mediaIds.map { post.id to it } } PostsMedia.batchUpsert( - mediaIds, PostsMedia.postId + mediaIds, + PostsMedia.postId ) { this[PostsMedia.postId] = it.first this[PostsMedia.mediaId] = it.second diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/AuthController.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/AuthController.kt index bbda1b84..5951928c 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/AuthController.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/AuthController.kt @@ -41,7 +41,7 @@ class AuthController( } @PostMapping("/auth/sign_up") - suspend fun signUp(@Validated @ModelAttribute signUpForm: SignUpForm, model: Model): String { + suspend fun signUp(@Validated @ModelAttribute signUpForm: SignUpForm): String { val registerAccount = authApiService.registerAccount( RegisterAccountDto( signUpForm.username, diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/auth/AuthApiService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/auth/AuthApiService.kt index e4ca5a32..130ef8a8 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/auth/AuthApiService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/auth/AuthApiService.kt @@ -20,4 +20,4 @@ import dev.usbharu.hideout.core.domain.model.actor.Actor interface AuthApiService { suspend fun registerAccount(registerAccountDto: RegisterAccountDto): Actor -} \ No newline at end of file +} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/auth/AuthApiServiceImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/auth/AuthApiServiceImpl.kt index bfdd81d1..b1a2c6ed 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/auth/AuthApiServiceImpl.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/auth/AuthApiServiceImpl.kt @@ -33,20 +33,22 @@ class AuthApiServiceImpl( private val httpClient: HttpClient, private val captchaConfig: CaptchaConfig, private val objectMapper: ObjectMapper, - private val userService: UserService + private val userService: UserService, ) : AuthApiService { override suspend fun registerAccount(registerAccountDto: RegisterAccountDto): Actor { if (captchaConfig.reCaptchaSecretKey != null && captchaConfig.reCaptchaSiteKey != null) { val get = - httpClient.get("https://www.google.com/recaptcha/api/siteverify?secret=" + captchaConfig.reCaptchaSecretKey + "&response=" + registerAccountDto.recaptchaResponse) + httpClient.get( + "https://www.google.com/recaptcha/api/siteverify?secret=" + + captchaConfig.reCaptchaSecretKey + "&response=" + registerAccountDto.recaptchaResponse + ) val recaptchaResult = objectMapper.readValue(get.bodyAsText()) logger.debug("reCAPTCHA: {}", recaptchaResult) require(recaptchaResult.success) require(!(recaptchaResult.score < 0.5)) } - val createLocalUser = userService.createLocalUser( UserCreateDto( registerAccountDto.username, @@ -62,4 +64,4 @@ class AuthApiServiceImpl( companion object { private val logger = LoggerFactory.getLogger(AuthApiServiceImpl::class.java) } -} \ No newline at end of file +} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/auth/RegisterAccountDto.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/auth/RegisterAccountDto.kt index fec3ced4..c44c291c 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/auth/RegisterAccountDto.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/auth/RegisterAccountDto.kt @@ -17,7 +17,7 @@ package dev.usbharu.hideout.core.service.auth data class RegisterAccountDto( - val username:String, - val password:String, - val recaptchaResponse:String + val username: String, + val password: String, + val recaptchaResponse: String, ) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/post/PostServiceImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/post/PostServiceImpl.kt index eb5c2dff..d1d7a136 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/post/PostServiceImpl.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/post/PostServiceImpl.kt @@ -91,7 +91,6 @@ class PostServiceImpl( postRepository.findByActorId(actorId).filterNot { it.deleted }.forEach { postRepository.save(it.delete()) } - actorRepository.save(actor.copy(postsCount = 0, lastPostDate = null)) } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserServiceImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserServiceImpl.kt index f69e9510..889c5257 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserServiceImpl.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserServiceImpl.kt @@ -156,12 +156,12 @@ class UserServiceImpl( override suspend fun deleteRemoteActor(actorId: Long) { val actor = actorRepository.findByIdWithLock(actorId) ?: throw UserNotFoundException.withId(actorId) val deletedActor = DeletedActor( - actor.id, - actor.name, - actor.domain, - actor.url, - actor.publicKey, - Instant.now() + id = actor.id, + name = actor.name, + domain = actor.domain, + apiId = actor.url, + publicKey = actor.publicKey, + deletedAt = Instant.now() ) relationshipRepository.deleteByActorIdOrTargetActorId(actorId, actorId) @@ -186,12 +186,12 @@ class UserServiceImpl( val actor = actorRepository.findByIdWithLock(userId) ?: throw UserNotFoundException.withId(userId) apSendDeleteService.sendDeleteActor(actor) val deletedActor = DeletedActor( - actor.id, - actor.name, - actor.domain, - actor.url, - actor.publicKey, - Instant.now() + id = actor.id, + name = actor.name, + domain = actor.domain, + apiId = actor.url, + publicKey = actor.publicKey, + deletedAt = Instant.now() ) relationshipRepository.deleteByActorIdOrTargetActorId(userId, userId) diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/mastodon/domain/exception/MastodonApiException.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/mastodon/domain/exception/MastodonApiException.kt index 4a13854a..c3afd55a 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/mastodon/domain/exception/MastodonApiException.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/mastodon/domain/exception/MastodonApiException.kt @@ -18,6 +18,7 @@ package dev.usbharu.hideout.mastodon.domain.exception import dev.usbharu.hideout.mastodon.domain.model.MastodonApiErrorResponse +@Suppress("UnnecessaryAbstractClass") abstract class MastodonApiException : RuntimeException { val response: MastodonApiErrorResponse<*> diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/mastodon/service/account/AccountApiService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/mastodon/service/account/AccountApiService.kt index c9f15567..0e3afc2f 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/mastodon/service/account/AccountApiService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/mastodon/service/account/AccountApiService.kt @@ -151,7 +151,7 @@ class AccountApiServiceImpl( userService.updateUserStatistics(id) return@transaction accountService.findById(id) } - } catch (e: UserNotFoundException) { + } catch (_: UserNotFoundException) { throw AccountNotFoundException.ofId(id) } }