mirror of
https://github.com/n8n-io/n8n.git
synced 2024-09-11 13:15:28 +03:00
Added permissions for error workflows
This commit is contained in:
parent
99cc33efa7
commit
bd3f5d134f
@ -100,7 +100,28 @@ 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 } = user;
|
||||
const qb = Db.collections.Workflow!.createQueryBuilder('w');
|
||||
qb.innerJoin('w.shared', 'shared');
|
||||
qb.andWhere('shared.user = :id', { id });
|
||||
qb.andWhere('w.id = :workflowId', { workflowId });
|
||||
workflowData = await qb.getOne();
|
||||
}
|
||||
} else {
|
||||
workflowData = await Db.collections.Workflow!.findOne({ id: Number(workflowId) });
|
||||
}
|
||||
|
||||
if (workflowData === undefined) {
|
||||
// The error workflow could not be found
|
||||
|
Loading…
Reference in New Issue
Block a user