Skip to content

Commit 8b04bfe

Browse files
committed
Fix bypass check to ignore unmet condition requirements
1 parent 9ee5fc6 commit 8b04bfe

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/components/workflow/workflow.service.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Inject, Injectable } from '@nestjs/common';
22
import { Nil } from '@seedcompany/common';
33
import { ID, Session, UnauthorizedException } from '~/common';
44
import { Privileges } from '../authorization';
5+
import { MissingContextException } from '../authorization/policy/conditions';
56
import { Workflow } from './define-workflow';
67
import {
78
ExecuteTransitionInput as ExecuteTransitionInputFn,
@@ -104,9 +105,18 @@ export const WorkflowService = <W extends Workflow>(workflow: () => W) => {
104105
}
105106

106107
canBypass(session: Session) {
107-
return this.privileges
108-
.for(session, this.workflow.eventResource)
109-
.can('create');
108+
try {
109+
return this.privileges
110+
.for(session, this.workflow.eventResource)
111+
.can('create');
112+
} catch (e) {
113+
if (e instanceof MissingContextException) {
114+
// Missing context, means a condition was required.
115+
// Therefore, bypass is not allowed, as the convention is "condition-less execute"
116+
return false;
117+
}
118+
throw e;
119+
}
110120
}
111121

112122
protected getBypassIfValid(

0 commit comments

Comments
 (0)