From 2ad3b1fd74f20698be13a4beb5ee4b818ea0f090 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 24 Sep 2023 10:33:30 +0900 Subject: [PATCH] improve moderation log --- locales/index.d.ts | 3 +++ packages/backend/src/core/RoleService.ts | 13 +++++++++++++ .../src/server/api/endpoints/admin/roles/delete.ts | 11 ++++------- packages/backend/src/types.ts | 2 +- packages/misskey-js/src/consts.ts | 2 +- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/locales/index.d.ts b/locales/index.d.ts index fd99f10b69..1e5396ad63 100644 --- a/locales/index.d.ts +++ b/locales/index.d.ts @@ -2262,6 +2262,9 @@ export interface Locale { "deleteNote": string; "createGlobalAnnouncement": string; "createUserAnnouncement": string; + "resetPassword": string; + "suspendRemoteInstance": string; + "unsuspendRemoteInstance": string; }; } declare const locales: { diff --git a/packages/backend/src/core/RoleService.ts b/packages/backend/src/core/RoleService.ts index 39f21ecec4..dea6dc68cd 100644 --- a/packages/backend/src/core/RoleService.ts +++ b/packages/backend/src/core/RoleService.ts @@ -493,6 +493,19 @@ export class RoleService implements OnApplicationShutdown { } } + @bindThis + public async delete(role: MiRole, moderator?: MiUser): Promise { + await this.rolesRepository.delete({ id: role.id }); + this.globalEventService.publishInternalEvent('roleDeleted', role); + + if (moderator) { + this.moderationLogService.log(moderator, 'deleteRole', { + roleId: role.id, + role: role, + }); + } + } + @bindThis public dispose(): void { this.redisForSub.off('message', this.onMessage); diff --git a/packages/backend/src/server/api/endpoints/admin/roles/delete.ts b/packages/backend/src/server/api/endpoints/admin/roles/delete.ts index 6e012f6428..7b989050eb 100644 --- a/packages/backend/src/server/api/endpoints/admin/roles/delete.ts +++ b/packages/backend/src/server/api/endpoints/admin/roles/delete.ts @@ -6,9 +6,9 @@ import { Inject, Injectable } from '@nestjs/common'; import { Endpoint } from '@/server/api/endpoint-base.js'; import type { RolesRepository } from '@/models/_.js'; -import { GlobalEventService } from '@/core/GlobalEventService.js'; import { DI } from '@/di-symbols.js'; import { ApiError } from '@/server/api/error.js'; +import { RoleService } from '@/core/RoleService.js'; export const meta = { tags: ['admin', 'role'], @@ -41,17 +41,14 @@ export default class extends Endpoint { // eslint- @Inject(DI.rolesRepository) private rolesRepository: RolesRepository, - private globalEventService: GlobalEventService, + private roleService: RoleService, ) { - super(meta, paramDef, async (ps) => { + super(meta, paramDef, async (ps, me) => { const role = await this.rolesRepository.findOneBy({ id: ps.roleId }); if (role == null) { throw new ApiError(meta.errors.noSuchRole); } - await this.rolesRepository.delete({ - id: ps.roleId, - }); - this.globalEventService.publishInternalEvent('roleDeleted', role); + await this.roleService.delete(role, me); }); } } diff --git a/packages/backend/src/types.ts b/packages/backend/src/types.ts index 0a53e77b79..a58bb9585a 100644 --- a/packages/backend/src/types.ts +++ b/packages/backend/src/types.ts @@ -85,7 +85,7 @@ export type ModerationLogPayloads = { }; deleteRole: { roleId: string; - roleName: string; + role: any; }; clearQueue: Record; promoteQueue: Record; diff --git a/packages/misskey-js/src/consts.ts b/packages/misskey-js/src/consts.ts index a8962ab3d3..a5c8c2ba00 100644 --- a/packages/misskey-js/src/consts.ts +++ b/packages/misskey-js/src/consts.ts @@ -103,7 +103,7 @@ export type ModerationLogPayloads = { }; deleteRole: { roleId: string; - roleName: string; + role: any; }; clearQueue: Record; promoteQueue: Record;