From 9771f1c435d613ef5d8eecb9b32dd68527b3eefc Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 29 Sep 2023 13:26:11 +0900 Subject: [PATCH] enhance: improve moderation log --- locales/index.d.ts | 3 +++ locales/ja-JP.yml | 3 +++ .../server/api/endpoints/admin/ad/create.ts | 8 ++++++ .../server/api/endpoints/admin/ad/delete.ts | 8 ++++++ .../server/api/endpoints/admin/ad/update.ts | 11 ++++++++ packages/backend/src/types.ts | 16 ++++++++++++ .../src/pages/admin/modlog.ModLog.vue | 26 ++++++++++++++++++- packages/misskey-js/etc/misskey-js.api.md | 2 +- packages/misskey-js/src/consts.ts | 16 ++++++++++++ 9 files changed, 91 insertions(+), 2 deletions(-) diff --git a/locales/index.d.ts b/locales/index.d.ts index b971e8905..099ebbfc7 100644 --- a/locales/index.d.ts +++ b/locales/index.d.ts @@ -2283,6 +2283,9 @@ export interface Locale { "unmarkSensitiveDriveFile": string; "resolveAbuseReport": string; "createInvitation": string; + "createAd": string; + "deleteAd": string; + "updateAd": string; }; } declare const locales: { diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index 5822ba8fb..321c2c5f0 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -2196,3 +2196,6 @@ _moderationLogTypes: unmarkSensitiveDriveFile: "ファイルをセンシティブ解除" resolveAbuseReport: "通報を解決" createInvitation: "招待コードを作成" + createAd: "広告を作成" + deleteAd: "広告を削除" + updateAd: "広告を更新" diff --git a/packages/backend/src/server/api/endpoints/admin/ad/create.ts b/packages/backend/src/server/api/endpoints/admin/ad/create.ts index 2ed9410e7..e48dffecf 100644 --- a/packages/backend/src/server/api/endpoints/admin/ad/create.ts +++ b/packages/backend/src/server/api/endpoints/admin/ad/create.ts @@ -8,6 +8,7 @@ import { Endpoint } from '@/server/api/endpoint-base.js'; import type { AdsRepository } from '@/models/_.js'; import { IdService } from '@/core/IdService.js'; import { DI } from '@/di-symbols.js'; +import { ModerationLogService } from '@/core/ModerationLogService.js'; export const meta = { tags: ['admin'], @@ -39,6 +40,7 @@ export default class extends Endpoint { // eslint- private adsRepository: AdsRepository, private idService: IdService, + private moderationLogService: ModerationLogService, ) { super(meta, paramDef, async (ps, me) => { const ad = await this.adsRepository.insert({ @@ -54,6 +56,12 @@ export default class extends Endpoint { // eslint- place: ps.place, memo: ps.memo, }).then(r => this.adsRepository.findOneByOrFail({ id: r.identifiers[0].id })); + + this.moderationLogService.log(me, 'createAd', { + adId: ad.id, + ad: ad, + }); + return ad; }); } diff --git a/packages/backend/src/server/api/endpoints/admin/ad/delete.ts b/packages/backend/src/server/api/endpoints/admin/ad/delete.ts index d3c53d4f6..8097133a4 100644 --- a/packages/backend/src/server/api/endpoints/admin/ad/delete.ts +++ b/packages/backend/src/server/api/endpoints/admin/ad/delete.ts @@ -7,6 +7,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { Endpoint } from '@/server/api/endpoint-base.js'; import type { AdsRepository } from '@/models/_.js'; import { DI } from '@/di-symbols.js'; +import { ModerationLogService } from '@/core/ModerationLogService.js'; import { ApiError } from '../../../error.js'; export const meta = { @@ -37,6 +38,8 @@ export default class extends Endpoint { // eslint- constructor( @Inject(DI.adsRepository) private adsRepository: AdsRepository, + + private moderationLogService: ModerationLogService, ) { super(meta, paramDef, async (ps, me) => { const ad = await this.adsRepository.findOneBy({ id: ps.id }); @@ -44,6 +47,11 @@ export default class extends Endpoint { // eslint- if (ad == null) throw new ApiError(meta.errors.noSuchAd); await this.adsRepository.delete(ad.id); + + this.moderationLogService.log(me, 'deleteAd', { + adId: ad.id, + ad: ad, + }); }); } } diff --git a/packages/backend/src/server/api/endpoints/admin/ad/update.ts b/packages/backend/src/server/api/endpoints/admin/ad/update.ts index 5b77f67e1..d065f9ec5 100644 --- a/packages/backend/src/server/api/endpoints/admin/ad/update.ts +++ b/packages/backend/src/server/api/endpoints/admin/ad/update.ts @@ -7,6 +7,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { Endpoint } from '@/server/api/endpoint-base.js'; import type { AdsRepository } from '@/models/_.js'; import { DI } from '@/di-symbols.js'; +import { ModerationLogService } from '@/core/ModerationLogService.js'; import { ApiError } from '../../../error.js'; export const meta = { @@ -46,6 +47,8 @@ export default class extends Endpoint { // eslint- constructor( @Inject(DI.adsRepository) private adsRepository: AdsRepository, + + private moderationLogService: ModerationLogService, ) { super(meta, paramDef, async (ps, me) => { const ad = await this.adsRepository.findOneBy({ id: ps.id }); @@ -63,6 +66,14 @@ export default class extends Endpoint { // eslint- startsAt: new Date(ps.startsAt), dayOfWeek: ps.dayOfWeek, }); + + const updatedAd = await this.adsRepository.findOneByOrFail({ id: ad.id }); + + this.moderationLogService.log(me, 'updateAd', { + adId: ad.id, + before: ad, + after: updatedAd, + }); }); } } diff --git a/packages/backend/src/types.ts b/packages/backend/src/types.ts index 9e06d30aa..a9b9a55bc 100644 --- a/packages/backend/src/types.ts +++ b/packages/backend/src/types.ts @@ -57,6 +57,9 @@ export const moderationLogTypes = [ 'unmarkSensitiveDriveFile', 'resolveAbuseReport', 'createInvitation', + 'createAd', + 'updateAd', + 'deleteAd', ] as const; export type ModerationLogPayloads = { @@ -202,6 +205,19 @@ export type ModerationLogPayloads = { createInvitation: { invitations: any[]; }; + createAd: { + adId: string; + ad: any; + }; + updateAd: { + adId: string; + before: any; + after: any; + }; + deleteAd: { + adId: string; + ad: any; + }; }; export type Serialized = { diff --git a/packages/frontend/src/pages/admin/modlog.ModLog.vue b/packages/frontend/src/pages/admin/modlog.ModLog.vue index 8d83b32fa..99b8544f3 100644 --- a/packages/frontend/src/pages/admin/modlog.ModLog.vue +++ b/packages/frontend/src/pages/admin/modlog.ModLog.vue @@ -6,7 +6,13 @@ SPDX-License-Identifier: AGPL-3.0-only