From fd744f44c1ee7aff71d9dba6096cc9ffcb934271 Mon Sep 17 00:00:00 2001 From: zyoshoka <107108195+zyoshoka@users.noreply.github.com> Date: Sat, 17 Aug 2024 15:01:08 +0900 Subject: [PATCH] =?UTF-8?q?enhance(backend):=20=E3=83=9A=E3=83=BC=E3=82=B8?= =?UTF-8?q?=E3=80=81=E3=82=AE=E3=83=A3=E3=83=A9=E3=83=AA=E3=83=BC=E3=80=81?= =?UTF-8?q?Play=E3=81=AE=E3=83=A2=E3=83=87=E3=83=AC=E3=83=BC=E3=82=B7?= =?UTF-8?q?=E3=83=A7=E3=83=B3=E5=BC=B7=E5=8C=96=20(#13523)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * enhance(backend): Page、ギャラリー、Playのモデレーション強化 * Update CHANGELOG.md * fix: update misskey-js * refactor(frontend): use `MkA` * Update CHANGELOG.md * fix(i18n): Page -> ページ --- CHANGELOG.md | 2 + locales/index.d.ts | 14 +++- locales/ja-JP.yml | 5 +- .../src/server/api/endpoints/flash/delete.ts | 24 +++++- .../api/endpoints/gallery/posts/delete.ts | 35 +++++++-- .../src/server/api/endpoints/pages/delete.ts | 24 +++++- packages/backend/src/types.ts | 21 +++++ .../src/components/MkAbuseReportWindow.vue | 2 +- .../frontend/src/components/global/MkAcct.vue | 2 +- .../src/pages/admin/modlog.ModLog.vue | 6 ++ packages/frontend/src/pages/flash/flash.vue | 49 +++++++++++- packages/frontend/src/pages/gallery/post.vue | 55 +++++++++++-- packages/frontend/src/pages/page.vue | 77 ++++++++++++++++--- packages/misskey-js/etc/misskey-js.api.md | 14 +++- packages/misskey-js/src/consts.ts | 21 +++++ packages/misskey-js/src/entities.ts | 12 +++ 16 files changed, 333 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bade07c9d3..6e98f9f193 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,12 @@ ### General - Enhance: モデレーターはすべてのユーザーのフォロー・フォロワーの一覧を見られるように - Enhance: アカウントの削除のモデレーションログを残すように +- Enhance: 不適切なページ、ギャラリー、Playを管理者権限で削除できるように - Fix: リモートユーザのフォロー・フォロワーの一覧が非公開設定の場合も表示できてしまう問題を修正 ### Client - Enhance: 「自分のPlay」ページにおいてPlayが非公開かどうかが一目でわかるように +- Enhance: 不適切なページ、ギャラリー、Playを通報できるように - Fix: Play編集時に公開範囲が「パブリック」にリセットされる問題を修正 - Fix: ページ遷移に失敗することがある問題を修正 - Fix: iOSでユーザー名などがリンクとして誤検知される現象を抑制 diff --git a/locales/index.d.ts b/locales/index.d.ts index 2ab5f5797e..75e1703b4a 100644 --- a/locales/index.d.ts +++ b/locales/index.d.ts @@ -2829,7 +2829,7 @@ export interface Locale extends ILocale { */ "reportAbuseOf": ParameterizedString<"name">; /** - * 通報理由の詳細を記入してください。対象のノートがある場合はそのURLも記入してください。 + * 通報理由の詳細を記入してください。対象のノートやページなどがある場合はそのURLも記入してください。 */ "fillAbuseReportDescription": string; /** @@ -9687,6 +9687,18 @@ export interface Locale extends ILocale { * アカウントを削除 */ "deleteAccount": string; + /** + * ページを削除 + */ + "deletePage": string; + /** + * Playを削除 + */ + "deleteFlash": string; + /** + * ギャラリーの投稿を削除 + */ + "deleteGalleryPost": string; }; "_fileViewer": { /** diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index fac5b1e533..98e3cbfa41 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -703,7 +703,7 @@ abuseReports: "通報" reportAbuse: "通報" reportAbuseRenote: "リノートを通報" reportAbuseOf: "{name}を通報する" -fillAbuseReportDescription: "通報理由の詳細を記入してください。対象のノートがある場合はそのURLも記入してください。" +fillAbuseReportDescription: "通報理由の詳細を記入してください。対象のノートやページなどがある場合はそのURLも記入してください。" abuseReported: "内容が送信されました。ご報告ありがとうございました。" reporter: "通報者" reporteeOrigin: "通報先" @@ -2569,6 +2569,9 @@ _moderationLogTypes: updateAbuseReportNotificationRecipient: "通報の通知先を更新" deleteAbuseReportNotificationRecipient: "通報の通知先を削除" deleteAccount: "アカウントを削除" + deletePage: "ページを削除" + deleteFlash: "Playを削除" + deleteGalleryPost: "ギャラリーの投稿を削除" _fileViewer: title: "ファイルの詳細" diff --git a/packages/backend/src/server/api/endpoints/flash/delete.ts b/packages/backend/src/server/api/endpoints/flash/delete.ts index d3d47e5deb..6912450abf 100644 --- a/packages/backend/src/server/api/endpoints/flash/delete.ts +++ b/packages/backend/src/server/api/endpoints/flash/delete.ts @@ -4,9 +4,11 @@ */ import { Inject, Injectable } from '@nestjs/common'; -import type { FlashsRepository } from '@/models/_.js'; +import type { FlashsRepository, UsersRepository } from '@/models/_.js'; import { Endpoint } from '@/server/api/endpoint-base.js'; import { DI } from '@/di-symbols.js'; +import { ModerationLogService } from '@/core/ModerationLogService.js'; +import { RoleService } from '@/core/RoleService.js'; import { ApiError } from '../../error.js'; export const meta = { @@ -44,17 +46,35 @@ export default class extends Endpoint { // eslint- constructor( @Inject(DI.flashsRepository) private flashsRepository: FlashsRepository, + + @Inject(DI.usersRepository) + private usersRepository: UsersRepository, + + private moderationLogService: ModerationLogService, + private roleService: RoleService, ) { super(meta, paramDef, async (ps, me) => { const flash = await this.flashsRepository.findOneBy({ id: ps.flashId }); + if (flash == null) { throw new ApiError(meta.errors.noSuchFlash); } - if (flash.userId !== me.id) { + + if (!await this.roleService.isModerator(me) && flash.userId !== me.id) { throw new ApiError(meta.errors.accessDenied); } await this.flashsRepository.delete(flash.id); + + if (flash.userId !== me.id) { + const user = await this.usersRepository.findOneByOrFail({ id: flash.userId }); + this.moderationLogService.log(me, 'deleteFlash', { + flashId: flash.id, + flashUserId: flash.userId, + flashUserUsername: user.username, + flash, + }); + } }); } } diff --git a/packages/backend/src/server/api/endpoints/gallery/posts/delete.ts b/packages/backend/src/server/api/endpoints/gallery/posts/delete.ts index 527e3fb52d..b6b94db161 100644 --- a/packages/backend/src/server/api/endpoints/gallery/posts/delete.ts +++ b/packages/backend/src/server/api/endpoints/gallery/posts/delete.ts @@ -5,8 +5,10 @@ import { Inject, Injectable } from '@nestjs/common'; import { Endpoint } from '@/server/api/endpoint-base.js'; -import type { GalleryPostsRepository } from '@/models/_.js'; +import type { GalleryPostsRepository, UsersRepository } from '@/models/_.js'; import { DI } from '@/di-symbols.js'; +import { ModerationLogService } from '@/core/ModerationLogService.js'; +import { RoleService } from '@/core/RoleService.js'; import { ApiError } from '../../../error.js'; export const meta = { @@ -22,6 +24,12 @@ export const meta = { code: 'NO_SUCH_POST', id: 'ae52f367-4bd7-4ecd-afc6-5672fff427f5', }, + + accessDenied: { + message: 'Access denied.', + code: 'ACCESS_DENIED', + id: 'c86e09de-1c48-43ac-a435-1c7e42ed4496', + }, }, } as const; @@ -38,18 +46,35 @@ export default class extends Endpoint { // eslint- constructor( @Inject(DI.galleryPostsRepository) private galleryPostsRepository: GalleryPostsRepository, + + @Inject(DI.usersRepository) + private usersRepository: UsersRepository, + + private moderationLogService: ModerationLogService, + private roleService: RoleService, ) { super(meta, paramDef, async (ps, me) => { - const post = await this.galleryPostsRepository.findOneBy({ - id: ps.postId, - userId: me.id, - }); + const post = await this.galleryPostsRepository.findOneBy({ id: ps.postId }); if (post == null) { throw new ApiError(meta.errors.noSuchPost); } + if (!await this.roleService.isModerator(me) && post.userId !== me.id) { + throw new ApiError(meta.errors.accessDenied); + } + await this.galleryPostsRepository.delete(post.id); + + if (post.userId !== me.id) { + const user = await this.usersRepository.findOneByOrFail({ id: post.userId }); + this.moderationLogService.log(me, 'deleteGalleryPost', { + postId: post.id, + postUserId: post.userId, + postUserUsername: user.username, + post, + }); + } }); } } diff --git a/packages/backend/src/server/api/endpoints/pages/delete.ts b/packages/backend/src/server/api/endpoints/pages/delete.ts index aa2ba75a41..f2bc946788 100644 --- a/packages/backend/src/server/api/endpoints/pages/delete.ts +++ b/packages/backend/src/server/api/endpoints/pages/delete.ts @@ -4,9 +4,11 @@ */ import { Inject, Injectable } from '@nestjs/common'; -import type { PagesRepository } from '@/models/_.js'; +import type { PagesRepository, UsersRepository } from '@/models/_.js'; import { Endpoint } from '@/server/api/endpoint-base.js'; import { DI } from '@/di-symbols.js'; +import { ModerationLogService } from '@/core/ModerationLogService.js'; +import { RoleService } from '@/core/RoleService.js'; import { ApiError } from '../../error.js'; export const meta = { @@ -44,17 +46,35 @@ export default class extends Endpoint { // eslint- constructor( @Inject(DI.pagesRepository) private pagesRepository: PagesRepository, + + @Inject(DI.usersRepository) + private usersRepository: UsersRepository, + + private moderationLogService: ModerationLogService, + private roleService: RoleService, ) { super(meta, paramDef, async (ps, me) => { const page = await this.pagesRepository.findOneBy({ id: ps.pageId }); + if (page == null) { throw new ApiError(meta.errors.noSuchPage); } - if (page.userId !== me.id) { + + if (!await this.roleService.isModerator(me) && page.userId !== me.id) { throw new ApiError(meta.errors.accessDenied); } await this.pagesRepository.delete(page.id); + + if (page.userId !== me.id) { + const user = await this.usersRepository.findOneByOrFail({ id: page.userId }); + this.moderationLogService.log(me, 'deletePage', { + pageId: page.id, + pageUserId: page.userId, + pageUserUsername: user.username, + page, + }); + } }); } } diff --git a/packages/backend/src/types.ts b/packages/backend/src/types.ts index dbeb232926..e852cf5ae2 100644 --- a/packages/backend/src/types.ts +++ b/packages/backend/src/types.ts @@ -97,6 +97,9 @@ export const moderationLogTypes = [ 'updateAbuseReportNotificationRecipient', 'deleteAbuseReportNotificationRecipient', 'deleteAccount', + 'deletePage', + 'deleteFlash', + 'deleteGalleryPost', ] as const; export type ModerationLogPayloads = { @@ -320,6 +323,24 @@ export type ModerationLogPayloads = { userUsername: string; userHost: string | null; }; + deletePage: { + pageId: string; + pageUserId: string; + pageUserUsername: string; + page: any; + }; + deleteFlash: { + flashId: string; + flashUserId: string; + flashUserUsername: string; + flash: any; + }; + deleteGalleryPost: { + postId: string; + postUserId: string; + postUserUsername: string; + post: any; + }; }; export type Serialized = { diff --git a/packages/frontend/src/components/MkAbuseReportWindow.vue b/packages/frontend/src/components/MkAbuseReportWindow.vue index b09c7bb3fb..a634a748e9 100644 --- a/packages/frontend/src/components/MkAbuseReportWindow.vue +++ b/packages/frontend/src/components/MkAbuseReportWindow.vue @@ -39,7 +39,7 @@ import * as os from '@/os.js'; import { i18n } from '@/i18n.js'; const props = defineProps<{ - user: Misskey.entities.UserDetailed; + user: Misskey.entities.UserLite; initialComment?: string; }>(); diff --git a/packages/frontend/src/components/global/MkAcct.vue b/packages/frontend/src/components/global/MkAcct.vue index 8cb082585b..bbcb070803 100644 --- a/packages/frontend/src/components/global/MkAcct.vue +++ b/packages/frontend/src/components/global/MkAcct.vue @@ -21,7 +21,7 @@ import { host as hostRaw } from '@/config.js'; import { defaultStore } from '@/store.js'; defineProps<{ - user: Misskey.entities.User; + user: Misskey.entities.UserLite; detail?: boolean; }>(); diff --git a/packages/frontend/src/pages/admin/modlog.ModLog.vue b/packages/frontend/src/pages/admin/modlog.ModLog.vue index eb50d068d9..64d7f25845 100644 --- a/packages/frontend/src/pages/admin/modlog.ModLog.vue +++ b/packages/frontend/src/pages/admin/modlog.ModLog.vue @@ -37,6 +37,9 @@ SPDX-License-Identifier: AGPL-3.0-only 'deleteSystemWebhook', 'deleteAbuseReportNotificationRecipient', 'deleteAccount', + 'deletePage', + 'deleteFlash', + 'deleteGalleryPost', ].includes(log.type) }" >{{ i18n.ts._moderationLogTypes[log.type] }} @@ -74,6 +77,9 @@ SPDX-License-Identifier: AGPL-3.0-only : {{ log.info.before.name }} : {{ log.info.recipient.name }} : @{{ log.info.userUsername }}{{ log.info.userHost ? '@' + log.info.userHost : '' }} + : @{{ log.info.pageUserUsername }} + : @{{ log.info.flashUserUsername }} + : @{{ log.info.postUserUsername }}