Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(enforcement): user reports cover the reporter's DM (#3608)

Hampusbf097c449940
diff --git a/fluxer_api/src/api/enforcement/EnforcementEvidence.ts b/fluxer_api/src/api/enforcement/EnforcementEvidence.ts
index b44e69771..375735592 100644
--- a/fluxer_api/src/api/enforcement/EnforcementEvidence.ts
+++ b/fluxer_api/src/api/enforcement/EnforcementEvidence.ts
@@ -9,7 +9,7 @@ import type {EvidenceMessageLocation} from '@app/api/enforcement/EnforcementNoti
import type {GuildRepository} from '@app/api/guild/repositories/GuildRepository';
import type {Channel} from '@app/api/models/Channel';
import type {Message} from '@app/api/models/Message';
-import type {IARMessageContext, IARSubmission} from '@app/api/report/ReportModels';
+import {type IARMessageContext, type IARSubmission, ReportType} from '@app/api/report/ReportModels';
import {ChannelTypes, MessageTypes} from '@fluxer/constants/src/ChannelConstants';
import {ValidationErrorCodes} from '@fluxer/constants/src/ValidationErrorCodes';
import {InputValidationError} from '@fluxer/errors/src/domains/core/InputValidationError';
@@ -23,6 +23,18 @@ function isConversation(type: number): boolean {
return type === ChannelTypes.DM || type === ChannelTypes.GROUP_DM;
}
+function coversConversation(report: IARSubmission, channel: Channel): boolean {
+ if (report.reportedChannelId === channel.id) return true;
+ return (
+ report.reportType === ReportType.USER &&
+ channel.type === ChannelTypes.DM &&
+ report.reporterId !== null &&
+ report.reportedUserId !== null &&
+ channel.recipientIds.has(report.reporterId) &&
+ channel.recipientIds.has(report.reportedUserId)
+ );
+}
+
function attachmentMetadata(attachment: MessageAttachment): MessageAttachment {
return {
attachment_id: attachment.attachment_id,
@@ -192,7 +204,7 @@ export async function collectEvidence({
throw InputValidationError.fromCode(entryPath, ValidationErrorCodes.ENFORCEMENT_EVIDENCE_NOT_SUBJECT);
}
const channel = await findChannel(channelId);
- if (channel && isConversation(channel.type) && !reports.some((report) => report.reportedChannelId === channelId)) {
+ if (channel && isConversation(channel.type) && !reports.some((report) => coversConversation(report, channel))) {
throw InputValidationError.fromCode(entryPath, ValidationErrorCodes.ENFORCEMENT_EVIDENCE_DM_UNREPORTED);
}
collected.set(message.id, fromLiveMessage(message, subject.type === 'user' ? subject : UNKNOWN_AUTHOR));
diff --git a/fluxer_api/src/api/enforcement/tests/EnforcementValidation.test.ts b/fluxer_api/src/api/enforcement/tests/EnforcementValidation.test.ts
index 7a4708e51..017771ac7 100644
--- a/fluxer_api/src/api/enforcement/tests/EnforcementValidation.test.ts
+++ b/fluxer_api/src/api/enforcement/tests/EnforcementValidation.test.ts
@@ -227,6 +227,35 @@ describe('Enforcement decision validation', () => {
);
});
+ test('a user report covers the direct message between the reporter and the reported user', async () => {
+ const target = await createTestAccount(harness);
+ const recipient = await createTestAccount(harness);
+ const bystander = await createTestAccount(harness);
+ await createFriendship(harness, target, recipient);
+ const dm = await createDmChannel(harness, target.token, recipient.userId);
+ const message = await sendChannelMessage(harness, target.token, dm.id, 'send me your password');
+ const evidence = [{channel_id: dm.id, message_id: message.id}];
+ const userReport = async (reporter: TestAccount) =>
+ (
+ await createBuilder<{report_id: string}>(harness, reporter.token)
+ .post('/reports/user')
+ .body({user_id: target.userId, category: 'harassment'})
+ .expect(HTTP_STATUS.OK)
+ .execute()
+ ).report_id;
+ const fromBystander = await userReport(bystander);
+ expect(
+ await refusedSuspension(target, decisionBody({source: 'report', report_ids: [fromBystander], evidence})),
+ ).toMatchObject({code: ValidationErrorCodes.ENFORCEMENT_EVIDENCE_DM_UNREPORTED});
+ const fromRecipient = await userReport(recipient);
+ await suspend(
+ harness,
+ staff,
+ target.userId,
+ decisionBody({source: 'report', report_ids: [fromRecipient], evidence}),
+ );
+ });
+
test('a decision needs evidence or a note to the user', async () => {
const target = await createTestAccount(harness);
expect(await refusedSuspension(target, decisionBody({statement: undefined}))).toMatchObject({