From cbb7e95d82d363d96462b90943bf329469ad08df Mon Sep 17 00:00:00 2001 From: Johann150 Date: Thu, 20 Jan 2022 19:06:38 +0100 Subject: [PATCH] enhance: Forward report (#8001) * implement sending AP Flag object Optionally allow a user to select to forward a report about a remote user to the other instance. This is added in a backwards-compatible way. * add locale string * forward report only for moderators * add switch to moderator UI to forward report * fix report note url * return forwarded status from API apparently forgot to carry this over from my testing environment * object in Flag activity has to be an array For correct interoperability with Pleroma the "object" property of the Flag activity has to be an array. This array will in the future also hold the link to respective notes, so it makes sense to correct this on our side. * Update get-note-menu.ts Co-authored-by: syuilo --- locales/ja-JP.yml | 3 + .../1637320813000-forwarded-report.js | 13 +++ .../src/models/entities/abuse-user-report.ts | 5 + .../models/repositories/abuse-user-report.ts | 1 + .../src/remote/activitypub/renderer/flag.ts | 15 +++ .../api/endpoints/admin/abuse-user-reports.ts | 5 + .../admin/resolve-abuse-user-report.ts | 20 +++- .../client/src/components/abuse-report.vue | 102 ++++++++++++++++++ packages/client/src/pages/admin/abuses.vue | 62 +---------- packages/client/src/scripts/get-note-menu.ts | 2 +- 10 files changed, 169 insertions(+), 59 deletions(-) create mode 100644 packages/backend/migration/1637320813000-forwarded-report.js create mode 100644 packages/backend/src/remote/activitypub/renderer/flag.ts create mode 100644 packages/client/src/components/abuse-report.vue diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index dd853aa83..59ce5ee84 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -619,8 +619,11 @@ reportAbuse: "通報" reportAbuseOf: "{name}を通報する" fillAbuseReportDescription: "通報理由の詳細を記入してください。対象のノートがある場合はそのURLも記入してください。" abuseReported: "内容が送信されました。ご報告ありがとうございました。" +reporter: "通報者" reporteeOrigin: "通報先" reporterOrigin: "通報元" +forwardReport: "リモートインスタンスに通報を転送する" +forwardReportIsAnonymous: "リモートインスタンスからはあなたの情報は見れず、匿名のシステムアカウントとして表示されます。" send: "送信" abuseMarkAsResolved: "対応済みにする" openInNewTab: "新しいタブで開く" diff --git a/packages/backend/migration/1637320813000-forwarded-report.js b/packages/backend/migration/1637320813000-forwarded-report.js new file mode 100644 index 000000000..4056f7b5f --- /dev/null +++ b/packages/backend/migration/1637320813000-forwarded-report.js @@ -0,0 +1,13 @@ +const { QueryRunner } = require('typeorm'); + +module.exports = class forwardedReport1637320813000 { + name = 'forwardedReport1637320813000'; + + async up(queryRunner) { + await queryRunner.query(`ALTER TABLE "abuse_user_report" ADD "forwarded" boolean NOT NULL DEFAULT false`); + } + + async down(queryRunner) { + await queryRunner.query(`ALTER TABLE "abuse_user_report" DROP COLUMN "forwarded"`); + } +}; diff --git a/packages/backend/src/models/entities/abuse-user-report.ts b/packages/backend/src/models/entities/abuse-user-report.ts index 019d613f7..27c1e47fd 100644 --- a/packages/backend/src/models/entities/abuse-user-report.ts +++ b/packages/backend/src/models/entities/abuse-user-report.ts @@ -51,6 +51,11 @@ export class AbuseUserReport { }) public resolved: boolean; + @Column('boolean', { + default: false + }) + public forwarded: boolean; + @Column('varchar', { length: 2048, }) diff --git a/packages/backend/src/models/repositories/abuse-user-report.ts b/packages/backend/src/models/repositories/abuse-user-report.ts index 5e267b3c2..943b65eb6 100644 --- a/packages/backend/src/models/repositories/abuse-user-report.ts +++ b/packages/backend/src/models/repositories/abuse-user-report.ts @@ -27,6 +27,7 @@ export class AbuseUserReportRepository extends Repository { assignee: report.assigneeId ? Users.pack(report.assignee || report.assigneeId, null, { detail: true, }) : null, + forwarded: report.forwarded, }); } diff --git a/packages/backend/src/remote/activitypub/renderer/flag.ts b/packages/backend/src/remote/activitypub/renderer/flag.ts new file mode 100644 index 000000000..60ac49650 --- /dev/null +++ b/packages/backend/src/remote/activitypub/renderer/flag.ts @@ -0,0 +1,15 @@ +import config from '@/config/index'; +import { IObject, IActivity } from '@/remote/activitypub/type'; +import { ILocalUser, IRemoteUser } from '@/models/entities/user'; +import { getInstanceActor } from '@/services/instance-actor'; + +// to anonymise reporters, the reporting actor must be a system user +// object has to be a uri or array of uris +export const renderFlag = (user: ILocalUser, object: [string], content: string): IActivity => { + return { + type: 'Flag', + actor: `${config.url}/users/${user.id}`, + content, + object, + }; +}; diff --git a/packages/backend/src/server/api/endpoints/admin/abuse-user-reports.ts b/packages/backend/src/server/api/endpoints/admin/abuse-user-reports.ts index 807afd269..ed7b146d0 100644 --- a/packages/backend/src/server/api/endpoints/admin/abuse-user-reports.ts +++ b/packages/backend/src/server/api/endpoints/admin/abuse-user-reports.ts @@ -46,6 +46,11 @@ export const meta = { ]), default: 'combined', }, + + forwarded: { + validator: $.optional.bool, + default: false, + }, }, res: { diff --git a/packages/backend/src/server/api/endpoints/admin/resolve-abuse-user-report.ts b/packages/backend/src/server/api/endpoints/admin/resolve-abuse-user-report.ts index 3b47d7d35..b00457f09 100644 --- a/packages/backend/src/server/api/endpoints/admin/resolve-abuse-user-report.ts +++ b/packages/backend/src/server/api/endpoints/admin/resolve-abuse-user-report.ts @@ -1,7 +1,11 @@ import $ from 'cafy'; import { ID } from '@/misc/cafy-id'; import define from '../../define'; -import { AbuseUserReports } from '@/models/index'; +import { AbuseUserReports, Users } from '@/models/index'; +import { getInstanceActor } from '@/services/instance-actor'; +import { deliver } from '@/queue/index'; +import { renderActivity } from '@/remote/activitypub/renderer/index'; +import { renderFlag } from '@/remote/activitypub/renderer/flag'; export const meta = { tags: ['admin'], @@ -13,6 +17,12 @@ export const meta = { reportId: { validator: $.type(ID), }, + + forward: { + validator: $.optional.boolean, + required: false, + default: false, + }, }, } as const; @@ -24,8 +34,16 @@ export default define(meta, async (ps, me) => { throw new Error('report not found'); } + if (ps.forward && report.targetUserHost != null) { + const actor = await getInstanceActor(); + const targetUser = await Users.findOne(report.targetUserId); + + deliver(actor, renderActivity(renderFlag(actor, [targetUser.uri], report.comment)), targetUser.inbox); + } + await AbuseUserReports.update(report.id, { resolved: true, assigneeId: me.id, + forwarded: ps.forward && report.targetUserHost != null, }); }); diff --git a/packages/client/src/components/abuse-report.vue b/packages/client/src/components/abuse-report.vue new file mode 100644 index 000000000..b67cef209 --- /dev/null +++ b/packages/client/src/components/abuse-report.vue @@ -0,0 +1,102 @@ + + + + + diff --git a/packages/client/src/pages/admin/abuses.vue b/packages/client/src/pages/admin/abuses.vue index 31cdef492..92f93797c 100644 --- a/packages/client/src/pages/admin/abuses.vue +++ b/packages/client/src/pages/admin/abuses.vue @@ -34,27 +34,7 @@ --> -
-
- -
- -
@{{ acct(report.targetUser) }}
-
-
-
-
- -
-
-
Reporter:
-
-
- -
+
@@ -64,20 +44,19 @@