From 6379deb5a741586ae5667043e99712dac71e9083 Mon Sep 17 00:00:00 2001 From: dakkar Date: Tue, 6 Aug 2024 10:44:56 +0100 Subject: [PATCH] fail `AbuseReportService.resolve` harder without remote users as @fEmber noticed, if `findOneByOrFail` throws, we would have marked the report as resolved, without logging that this way, the whole operation fails (the frontend should not send us ids of users that can't be resolved!) --- packages/backend/src/core/AbuseReportService.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/core/AbuseReportService.ts b/packages/backend/src/core/AbuseReportService.ts index 69c51509ba..ed10a4c5c6 100644 --- a/packages/backend/src/core/AbuseReportService.ts +++ b/packages/backend/src/core/AbuseReportService.ts @@ -93,6 +93,17 @@ export class AbuseReportService { id: In(params.map(it => it.reportId)), }); + const targetUserMap = new Map(); + for (const report of reports) { + const shouldForward = paramsMap.get(report.id)!.forward; + + if (shouldForward && report.targetUserHost != null) { + return targetUserMap.set(report.id, await this.usersRepository.findOneByOrFail({ id: report.targetUserId })); + } else { + return targetUserMap.set(report.id, null); + } + } + for (const report of reports) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const ps = paramsMap.get(report.id)!; @@ -103,9 +114,9 @@ export class AbuseReportService { forwarded: ps.forward && report.targetUserHost !== null, }); - if (ps.forward && report.targetUserHost != null) { + const targetUser = targetUserMap.get(report.id)!; + if (targetUser != null) { const actor = await this.instanceActorService.getInstanceActor(); - const targetUser = await this.usersRepository.findOneByOrFail({ id: report.targetUserId }); // eslint-disable-next-line const flag = this.apRendererService.renderFlag(actor, targetUser.uri!, report.comment);