From e85a9dc8e0d99c7d395e912f6c8da6d87dfdf1bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=AC=B4=EB=9D=BC=EC=BF=A0=EB=AA=A8?= Date: Mon, 13 May 2024 21:51:28 +0900 Subject: [PATCH] feat(UserEntityService): add isRoot flag on MeDetailed --- .../src/core/entities/UserEntityService.ts | 64 ++++++++++--------- .../backend/src/models/json-schema/user.ts | 4 ++ packages/misskey-js/src/autogen/types.ts | 1 + 3 files changed, 38 insertions(+), 31 deletions(-) diff --git a/packages/backend/src/core/entities/UserEntityService.ts b/packages/backend/src/core/entities/UserEntityService.ts index 919e98c0a..66dbda53e 100644 --- a/packages/backend/src/core/entities/UserEntityService.ts +++ b/packages/backend/src/core/entities/UserEntityService.ts @@ -469,6 +469,7 @@ export class UserEntityService implements OnModuleInit { const policies = isDetailed ? await this.roleService.getUserPolicies(user.id) : null; const isModerator = (isMe || iAmModerator) && isDetailed ? this.roleService.isModerator(user) : null; const isAdmin = (isMe || iAmModerator) && isDetailed ? this.roleService.isAdministrator(user) : null; + const isRoot = isMe && isDetailed ? user.isRoot : null; const unreadAnnouncements = isMe && isDetailed ? await this.announcementService.getUnreadAnnouncements(user) : null; const notificationsInfo = isMe && isDetailed ? await this.getNotificationsInfo(user.id) : null; @@ -509,7 +510,7 @@ export class UserEntityService implements OnModuleInit { }))) : undefined, ...(isDetailed ? { - url: profile!.url, + url: profile?.url, uri: user.uri, movedTo: user.movedToUri ? this.apPersonService.resolvePerson(user.movedToUri).then(user => user.id).catch(() => null) : null, alsoKnownAs: user.alsoKnownAs @@ -525,12 +526,12 @@ export class UserEntityService implements OnModuleInit { isSilenced: !policies?.canPublicNote, isLimited: !(policies?.canCreateContent && policies.canUpdateContent && policies.canDeleteContent && policies.canInitiateConversation), isSuspended: user.isSuspended, - description: profile!.description, - location: profile!.location, - birthday: profile!.birthday, - lang: profile!.lang, - fields: profile!.fields, - verifiedLinks: profile!.verifiedLinks, + description: profile?.description, + location: profile?.location, + birthday: profile?.birthday, + lang: profile?.lang, + fields: profile?.fields, + verifiedLinks: profile?.verifiedLinks, followersCount: followersCount ?? 0, followingCount: followingCount ?? 0, notesCount: user.notesCount, @@ -538,14 +539,14 @@ export class UserEntityService implements OnModuleInit { pinnedNotes: this.noteEntityService.packMany(pins.map(pin => pin.note!), me, { detail: true, }), - pinnedPageId: profile!.pinnedPageId, - pinnedPage: profile!.pinnedPageId ? this.pageEntityService.pack(profile!.pinnedPageId, me) : null, - publicReactions: this.isLocalUser(user) ? profile!.publicReactions : false, // https://github.com/misskey-dev/misskey/issues/12964 - followersVisibility: profile!.followersVisibility, - followingVisibility: profile!.followingVisibility, - twoFactorEnabled: profile!.twoFactorEnabled, - usePasswordLessLogin: profile!.usePasswordLessLogin, - securityKeys: profile!.twoFactorEnabled + pinnedPageId: profile?.pinnedPageId, + pinnedPage: profile?.pinnedPageId ? this.pageEntityService.pack(profile.pinnedPageId, me) : null, + publicReactions: this.isLocalUser(user) ? profile?.publicReactions : false, // https://github.com/misskey-dev/misskey/issues/12964 + followersVisibility: profile?.followersVisibility, + followingVisibility: profile?.followingVisibility, + twoFactorEnabled: profile?.twoFactorEnabled, + usePasswordLessLogin: profile?.usePasswordLessLogin, + securityKeys: profile?.twoFactorEnabled ? this.userSecurityKeysRepository.countBy({ userId: user.id }).then(result => result >= 1) : false, roles: this.roleService.getUserRoles(user.id).then(roles => roles @@ -563,7 +564,7 @@ export class UserEntityService implements OnModuleInit { })) ), memo: memo, - moderationNote: iAmModerator ? (profile!.moderationNote ?? '') : undefined, + moderationNote: iAmModerator ? (profile?.moderationNote ?? '') : undefined, } : {}), ...(isDetailed && (isMe || iAmModerator) ? { @@ -571,14 +572,15 @@ export class UserEntityService implements OnModuleInit { bannerId: user.bannerId, isModerator: isModerator, isAdmin: isAdmin, - injectFeaturedNote: profile!.injectFeaturedNote, - receiveAnnouncementEmail: profile!.receiveAnnouncementEmail, - alwaysMarkNsfw: profile!.alwaysMarkNsfw, - autoSensitive: profile!.autoSensitive, - carefulBot: profile!.carefulBot, - autoAcceptFollowed: profile!.autoAcceptFollowed, - noCrawle: profile!.noCrawle, - preventAiLearning: profile!.preventAiLearning, + isRoot: isRoot, + injectFeaturedNote: profile?.injectFeaturedNote, + receiveAnnouncementEmail: profile?.receiveAnnouncementEmail, + alwaysMarkNsfw: profile?.alwaysMarkNsfw, + autoSensitive: profile?.autoSensitive, + carefulBot: profile?.carefulBot, + autoAcceptFollowed: profile?.autoAcceptFollowed, + noCrawle: profile?.noCrawle, + preventAiLearning: profile?.preventAiLearning, isExplorable: user.isExplorable, isDeleted: user.isDeleted, twoFactorBackupCodesStock: profile?.twoFactorBackupSecret?.length === 20 ? 'full' : (profile?.twoFactorBackupSecret?.length ?? 0) > 0 ? 'partial' : 'none', @@ -601,17 +603,17 @@ export class UserEntityService implements OnModuleInit { mutedWords: profile!.mutedWords, mutedInstances: profile!.mutedInstances, mutingNotificationTypes: [], // 後方互換性のため - notificationRecieveConfig: profile!.notificationRecieveConfig, - emailNotificationTypes: profile!.emailNotificationTypes, - achievements: profile!.achievements, - loggedInDays: profile!.loggedInDates.length, + notificationRecieveConfig: profile?.notificationRecieveConfig, + emailNotificationTypes: profile?.emailNotificationTypes, + achievements: profile?.achievements, + loggedInDays: profile?.loggedInDates.length, policies: policies, } : {}), ...(opts.includeSecrets ? { - email: profile!.email, - emailVerified: profile!.emailVerified, - securityKeysList: profile!.twoFactorEnabled + email: profile?.email, + emailVerified: profile?.emailVerified, + securityKeysList: profile?.twoFactorEnabled ? this.userSecurityKeysRepository.find({ where: { userId: user.id, diff --git a/packages/backend/src/models/json-schema/user.ts b/packages/backend/src/models/json-schema/user.ts index 4531fcee0..4a1597a92 100644 --- a/packages/backend/src/models/json-schema/user.ts +++ b/packages/backend/src/models/json-schema/user.ts @@ -453,6 +453,10 @@ export const packedMeDetailedOnlySchema = { type: 'boolean', nullable: true, optional: false, }, + isRoot: { + type: 'boolean', + nullable: true, optional: false, + }, injectFeaturedNote: { type: 'boolean', nullable: false, optional: false, diff --git a/packages/misskey-js/src/autogen/types.ts b/packages/misskey-js/src/autogen/types.ts index b743313de..511407065 100644 --- a/packages/misskey-js/src/autogen/types.ts +++ b/packages/misskey-js/src/autogen/types.ts @@ -3852,6 +3852,7 @@ export type components = { bannerId: string | null; isModerator: boolean | null; isAdmin: boolean | null; + isRoot: boolean | null; injectFeaturedNote: boolean; receiveAnnouncementEmail: boolean; alwaysMarkNsfw: boolean;