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
@@ -122,6 +122,16 @@ function UsersTableBare() {
|
||||
const verifyWorkflows = trpc.viewer.admin.verifyWorkflows.useMutation({
|
||||
onSuccess: () => {
|
||||
showToast("Workflows verified", "success");
|
||||
utils.viewer.admin.listPaginated.invalidate();
|
||||
},
|
||||
});
|
||||
const whitelistUserWorkflows = trpc.viewer.admin.whitelistUserWorkflows.useMutation({
|
||||
onSuccess: (data) => {
|
||||
showToast(
|
||||
data.whitelistWorkflows ? t("user_workflows_whitelisted") : t("user_workflows_unwhitelisted"),
|
||||
"success"
|
||||
);
|
||||
utils.viewer.admin.listPaginated.invalidate();
|
||||
},
|
||||
});
|
||||
|
||||
@@ -248,6 +258,19 @@ function UsersTableBare() {
|
||||
onClick: () => verifyWorkflows.mutate({ userId: user.id }),
|
||||
icon: "check",
|
||||
},
|
||||
{
|
||||
id: "whitelist-user-workflows",
|
||||
label: user.whitelistWorkflows
|
||||
? t("remove_whitelist_status")
|
||||
: t("whitelist_user_workflows"),
|
||||
onClick: () => {
|
||||
whitelistUserWorkflows.mutate({
|
||||
userId: user.id,
|
||||
whitelistWorkflows: !user.whitelistWorkflows,
|
||||
});
|
||||
},
|
||||
icon: "check",
|
||||
},
|
||||
{
|
||||
id: "impersonation",
|
||||
label: "Impersonate",
|
||||
|
||||
@@ -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