From 19bc9c20a651be62286573377348f4c61ae96587 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 23 Sep 2023 20:50:02 +0900 Subject: [PATCH] improve moderation log --- locales/ja-JP.yml | 3 +++ .../admin/federation/update-instance.ts | 18 +++++++++++++++++- .../api/endpoints/admin/reset-password.ts | 9 ++++++++- packages/backend/src/types.ts | 14 ++++++++++++++ packages/misskey-js/etc/misskey-js.api.md | 11 ++++++++++- packages/misskey-js/src/consts.ts | 14 ++++++++++++++ packages/misskey-js/src/entities.ts | 9 +++++++++ 7 files changed, 75 insertions(+), 3 deletions(-) diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index b396014ee..47bbb0aa5 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -2175,3 +2175,6 @@ _moderationLogTypes: deleteNote: "ノートを削除" createGlobalAnnouncement: "全体のお知らせを作成" createUserAnnouncement: "ユーザーへお知らせを作成" + resetPassword: "パスワードをリセット" + suspendRemoteInstance: "リモートサーバーを停止" + unsuspendRemoteInstance: "リモートサーバーを再開" diff --git a/packages/backend/src/server/api/endpoints/admin/federation/update-instance.ts b/packages/backend/src/server/api/endpoints/admin/federation/update-instance.ts index fbb91837f..357bf83e8 100644 --- a/packages/backend/src/server/api/endpoints/admin/federation/update-instance.ts +++ b/packages/backend/src/server/api/endpoints/admin/federation/update-instance.ts @@ -9,6 +9,7 @@ import type { InstancesRepository } from '@/models/_.js'; import { UtilityService } from '@/core/UtilityService.js'; import { DI } from '@/di-symbols.js'; import { FederatedInstanceService } from '@/core/FederatedInstanceService.js'; +import { ModerationLogService } from '@/core/ModerationLogService.js'; export const meta = { tags: ['admin'], @@ -34,6 +35,7 @@ export default class extends Endpoint { // eslint- private utilityService: UtilityService, private federatedInstanceService: FederatedInstanceService, + private moderationLogService: ModerationLogService, ) { super(meta, paramDef, async (ps, me) => { const instance = await this.instancesRepository.findOneBy({ host: this.utilityService.toPuny(ps.host) }); @@ -42,9 +44,23 @@ export default class extends Endpoint { // eslint- throw new Error('instance not found'); } - this.federatedInstanceService.update(instance.id, { + await this.federatedInstanceService.update(instance.id, { isSuspended: ps.isSuspended, }); + + if (instance.isSuspended !== ps.isSuspended) { + if (ps.isSuspended) { + this.moderationLogService.log(me, 'suspendRemoteInstance', { + id: instance.id, + host: instance.host, + }); + } else { + this.moderationLogService.log(me, 'unsuspendRemoteInstance', { + id: instance.id, + host: instance.host, + }); + } + } }); } } diff --git a/packages/backend/src/server/api/endpoints/admin/reset-password.ts b/packages/backend/src/server/api/endpoints/admin/reset-password.ts index 0dd4fb412..6ce758327 100644 --- a/packages/backend/src/server/api/endpoints/admin/reset-password.ts +++ b/packages/backend/src/server/api/endpoints/admin/reset-password.ts @@ -9,6 +9,7 @@ import { Endpoint } from '@/server/api/endpoint-base.js'; import type { UsersRepository, UserProfilesRepository } from '@/models/_.js'; import { DI } from '@/di-symbols.js'; import { secureRndstr } from '@/misc/secure-rndstr.js'; +import { ModerationLogService } from '@/core/ModerationLogService.js'; export const meta = { tags: ['admin'], @@ -46,8 +47,10 @@ export default class extends Endpoint { // eslint- @Inject(DI.userProfilesRepository) private userProfilesRepository: UserProfilesRepository, + + private moderationLogService: ModerationLogService, ) { - super(meta, paramDef, async (ps) => { + super(meta, paramDef, async (ps, me) => { const user = await this.usersRepository.findOneBy({ id: ps.userId }); if (user == null) { @@ -69,6 +72,10 @@ export default class extends Endpoint { // eslint- password: hash, }); + this.moderationLogService.log(me, 'resetPassword', { + targetId: user.id, + }); + return { password: passwd, }; diff --git a/packages/backend/src/types.ts b/packages/backend/src/types.ts index 7946e66b8..0a53e77b7 100644 --- a/packages/backend/src/types.ts +++ b/packages/backend/src/types.ts @@ -43,6 +43,9 @@ export const moderationLogTypes = [ 'deleteNote', 'createGlobalAnnouncement', 'createUserAnnouncement', + 'resetPassword', + 'suspendRemoteInstance', + 'unsuspendRemoteInstance', ] as const; export type ModerationLogPayloads = { @@ -104,4 +107,15 @@ export type ModerationLogPayloads = { announcement: any; userId: string; }; + resetPassword: { + targetId: string; + }; + suspendRemoteInstance: { + id: string; + host: string; + }; + unsuspendRemoteInstance: { + id: string; + host: string; + }; }; diff --git a/packages/misskey-js/etc/misskey-js.api.md b/packages/misskey-js/etc/misskey-js.api.md index 804733c06..adedea875 100644 --- a/packages/misskey-js/etc/misskey-js.api.md +++ b/packages/misskey-js/etc/misskey-js.api.md @@ -2556,10 +2556,19 @@ type ModerationLog = { } | { type: 'promoteQueue'; info: ModerationLogPayloads['promoteQueue']; +} | { + type: 'resetPassword'; + info: ModerationLogPayloads['resetPassword']; +} | { + type: 'suspendRemoteInstance'; + info: ModerationLogPayloads['suspendRemoteInstance']; +} | { + type: 'unsuspendRemoteInstance'; + info: ModerationLogPayloads['unsuspendRemoteInstance']; }); // @public (undocumented) -export const moderationLogTypes: readonly ["updateServerSettings", "suspend", "unsuspend", "updateUserNote", "addCustomEmoji", "assignRole", "unassignRole", "updateRole", "deleteRole", "clearQueue", "promoteQueue", "deleteDriveFile", "deleteNote", "createGlobalAnnouncement", "createUserAnnouncement"]; +export const moderationLogTypes: readonly ["updateServerSettings", "suspend", "unsuspend", "updateUserNote", "addCustomEmoji", "assignRole", "unassignRole", "updateRole", "deleteRole", "clearQueue", "promoteQueue", "deleteDriveFile", "deleteNote", "createGlobalAnnouncement", "createUserAnnouncement", "resetPassword", "suspendRemoteInstance", "unsuspendRemoteInstance"]; // @public (undocumented) export const mutedNoteReasons: readonly ["word", "manual", "spam", "other"]; diff --git a/packages/misskey-js/src/consts.ts b/packages/misskey-js/src/consts.ts index 346affc6a..a8962ab3d 100644 --- a/packages/misskey-js/src/consts.ts +++ b/packages/misskey-js/src/consts.ts @@ -61,6 +61,9 @@ export const moderationLogTypes = [ 'deleteNote', 'createGlobalAnnouncement', 'createUserAnnouncement', + 'resetPassword', + 'suspendRemoteInstance', + 'unsuspendRemoteInstance', ] as const; export type ModerationLogPayloads = { @@ -122,4 +125,15 @@ export type ModerationLogPayloads = { announcement: any; userId: string; }; + resetPassword: { + targetId: string; + }; + suspendRemoteInstance: { + id: string; + host: string; + }; + unsuspendRemoteInstance: { + id: string; + host: string; + }; }; diff --git a/packages/misskey-js/src/entities.ts b/packages/misskey-js/src/entities.ts index 0e6604cba..a1fc8befb 100644 --- a/packages/misskey-js/src/entities.ts +++ b/packages/misskey-js/src/entities.ts @@ -607,4 +607,13 @@ export type ModerationLog = { } | { type: 'promoteQueue'; info: ModerationLogPayloads['promoteQueue']; +} | { + type: 'resetPassword'; + info: ModerationLogPayloads['resetPassword']; +} | { + type: 'suspendRemoteInstance'; + info: ModerationLogPayloads['suspendRemoteInstance']; +} | { + type: 'unsuspendRemoteInstance'; + info: ModerationLogPayloads['unsuspendRemoteInstance']; });