feat: Whitelist user's from workflow spam scanning (#20717)
* Add whitelistWorkflows to user * Do not autolock whitelisted users * Add endpoint to whitelist a user * Get users data - include whitelistWorkflows * Whitelist a user on the user admin page * Fix typo * Add test * Use translations * Add `updateWhitelistWorkflows` to `UserRepository` * Use i18 for strings * Rename to whitelistWorkflows --------- Co-authored-by: Benny Joo <[email protected]>
This commit is contained in:
1 parent
515f3263e0
commit
a82d616b79
11 files changed
+110
-2
No files matched your search
@@ -172,4 +172,23 @@ describe("scanWorkflowBody", () => {
|
||||
|
||||
expect(scheduleWorkflowNotifications).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should handle whitelisted user being flagged as spam", async () => {
|
||||
const payload = JSON.stringify({
|
||||
userId: 1,
|
||||
workflowStepIds: [1],
|
||||
});
|
||||
|
||||
prismaMock.workflowStep.findMany.mockResolvedValue([
|
||||
{ ...mockWorkflowStep, workflow: { user: { whitelistWorkflows: true } } },
|
||||
]);
|
||||
prismaMock.workflow.findFirst.mockResolvedValue(mockWorkflow);
|
||||
mockAkismetCheckSpam.mockResolvedValue(true);
|
||||
|
||||
await scanWorkflowBody(payload);
|
||||
|
||||
expect(mockAkismetCheckSpam).toHaveBeenCalled();
|
||||
expect(prismaMock.workflowStep.update).not.toHaveBeenCalled();
|
||||
expect(lockUser).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -40,6 +40,7 @@ export async function scanWorkflowBody(payload: string) {
|
||||
select: {
|
||||
locale: true,
|
||||
timeFormat: true,
|
||||
whitelistWorkflows: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -100,6 +101,13 @@ export async function scanWorkflowBody(payload: string) {
|
||||
const isSpam = await client.checkSpam(comment);
|
||||
|
||||
if (isSpam) {
|
||||
if (workflowStep.workflow.user?.whitelistWorkflows) {
|
||||
log.warn(
|
||||
`For whitelisted user, workflow step ${workflowStep.id} is spam with body ${workflowStep.reminderBody}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// We won't delete the workflow step incase it is flagged as a false positive
|
||||
log.warn(`Workflow step ${workflowStep.id} is spam with body ${workflowStep.reminderBody}`);
|
||||
await lockUser("userId", userId.toString(), LockReason.SPAM_WORKFLOW_BODY);
|
||||
|
||||
Reference in new issue
Block a user