Skip to content
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

Handle error workflows permissions #2908

Merged
merged 3 commits into from
Mar 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion packages/cli/src/WorkflowHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,33 @@ export async function executeErrorWorkflow(
): Promise<void> {
// Wrap everything in try/catch to make sure that no errors bubble up and all get caught here
try {
const workflowData = await Db.collections.Workflow!.findOne({ id: Number(workflowId) });
let workflowData;
if (workflowId.toString() !== workflowErrorData.workflow.id?.toString()) {
// To make this code easier to understand, we split it in 2 parts:
// 1) Fetch the owner of the errored workflows and then
// 2) if now instance owner, then check if the user has access to the
// triggered workflow.

const user = await getWorkflowOwner(workflowErrorData.workflow.id!);

if (user.globalRole.name === 'owner') {
workflowData = await Db.collections.Workflow!.findOne({ id: Number(workflowId) });
} else {
const { id: userId } = user;
const sharedWorkflowData = await Db.collections.SharedWorkflow!.findOne({
where: {
workflowId,
userId,
},
relations: ['workflow'],
});
krynble marked this conversation as resolved.
Show resolved Hide resolved
if (sharedWorkflowData) {
workflowData = sharedWorkflowData.workflow;
}
}
} else {
workflowData = await Db.collections.Workflow!.findOne({ id: Number(workflowId) });
}

if (workflowData === undefined) {
// The error workflow could not be found
Expand Down