Skip to content

Commit 656a11d

Browse files
committed
fix: check for createdBy if updatedBy workflow
1 parent 2d153ae commit 656a11d

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

packages/backend/src/apps/gathersg/__tests__/auth/schema.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,5 +308,39 @@ describe('gathersg auth schema', () => {
308308
})
309309
expect(result.success).toBe(false)
310310
})
311+
312+
it('rejects Workflow updatedBy without createdBy', () => {
313+
const result = schema.safeParse({
314+
updatedBy: {
315+
name: 'Workflow',
316+
},
317+
})
318+
expect(result.success).toBe(false)
319+
})
320+
321+
it('rejects Workflow updatedBy when createdBy is missing email', () => {
322+
const result = schema.safeParse({
323+
updatedBy: {
324+
name: 'Workflow',
325+
},
326+
createdBy: {
327+
name: 'Creator',
328+
},
329+
})
330+
expect(result.success).toBe(false)
331+
})
332+
333+
it('rejects Workflow updatedBy when createdBy email is null', () => {
334+
const result = schema.safeParse({
335+
updatedBy: {
336+
name: 'Workflow',
337+
},
338+
createdBy: {
339+
email: null,
340+
name: 'Creator',
341+
},
342+
})
343+
expect(result.success).toBe(false)
344+
})
311345
})
312346
})

packages/backend/src/apps/gathersg/auth/schema.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,19 @@ const schema = z
3636
if (updatedBy.name === 'Workflow') {
3737
/**
3838
* SPECIAL CASE
39-
* if the workflow had an update step before sending the webhook,
39+
* if the workflow has an update step before calling the webhook,
4040
* the webhook will return with:
4141
* {
4242
* updatedBy: {
4343
* name: 'Workflow',
4444
* },
4545
* }
46+
*
47+
* Best effort check that createdBy must contain both email and name
48+
* to know that its not an API creating the case and an instant workflow
49+
* calling Plumber again.
4650
*/
47-
return !updatedBy.email
51+
return !updatedBy.email && !!createdBy?.email && !!createdBy?.name
4852
}
4953
return !!updatedBy.email
5054
}

0 commit comments

Comments
 (0)