From 9e4ff380ad1a8c0267cac49d5b7461267131134e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=BE=E3=81=A3=E3=81=A1=E3=82=83=E3=81=A8=E3=83=BC?= =?UTF-8?q?=E3=81=AB=E3=82=85?= <17376330+u1-liquid@users.noreply.github.com> Date: Fri, 24 May 2024 21:40:09 +0900 Subject: [PATCH] =?UTF-8?q?enhance(backend):=20MisskeyIO#615=20=E3=81=AE?= =?UTF-8?q?=E3=83=91=E3=83=95=E3=82=A9=E3=83=BC=E3=83=9E=E3=83=B3=E3=82=B9?= =?UTF-8?q?=E6=94=B9=E5=96=84=20(MisskeyIO#638)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../queue/processors/ReportAbuseProcessorService.ts | 10 +++------- .../api/endpoints/admin/resolve-abuse-user-report.ts | 10 +++------- .../src/server/api/endpoints/users/report-abuse.ts | 10 +++------- 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/packages/backend/src/queue/processors/ReportAbuseProcessorService.ts b/packages/backend/src/queue/processors/ReportAbuseProcessorService.ts index d80e31542..a47019509 100644 --- a/packages/backend/src/queue/processors/ReportAbuseProcessorService.ts +++ b/packages/backend/src/queue/processors/ReportAbuseProcessorService.ts @@ -88,13 +88,9 @@ export class ReportAbuseProcessorService { forwarded: resolver.forward && job.data.targetUserHost !== null && job.data.reporterHost === null, }); - const activeWebhooks = await this.webhookService.getActiveWebhooks(); - for (const webhook of activeWebhooks) { - const webhookUser = await this.usersRepository.findOneByOrFail({ - id: webhook.userId, - }); - const isAdmin = await this.roleService.isAdministrator(webhookUser); - if (webhook.on.includes('reportAutoResolved') && isAdmin) { + const webhooks = (await this.webhookService.getActiveWebhooks()).filter(x => x.on.includes('reportAutoResolved')); + for (const webhook of webhooks) { + if (await this.roleService.isAdministrator({ id: webhook.userId, isRoot: false })) { this.queueService.webhookDeliver(webhook, 'reportAutoResolved', { resolver: resolver, report: job.data, 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 0fa3fe833..dbd2416d1 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 @@ -69,13 +69,9 @@ export default class extends Endpoint { // eslint- forwarded: ps.forward && report.targetUserHost != null, }).then(() => this.abuseUserReportsRepository.findOneBy({ id: ps.reportId })); - const activeWebhooks = await this.webhookService.getActiveWebhooks(); - for (const webhook of activeWebhooks) { - const webhookUser = await this.usersRepository.findOneByOrFail({ - id: webhook.userId, - }); - const isAdmin = await this.roleService.isAdministrator(webhookUser); - if (webhook.on.includes('reportResolved') && isAdmin) { + const webhooks = (await this.webhookService.getActiveWebhooks()).filter(x => x.on.includes('reportResolved')); + for (const webhook of webhooks) { + if (await this.roleService.isAdministrator({ id: webhook.userId, isRoot: false })) { this.queueService.webhookDeliver(webhook, 'reportResolved', { updatedReport, }); diff --git a/packages/backend/src/server/api/endpoints/users/report-abuse.ts b/packages/backend/src/server/api/endpoints/users/report-abuse.ts index 4d5886aff..fd952c460 100644 --- a/packages/backend/src/server/api/endpoints/users/report-abuse.ts +++ b/packages/backend/src/server/api/endpoints/users/report-abuse.ts @@ -100,13 +100,9 @@ export default class extends Endpoint { // eslint- category: ps.category, }).then(x => this.abuseUserReportsRepository.findOneByOrFail(x.identifiers[0])); - const activeWebhooks = await this.webhookService.getActiveWebhooks(); - for (const webhook of activeWebhooks) { - const webhookUser = await this.usersRepository.findOneByOrFail({ - id: webhook.userId, - }); - const isAdmin = await this.roleService.isAdministrator(webhookUser); - if (webhook.on.includes('reportCreated') && isAdmin) { + const webhooks = (await this.webhookService.getActiveWebhooks()).filter(x => x.on.includes('reportCreated')); + for (const webhook of webhooks) { + if (await this.roleService.isAdministrator({ id: webhook.userId, isRoot: false })) { this.queueService.webhookDeliver(webhook, 'reportCreated', { report, });