From ee69e0af4153e4486936de37af445fd9717ebc9b Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Tue, 12 Dec 2023 01:32:55 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=83=95=E3=82=A9=E3=83=AD=E3=83=BC?= =?UTF-8?q?=E6=89=BF=E8=AA=8D=E5=88=B6=E3=83=A6=E3=83=BC=E3=82=B6=E3=83=BC?= =?UTF-8?q?=E3=81=8B=E3=81=AE=E6=83=85=E5=A0=B1=E3=82=92ActivityPub?= =?UTF-8?q?=E5=81=B4=E3=81=A7=E3=82=82=E6=8C=81=E3=81=9F=E3=81=9B=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/e2eTest/resources/oauth2/user.sql | 4 +-- ...iV1AccountsIdFollowPost フォローできる.sql | 6 ++--- ...でフォロワーがfollowers投稿を取得できる.sql | 11 +++----- ...証でフォロワーがpublic投稿を取得できる.sql | 12 +++------ ...でフォロワーがunlisted投稿を取得できる.sql | 11 +++----- ...稿はattachmentにDocumentとして画像が存在する.sql | 4 +-- ...イになっている投稿はinReplyToが存在する.sql | 4 +-- ...でfollowers投稿を取得しようとすると404.sql | 4 +-- .../sql/note/匿名でpublic投稿を取得できる.sql | 4 +-- .../note/匿名でunlisted投稿を取得できる.sql | 4 +-- src/intTest/resources/sql/test-user.sql | 4 +-- src/intTest/resources/sql/test-user2.sql | 4 +-- .../activitypub/domain/model/Person.kt | 26 ++++++++++++++++--- .../service/objects/user/APUserService.kt | 9 ++++--- .../hideout/core/domain/model/actor/Actor.kt | 14 +++++++--- .../exposed/UserResultRowMapper.kt | 3 ++- .../exposedrepository/ActorRepositoryImpl.kt | 3 +++ .../core/service/user/RemoteUserCreateDto.kt | 3 ++- .../core/service/user/UserServiceImpl.kt | 6 +++-- .../resources/db/migration/V1__Init_DB.sql | 1 + .../api/actor/ActorAPControllerImplTest.kt | 3 ++- .../objects/note/APNoteServiceImplTest.kt | 1 + .../core/service/user/ActorServiceTest.kt | 3 ++- .../MastodonAccountApiControllerTest.kt | 6 ++--- .../account/AccountApiServiceImplTest.kt | 4 +++ src/test/kotlin/utils/UserBuilder.kt | 7 ++--- 26 files changed, 98 insertions(+), 63 deletions(-) diff --git a/src/e2eTest/resources/oauth2/user.sql b/src/e2eTest/resources/oauth2/user.sql index 50c52058..001f51a7 100644 --- a/src/e2eTest/resources/oauth2/user.sql +++ b/src/e2eTest/resources/oauth2/user.sql @@ -1,5 +1,5 @@ insert into actors (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, - CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) + CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE, LOCKED) VALUES (1730415786666758144, 'test-user', 'localhost', 'Im test user.', 'THis account is test user.', 'http://localhost/users/test-user/inbox', 'http://localhost/users/test-user/outbox', 'http://localhost/users/test-user', @@ -43,7 +43,7 @@ Ja15+ZWbOA4vJA9pOh3x4XM= -----END PRIVATE KEY----- ', 1701398248417, 'http://localhost/users/test-user#pubkey', 'http://localhost/users/test-user/following', - 'http://localhost/users/test-users/followers', null); + 'http://localhost/users/test-users/followers', null, false); insert into user_details (actor_id, password, auto_accept_follow_request, auto_accept_followee_follow_request) values ( 1730415786666758144 diff --git a/src/intTest/resources/sql/accounts/apiV1AccountsIdFollowPost フォローできる.sql b/src/intTest/resources/sql/accounts/apiV1AccountsIdFollowPost フォローできる.sql index a749a39a..a736a29c 100644 --- a/src/intTest/resources/sql/accounts/apiV1AccountsIdFollowPost フォローできる.sql +++ b/src/intTest/resources/sql/accounts/apiV1AccountsIdFollowPost フォローできる.sql @@ -1,16 +1,16 @@ insert into "actors" (id, name, domain, screen_name, description, inbox, outbox, url, public_key, private_key, - created_at, key_id, following, followers, instance) + created_at, key_id, following, followers, instance, locked) VALUES (3733363, 'follow-test-user-1', 'example.com', 'follow-test-user-1-name', '', 'https://example.com/users/follow-test-user-1/inbox', 'https://example.com/users/follow-test-user-1/outbox', 'https://example.com/users/follow-test-user-1', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', '-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----', 12345678, 'https://example.com/users/follow-test-user-1#pubkey', 'https://example.com/users/follow-test-user-1/following', - 'https://example.com/users/follow-test-user-1/followers', null), + 'https://example.com/users/follow-test-user-1/followers', null, false), (37335363, 'follow-test-user-2', 'example.com', 'follow-test-user-2-name', '', 'https://example.com/users/follow-test-user-2/inbox', 'https://example.com/users/follow-test-user-2/outbox', 'https://example.com/users/follow-test-user-2', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', '-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----', 12345678, 'https://example.com/users/follow-test-user-2#pubkey', 'https://example.com/users/follow-test-user-2/following', - 'https://example.com/users/follow-test-user-2/followers', null); + 'https://example.com/users/follow-test-user-2/followers', null, false); diff --git a/src/intTest/resources/sql/note/httpSignature認証でフォロワーがfollowers投稿を取得できる.sql b/src/intTest/resources/sql/note/httpSignature認証でフォロワーがfollowers投稿を取得できる.sql index 87509d2d..74a08848 100644 --- a/src/intTest/resources/sql/note/httpSignature認証でフォロワーがfollowers投稿を取得できる.sql +++ b/src/intTest/resources/sql/note/httpSignature認証でフォロワーがfollowers投稿を取得できる.sql @@ -1,23 +1,20 @@ insert into "actors" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, - CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) + CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE, LOCKED) VALUES (8, 'test-user8', 'example.com', 'Im test-user8.', 'THis account is test-user8.', 'https://example.com/users/test-user8/inbox', 'https://example.com/users/test-user8/outbox', 'https://example.com/users/test-user8', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', '-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----', 12345678, 'https://example.com/users/test-user8#pubkey', 'https://example.com/users/test-user8/following', - 'https://example.com/users/test-user8/followers', null); - -insert into "actors" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, - CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) -VALUES (9, 'test-user9', 'follower.example.com', 'Im test-user9.', 'THis account is test-user9.', + 'https://example.com/users/test-user8/followers', null, false), + (9, 'test-user9', 'follower.example.com', 'Im test-user9.', 'THis account is test-user9.', 'https://follower.example.com/users/test-user9/inbox', 'https://follower.example.com/users/test-user9/outbox', 'https://follower.example.com/users/test-user9', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', null, 12345678, 'https://follower.example.com/users/test-user9#pubkey', 'https://follower.example.com/users/test-user9/following', - 'https://follower.example.com/users/test-user9/followers', null); + 'https://follower.example.com/users/test-user9/followers', null, false); insert into relationships (actor_id, target_actor_id, following, blocking, muting, follow_request, ignore_follow_request) diff --git a/src/intTest/resources/sql/note/httpSignature認証でフォロワーがpublic投稿を取得できる.sql b/src/intTest/resources/sql/note/httpSignature認証でフォロワーがpublic投稿を取得できる.sql index b4a0201d..f5e41dd3 100644 --- a/src/intTest/resources/sql/note/httpSignature認証でフォロワーがpublic投稿を取得できる.sql +++ b/src/intTest/resources/sql/note/httpSignature認証でフォロワーがpublic投稿を取得できる.sql @@ -1,24 +1,20 @@ insert into "actors" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, - CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) + CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE, LOCKED) VALUES (4, 'test-user4', 'example.com', 'Im test user4.', 'THis account is test user4.', 'https://example.com/users/test-user4/inbox', 'https://example.com/users/test-user4/outbox', 'https://example.com/users/test-user4', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', '-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----', 12345678, 'https://example.com/users/test-user4#pubkey', 'https://example.com/users/test-user4/following', - 'https://example.com/users/test-user4/followers', null); - -insert into "actors" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, - CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) -VALUES (5, 'test-user5', 'follower.example.com', 'Im test user5.', 'THis account is test user5.', - + 'https://example.com/users/test-user4/followers', null, false), + (5, 'test-user5', 'follower.example.com', 'Im test user5.', 'THis account is test user5.', 'https://follower.example.com/users/test-user5/inbox', 'https://follower.example.com/users/test-user5/outbox', 'https://follower.example.com/users/test-user5', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', null, 12345678, 'https://follower.example.com/users/test-user5#pubkey', 'https://follower.example.com/users/test-user5/following', - 'https://follower.example.com/users/test-user5/followers', null); + 'https://follower.example.com/users/test-user5/followers', null, false); insert into relationships (actor_id, target_actor_id, following, blocking, muting, follow_request, ignore_follow_request) diff --git a/src/intTest/resources/sql/note/httpSignature認証でフォロワーがunlisted投稿を取得できる.sql b/src/intTest/resources/sql/note/httpSignature認証でフォロワーがunlisted投稿を取得できる.sql index a90569a1..3c40f0ca 100644 --- a/src/intTest/resources/sql/note/httpSignature認証でフォロワーがunlisted投稿を取得できる.sql +++ b/src/intTest/resources/sql/note/httpSignature認証でフォロワーがunlisted投稿を取得できる.sql @@ -1,23 +1,20 @@ insert into "actors" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, - CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) + CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE, LOCKED) VALUES (6, 'test-user6', 'example.com', 'Im test-user6.', 'THis account is test-user6.', 'https://example.com/users/test-user6/inbox', 'https://example.com/users/test-user6/outbox', 'https://example.com/users/test-user6', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', '-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----', 12345678, 'https://example.com/users/test-user6#pubkey', 'https://example.com/users/test-user6/following', - 'https://example.com/users/test-user6/followers', null); - -insert into "actors" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, - CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) -VALUES (7, 'test-user7', 'follower.example.com', 'Im test-user7.', 'THis account is test-user7.', + 'https://example.com/users/test-user6/followers', null, false), + (7, 'test-user7', 'follower.example.com', 'Im test-user7.', 'THis account is test-user7.', 'https://follower.example.com/users/test-user7/inbox', 'https://follower.example.com/users/test-user7/outbox', 'https://follower.example.com/users/test-user7', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', null, 12345678, 'https://follower.example.com/users/test-user7#pubkey', 'https://follower.example.com/users/test-user7/following', - 'https://follower.example.com/users/test-user7/followers', null); + 'https://follower.example.com/users/test-user7/followers', null, false); insert into relationships (actor_id, target_actor_id, following, blocking, muting, follow_request, ignore_follow_request) diff --git a/src/intTest/resources/sql/note/メディア付き投稿はattachmentにDocumentとして画像が存在する.sql b/src/intTest/resources/sql/note/メディア付き投稿はattachmentにDocumentとして画像が存在する.sql index 499595c8..edc35707 100644 --- a/src/intTest/resources/sql/note/メディア付き投稿はattachmentにDocumentとして画像が存在する.sql +++ b/src/intTest/resources/sql/note/メディア付き投稿はattachmentにDocumentとして画像が存在する.sql @@ -1,12 +1,12 @@ insert into "actors" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, - CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) + CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE, LOCKED) VALUES (11, 'test-user11', 'example.com', 'Im test-user11.', 'THis account is test-user11.', 'https://example.com/users/test-user11/inbox', 'https://example.com/users/test-user11/outbox', 'https://example.com/users/test-user11', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', '-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----', 12345678, 'https://example.com/users/test-user11#pubkey', 'https://example.com/users/test-user11/following', - 'https://example.com/users/test-user11/followers', null); + 'https://example.com/users/test-user11/followers', null, false); insert into POSTS (ID, actor_id, OVERVIEW, TEXT, "CREATED_AT", VISIBILITY, URL, "REPOST_ID", "REPLY_ID", SENSITIVE, AP_ID) diff --git a/src/intTest/resources/sql/note/リプライになっている投稿はinReplyToが存在する.sql b/src/intTest/resources/sql/note/リプライになっている投稿はinReplyToが存在する.sql index 76182d59..4df7c878 100644 --- a/src/intTest/resources/sql/note/リプライになっている投稿はinReplyToが存在する.sql +++ b/src/intTest/resources/sql/note/リプライになっている投稿はinReplyToが存在する.sql @@ -1,12 +1,12 @@ insert into "actors" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, - CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) + CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE, LOCKED) VALUES (10, 'test-user10', 'example.com', 'Im test-user10.', 'THis account is test-user10.', 'https://example.com/users/test-user10/inbox', 'https://example.com/users/test-user10/outbox', 'https://example.com/users/test-user10', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', '-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----', 12345678, 'https://example.com/users/test-user10#pubkey', 'https://example.com/users/test-user10/following', - 'https://example.com/users/test-user10/followers', null); + 'https://example.com/users/test-user10/followers', null, false); insert into POSTS (ID, actor_id, OVERVIEW, TEXT, "CREATED_AT", VISIBILITY, URL, "REPOST_ID", "REPLY_ID", SENSITIVE, AP_ID) diff --git a/src/intTest/resources/sql/note/匿名でfollowers投稿を取得しようとすると404.sql b/src/intTest/resources/sql/note/匿名でfollowers投稿を取得しようとすると404.sql index e97f9b2d..627372d5 100644 --- a/src/intTest/resources/sql/note/匿名でfollowers投稿を取得しようとすると404.sql +++ b/src/intTest/resources/sql/note/匿名でfollowers投稿を取得しようとすると404.sql @@ -1,12 +1,12 @@ insert into "actors" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, - CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) + CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE, LOCKED) VALUES (3, 'test-user3', 'example.com', 'Im test user3.', 'THis account is test user3.', 'https://example.com/users/test-user3/inbox', 'https://example.com/users/test-user3/outbox', 'https://example.com/users/test-user3', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', '-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----', 12345678, 'https://example.com/users/test-user3#pubkey', 'https://example.com/users/test-user3/following', - 'https://example.com/users/test-user3/followers', null); + 'https://example.com/users/test-user3/followers', null, false); insert into POSTS (ID, actor_id, OVERVIEW, TEXT, "CREATED_AT", VISIBILITY, URL, "REPOST_ID", "REPLY_ID", SENSITIVE, AP_ID) diff --git a/src/intTest/resources/sql/note/匿名でpublic投稿を取得できる.sql b/src/intTest/resources/sql/note/匿名でpublic投稿を取得できる.sql index 414a4394..22d44040 100644 --- a/src/intTest/resources/sql/note/匿名でpublic投稿を取得できる.sql +++ b/src/intTest/resources/sql/note/匿名でpublic投稿を取得できる.sql @@ -1,12 +1,12 @@ insert into actors (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, - CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) + CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE, LOCKED) VALUES (1, 'test-user', 'example.com', 'Im test user.', 'THis account is test user.', 'https://example.com/users/test-user/inbox', 'https://example.com/users/test-user/outbox', 'https://example.com/users/test-user', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', '-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----', 12345678, 'https://example.com/users/test-user#pubkey', 'https://example.com/users/test-user/following', - 'https://example.com/users/test-users/followers', null); + 'https://example.com/users/test-users/followers', null, false); insert into POSTS (ID, actor_id, OVERVIEW, TEXT, "CREATED_AT", VISIBILITY, URL, "REPOST_ID", "REPLY_ID", SENSITIVE, AP_ID) diff --git a/src/intTest/resources/sql/note/匿名でunlisted投稿を取得できる.sql b/src/intTest/resources/sql/note/匿名でunlisted投稿を取得できる.sql index 6a7dc9c5..db8674e5 100644 --- a/src/intTest/resources/sql/note/匿名でunlisted投稿を取得できる.sql +++ b/src/intTest/resources/sql/note/匿名でunlisted投稿を取得できる.sql @@ -1,12 +1,12 @@ insert into actors (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, - CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) + CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE, LOCKED) VALUES (2, 'test-user2', 'example.com', 'Im test user2.', 'THis account is test user2.', 'https://example.com/users/test-user2/inbox', 'https://example.com/users/test-user2/outbox', 'https://example.com/users/test-user2', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', '-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----', 12345678, 'https://example.com/users/test-user2#pubkey', 'https://example.com/users/test-user2/following', - 'https://example.com/users/test-user2/followers', null); + 'https://example.com/users/test-user2/followers', null, false); insert into POSTS (ID, actor_id, OVERVIEW, TEXT, "CREATED_AT", VISIBILITY, URL, "REPOST_ID", "REPLY_ID", SENSITIVE, AP_ID) diff --git a/src/intTest/resources/sql/test-user.sql b/src/intTest/resources/sql/test-user.sql index 54cb1852..f8239b21 100644 --- a/src/intTest/resources/sql/test-user.sql +++ b/src/intTest/resources/sql/test-user.sql @@ -1,9 +1,9 @@ insert into "actors" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, - CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) + CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE, LOCKED) VALUES (1, 'test-user', 'example.com', 'Im test user.', 'THis account is test user.', 'https://example.com/users/test-user/inbox', 'https://example.com/users/test-user/outbox', 'https://example.com/users/test-user', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', '-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----', 12345678, 'https://example.com/users/test-user#pubkey', 'https://example.com/users/test-user/following', - 'https://example.com/users/test-users/followers', null); + 'https://example.com/users/test-users/followers', null, false); diff --git a/src/intTest/resources/sql/test-user2.sql b/src/intTest/resources/sql/test-user2.sql index 284716cb..93a466a2 100644 --- a/src/intTest/resources/sql/test-user2.sql +++ b/src/intTest/resources/sql/test-user2.sql @@ -1,9 +1,9 @@ insert into "actors" (ID, NAME, DOMAIN, SCREEN_NAME, DESCRIPTION, INBOX, OUTBOX, URL, PUBLIC_KEY, PRIVATE_KEY, - CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE) + CREATED_AT, KEY_ID, FOLLOWING, FOLLOWERS, INSTANCE, LOCKED) VALUES (2, 'test-user2', 'example.com', 'Im test user.', 'THis account is test user.', 'https://example.com/users/test-user2/inbox', 'https://example.com/users/test-user2/outbox', 'https://example.com/users/test-user2', '-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----', '-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----', 12345678, 'https://example.com/users/test-user2#pubkey', 'https://example.com/users/test-user2/following', - 'https://example.com/users/test-user2s/followers', null); + 'https://example.com/users/test-user2s/followers', null, false); diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt index cba9eeaf..49a9f5b4 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Person.kt @@ -17,10 +17,10 @@ constructor( var publicKey: Key, var endpoints: Map = emptyMap(), var followers: String?, - var following: String? + var following: String?, + val manuallyApprovesFollowers: Boolean? = false ) : Object(add(type, "Person")), HasId, HasName { - @Suppress("CyclomaticComplexMethod", "CognitiveComplexMethod") override fun equals(other: Any?): Boolean { if (this === other) return true if (javaClass != other?.javaClass) return false @@ -40,11 +40,11 @@ constructor( if (endpoints != other.endpoints) return false if (followers != other.followers) return false if (following != other.following) return false + if (manuallyApprovesFollowers != other.manuallyApprovesFollowers) return false return true } - @Suppress("CyclomaticComplexMethod") override fun hashCode(): Int { var result = super.hashCode() result = 31 * result + name.hashCode() @@ -59,6 +59,26 @@ constructor( result = 31 * result + endpoints.hashCode() result = 31 * result + (followers?.hashCode() ?: 0) result = 31 * result + (following?.hashCode() ?: 0) + result = 31 * result + manuallyApprovesFollowers.hashCode() return result } + + override fun toString(): String { + return "Person(" + + "name='$name', " + + "id='$id', " + + "preferredUsername=$preferredUsername, " + + "summary=$summary, " + + "inbox='$inbox', " + + "outbox='$outbox', " + + "url='$url', " + + "icon=$icon, " + + "publicKey=$publicKey, " + + "endpoints=$endpoints, " + + "followers=$followers, " + + "following=$following, " + + "manuallyApprovesFollowers=$manuallyApprovesFollowers" + + ")" + + " ${super.toString()}" + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/user/APUserService.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/user/APUserService.kt index 1729c361..3b540ebb 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/user/APUserService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/objects/user/APUserService.kt @@ -68,7 +68,8 @@ class APUserServiceImpl( ), endpoints = mapOf("sharedInbox" to "${applicationConfig.url}/inbox"), followers = userEntity.followers, - following = userEntity.following + following = userEntity.following, + manuallyApprovesFollowers = userEntity.locked ) } @@ -104,7 +105,8 @@ class APUserServiceImpl( keyId = person.publicKey.id, following = person.following, followers = person.followers, - sharedInbox = person.endpoints["sharedInbox"] + sharedInbox = person.endpoints["sharedInbox"], + locked = person.manuallyApprovesFollowers ) ) } @@ -134,6 +136,7 @@ class APUserServiceImpl( ), endpoints = mapOf("sharedInbox" to "${applicationConfig.url}/inbox"), followers = actorEntity.followers, - following = actorEntity.following + following = actorEntity.following, + manuallyApprovesFollowers = actorEntity.locked ) } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt index fd2e28e3..f83fba96 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/actor/Actor.kt @@ -21,7 +21,8 @@ data class Actor private constructor( val keyId: String, val followers: String? = null, val following: String? = null, - val instance: Long? = null + val instance: Long? = null, + val locked: Boolean ) { @@ -46,7 +47,8 @@ data class Actor private constructor( keyId: String, following: String? = null, followers: String? = null, - instance: Long? = null + instance: Long? = null, + locked: Boolean ): Actor { // idは0未満ではいけない require(id >= 0) { "id must be greater than or equal to 0." } @@ -137,7 +139,8 @@ data class Actor private constructor( keyId = keyId, followers = followers, following = following, - instance = instance + instance = instance, + locked ) } } @@ -158,7 +161,10 @@ data class Actor private constructor( "keyId='$keyId', " + "followers=$followers, " + "following=$following, " + - "instance=$instance" + + "instance=$instance, " + + "locked=$locked" + ")" } + + } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/UserResultRowMapper.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/UserResultRowMapper.kt index 01958b82..abf8d880 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/UserResultRowMapper.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposed/UserResultRowMapper.kt @@ -25,7 +25,8 @@ class UserResultRowMapper(private val actorBuilder: Actor.UserBuilder) : ResultR keyId = resultRow[Actors.keyId], followers = resultRow[Actors.followers], following = resultRow[Actors.following], - instance = resultRow[Actors.instance] + instance = resultRow[Actors.instance], + locked = resultRow[Actors.locked] ) } } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ActorRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ActorRepositoryImpl.kt index 81625cd1..0eb59b59 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ActorRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/ActorRepositoryImpl.kt @@ -34,6 +34,7 @@ class ActorRepositoryImpl( it[following] = actor.following it[followers] = actor.followers it[instance] = actor.instance + it[locked] = actor.locked } } else { Actors.update({ Actors.id eq actor.id }) { @@ -51,6 +52,7 @@ class ActorRepositoryImpl( it[following] = actor.following it[followers] = actor.followers it[instance] = actor.instance + it[locked] = actor.locked } } return actor @@ -88,6 +90,7 @@ object Actors : Table("actors") { val following = varchar("following", length = 1000).nullable() val followers = varchar("followers", length = 1000).nullable() val instance = long("instance").references(Instance.id).nullable() + val locked = bool("locked") override val primaryKey: PrimaryKey = PrimaryKey(id) diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/user/RemoteUserCreateDto.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/user/RemoteUserCreateDto.kt index de85e74d..8260d050 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/user/RemoteUserCreateDto.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/user/RemoteUserCreateDto.kt @@ -12,5 +12,6 @@ data class RemoteUserCreateDto( val keyId: String, val followers: String?, val following: String?, - val sharedInbox: String? + val sharedInbox: String?, + val locked: Boolean? ) diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserServiceImpl.kt index f126fbf7..3a1d20ba 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/user/UserServiceImpl.kt @@ -49,7 +49,8 @@ class UserServiceImpl( createdAt = Instant.now(), following = "$userUrl/following", followers = "$userUrl/followers", - keyId = "$userUrl#pubkey" + keyId = "$userUrl#pubkey", + locked = false ) val save = actorRepository.save(userEntity) userDetailRepository.save(UserDetail(nextId, hashedPassword, true, true)) @@ -82,7 +83,8 @@ class UserServiceImpl( followers = user.followers, following = user.following, keyId = user.keyId, - instance = instance?.id + instance = instance?.id, + locked = user.locked ?: false ) return try { val save = actorRepository.save(userEntity) diff --git a/src/main/resources/db/migration/V1__Init_DB.sql b/src/main/resources/db/migration/V1__Init_DB.sql index 57aa0d35..9cdab874 100644 --- a/src/main/resources/db/migration/V1__Init_DB.sql +++ b/src/main/resources/db/migration/V1__Init_DB.sql @@ -30,6 +30,7 @@ create table if not exists actors "following" varchar(1000) null, followers varchar(1000) null, "instance" bigint null, + locked boolean not null, unique ("name", "domain"), constraint fk_actors_instance__id foreign key ("instance") references instance (id) on delete restrict on update restrict ); diff --git a/src/test/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/actor/ActorAPControllerImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/actor/ActorAPControllerImplTest.kt index 14283127..36cfa4c5 100644 --- a/src/test/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/actor/ActorAPControllerImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/actor/ActorAPControllerImplTest.kt @@ -59,7 +59,8 @@ class ActorAPControllerImplTest { ), endpoints = mapOf("sharedInbox" to "https://example.com/inbox"), followers = "https://example.com/users/hoge/followers", - following = "https://example.com/users/hoge/following" + following = "https://example.com/users/hoge/following", + manuallyApprovesFollowers = false ) whenever(apUserService.getPersonByName(eq("hoge"))).doReturn(person) diff --git a/src/test/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/APNoteServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/APNoteServiceImplTest.kt index f7415589..0a709b38 100644 --- a/src/test/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/APNoteServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/activitypub/service/objects/note/APNoteServiceImplTest.kt @@ -133,6 +133,7 @@ class APNoteServiceImplTest { endpoints = mapOf("sharedInbox" to "https://example.com/inbox"), followers = user.followers, following = user.following, + manuallyApprovesFollowers = false ) val apUserService = mock { diff --git a/src/test/kotlin/dev/usbharu/hideout/core/service/user/ActorServiceTest.kt b/src/test/kotlin/dev/usbharu/hideout/core/service/user/ActorServiceTest.kt index ad0959e8..9d5b6f10 100644 --- a/src/test/kotlin/dev/usbharu/hideout/core/service/user/ActorServiceTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/core/service/user/ActorServiceTest.kt @@ -79,7 +79,8 @@ class ActorServiceTest { keyId = "a", following = "", followers = "", - sharedInbox = null + sharedInbox = null, + locked = false ) userService.createRemoteUser(user) verify(actorRepository, times(1)).save(any()) diff --git a/src/test/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/account/MastodonAccountApiControllerTest.kt b/src/test/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/account/MastodonAccountApiControllerTest.kt index 895f33a4..8356f17e 100644 --- a/src/test/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/account/MastodonAccountApiControllerTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/mastodon/interfaces/api/account/MastodonAccountApiControllerTest.kt @@ -1,8 +1,8 @@ package dev.usbharu.hideout.mastodon.interfaces.api.account import dev.usbharu.hideout.application.config.ActivityPubConfig +import dev.usbharu.hideout.domain.mastodon.model.generated.AccountSource import dev.usbharu.hideout.domain.mastodon.model.generated.CredentialAccount -import dev.usbharu.hideout.domain.mastodon.model.generated.CredentialAccountSource import dev.usbharu.hideout.domain.mastodon.model.generated.Role import dev.usbharu.hideout.mastodon.service.account.AccountApiService import kotlinx.coroutines.test.runTest @@ -74,10 +74,10 @@ class MastodonAccountApiControllerTest { lastStatusAt = "", statusesCount = 0, followersCount = 0, - source = CredentialAccountSource( + source = AccountSource( note = "", fields = emptyList(), - privacy = CredentialAccountSource.Privacy.public, + privacy = AccountSource.Privacy.public, sensitive = false, followRequestsCount = 0 ), diff --git a/src/test/kotlin/dev/usbharu/hideout/mastodon/service/account/AccountApiServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/mastodon/service/account/AccountApiServiceImplTest.kt index d10e4e77..5beffa32 100644 --- a/src/test/kotlin/dev/usbharu/hideout/mastodon/service/account/AccountApiServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/mastodon/service/account/AccountApiServiceImplTest.kt @@ -4,6 +4,7 @@ import dev.usbharu.hideout.application.external.Transaction import dev.usbharu.hideout.core.domain.model.actor.ActorRepository import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository import dev.usbharu.hideout.core.query.FollowerQueryService +import dev.usbharu.hideout.core.service.media.MediaService import dev.usbharu.hideout.core.service.relationship.RelationshipService import dev.usbharu.hideout.core.service.user.UserService import dev.usbharu.hideout.domain.mastodon.model.generated.Account @@ -48,6 +49,9 @@ class AccountApiServiceImplTest { @Mock private lateinit var relationshipRepository: RelationshipRepository + @Mock + private lateinit var mediaService: MediaService + @InjectMocks private lateinit var accountApiServiceImpl: AccountApiServiceImpl diff --git a/src/test/kotlin/utils/UserBuilder.kt b/src/test/kotlin/utils/UserBuilder.kt index c496eed8..107a0613 100644 --- a/src/test/kotlin/utils/UserBuilder.kt +++ b/src/test/kotlin/utils/UserBuilder.kt @@ -19,7 +19,6 @@ object UserBuilder { domain: String = "example.com", screenName: String = name, description: String = "This user is test user.", - password: String = "password-$id", inbox: String = "https://$domain/users/$id/inbox", outbox: String = "https://$domain/users/$id/outbox", url: String = "https://$domain/users/$id", @@ -44,7 +43,8 @@ object UserBuilder { createdAt = createdAt, keyId = keyId, followers = followers, - following = following + following = following, + locked = false ) } @@ -77,7 +77,8 @@ object UserBuilder { createdAt = createdAt, keyId = keyId, followers = followers, - following = following + following = following, + locked = false ) }