-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: org-wide workflows #15083
base: main
Are you sure you want to change the base?
feat: org-wide workflows #15083
Conversation
const reminderMethods: { [x: string]: (id: number, referenceId: string | null) => void } = { | ||
[WorkflowMethods.EMAIL]: deleteScheduledEmailReminder, | ||
[WorkflowMethods.SMS]: deleteScheduledSMSReminder, | ||
[WorkflowMethods.WHATSAPP]: deleteScheduledWhatsappReminder, | ||
}; | ||
|
||
export const cancelWorkflowReminders = async ( | ||
workflowReminders: { method: WorkflowMethods; id: number; referenceId: string | null }[] | ||
) => { | ||
await Promise.all( | ||
workflowReminders.map((reminder) => { | ||
return reminderMethods[reminder.method](reminder.id, reminder.referenceId); | ||
}) | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to viewer/workflows/util.ts
and renamed to deleteWorkflowReminders
|
||
if (orgId) { | ||
if (teamId) { | ||
const orgTeamWorkflowsRel = await prisma.workflowsOnTeams.findMany({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all active org workflows that are active on the team of the event type
const orgTeamWorkflows = orgTeamWorkflowsRel?.map((workflowRel) => workflowRel.workflow) ?? []; | ||
allWorkflows.push(...orgTeamWorkflows); | ||
} else if (userId) { | ||
const orgUserWorkflowsRel = await prisma.workflowsOnTeams.findMany({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all active org workflows where user is part of a team that is active on workflow
allWorkflows.push(...orgUserWorkflows); | ||
} | ||
|
||
const activeOnAllOrgWorkflows = await prisma.workflow.findMany({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all org workflows where isActiveOnAll
is true, duplicated are removed later
} | ||
|
||
if (teamId) { | ||
const activeOnAllTeamWorkflows = await prisma.workflow.findMany({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All normal team workflows where isActiveOnAll
is true. Other active workflows are already included in eventTypeWorkflows
const verifyEmailSender = async ( | ||
email: string, | ||
userId: number, | ||
teamId: number | null, | ||
prisma: PrismaClient | ||
) => { | ||
const verifiedEmail = await prisma.verifiedEmail.findFirst({ | ||
where: { | ||
email, | ||
OR: [{ userId }, { teamId }], | ||
}, | ||
}); | ||
|
||
if (!verifiedEmail) { | ||
throw new TRPCError({ code: "NOT_FOUND", message: "Email not verified" }); | ||
} | ||
|
||
if (teamId) { | ||
if (!verifiedEmail.teamId) { | ||
await prisma.verifiedEmail.update({ | ||
where: { | ||
id: verifiedEmail.id, | ||
}, | ||
data: { | ||
teamId, | ||
}, | ||
}); | ||
} else if (verifiedEmail.teamId !== teamId) { | ||
await prisma.verifiedEmail.create({ | ||
data: { | ||
email, | ||
userId, | ||
teamId, | ||
}, | ||
}); | ||
} | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
verifyEmailSender
was moved to workfows/utils.ts
https://github.com/calcom/cal.com/pull/15083/files#diff-f6ef6880041c2afa0023a8b231030af6fc89b5c067f3920efa906890c100734fR71
for (const newEventTypeId of newActiveEventTypes) { | ||
const newEventType = await ctx.prisma.eventType.findFirst({ | ||
if (!isOrg) { | ||
// activeOn are event types ids |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code didn't change much from before
eventTypeId, | ||
})), | ||
}); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the else part handles updating org workflows, that's new code
} | ||
|
||
//todo: test this | ||
if (userWorkflow.trigger !== trigger) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updating already scheduled reminders when trigger is changed was not handled before, this was a bug
const eventTypeOptions = useMemo( | ||
() => | ||
data?.eventTypeGroups.reduce((options, group) => { | ||
/** don't show team event types for user workflow */ | ||
if (!teamId && group.teamId) return options; | ||
/** only show correct team event types for team workflows */ | ||
if (teamId && teamId !== group.teamId) return options; | ||
return [ | ||
...options, | ||
...group.eventTypes | ||
.filter( | ||
(evType) => | ||
!evType.metadata?.managedEventConfig || | ||
!!evType.metadata?.managedEventConfig.unlockedFields?.workflows || | ||
!!teamId | ||
) | ||
.map((eventType) => ({ | ||
value: String(eventType.id), | ||
label: `${eventType.title} ${ | ||
eventType.children && eventType.children.length ? `(+${eventType.children.length})` : `` | ||
}`, | ||
})), | ||
]; | ||
}, [] as Option[]) || [], | ||
[data] | ||
); | ||
|
||
let allEventTypeOptions = eventTypeOptions; | ||
const distinctEventTypes = new Set(); | ||
|
||
if (!teamId && isMixedEventType) { | ||
allEventTypeOptions = [...eventTypeOptions, ...selectedEventTypes]; | ||
allEventTypeOptions = allEventTypeOptions.filter((option) => { | ||
const duplicate = distinctEventTypes.has(option.value); | ||
distinctEventTypes.add(option.value); | ||
return !duplicate; | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to parent component workflow.tsx
Graphite Automations"Add foundation team as reviewer" took an action on this PR • (06/11/24)1 reviewer was added to this PR based on Keith Williams's automation. "Add consumer team as reviewer" took an action on this PR • (06/11/24)1 reviewer was added to this PR based on Keith Williams's automation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting my head around workflows right now. So, submitting partial review
return workflow; | ||
} | ||
|
||
describe("deleteRemindersFromRemovedActiveOn", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
describe("deleteRemindersFromRemovedActiveOn", () => { | |
describe("deleteRemindersOfActiveOnIds", () => { |
//team event types + children managed event types | ||
booking: { | ||
eventType: { | ||
OR: [{ teamId: teamId }, { parentId: teamId, teamId: null }], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't parentId
an eventTypeId ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting my head around workflows right now. So, submitting partial review
What does this PR do?
workflows/update.handler
is refactored into smaller functions that can be reused and tested.Fixes #14638
Fixes CAL-3489
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
Basic test:
Test other cases, for example:
WorkflowReminders
are correctly adjusted