Skip to content

Commit b37106e

Browse files
authored
Merge pull request #3244 from SeedCompany/project-workflow
2 parents dc4f011 + 255e1ad commit b37106e

18 files changed

+111
-69
lines changed

src/components/authorization/policies/conditions/creator.condition.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
AsCypherParams,
1515
Condition,
1616
IsAllowedParams,
17+
MissingContextException,
1718
} from '../../policy/conditions';
1819

1920
const CQL_VAR = 'requestingUser';
@@ -27,7 +28,7 @@ class CreatorCondition<TResourceStatic extends ResourceShape<HasCreator>>
2728
{
2829
isAllowed({ object, session }: IsAllowedParams<TResourceStatic>) {
2930
if (!object) {
30-
throw new Error("Needed object but wasn't given");
31+
throw new MissingContextException();
3132
}
3233

3334
const creator = (() => {

src/components/authorization/policies/conditions/enum-field.condition.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
Condition,
99
eqlInLiteralSet,
1010
IsAllowedParams,
11+
MissingContextException,
1112
} from '../../policy/conditions';
1213

1314
export class EnumFieldCondition<
@@ -25,14 +26,18 @@ export class EnumFieldCondition<
2526
// Double check at runtime that object has these, since they are usually
2627
// declared from DB, which cannot be verified.
2728
if (!object) {
28-
throw new Error(`Needed object's ${this.path} but object wasn't given`);
29+
throw new MissingContextException(
30+
`Needed object's ${this.path} but object wasn't given`,
31+
);
2932
}
3033
const value = get(object, this.path) as
3134
| Get<InstanceType<TResourceStatic>, Path>
3235
| undefined;
3336
const actual = unwrapSecured(value);
3437
if (!actual) {
35-
throw new Error(`Needed object's ${this.path} but it wasn't found`);
38+
throw new MissingContextException(
39+
`Needed object's ${this.path} but it wasn't found`,
40+
);
3641
}
3742

3843
return this.allowed.has(actual);

src/components/authorization/policies/conditions/self.condition.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
Condition,
88
fqnRelativeTo,
99
IsAllowedParams,
10+
MissingContextException,
1011
} from '../../policy/conditions';
1112

1213
const CQL_VAR = 'requestingUser';
@@ -16,7 +17,7 @@ class SelfCondition<TResourceStatic extends typeof User>
1617
{
1718
isAllowed({ object, session }: IsAllowedParams<TResourceStatic>) {
1819
if (!object) {
19-
throw new Error("Needed user object but wasn't given");
20+
throw new MissingContextException();
2021
}
2122
return object.id === session.userId;
2223
}

src/components/authorization/policies/conditions/sensitivity.condition.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
Condition,
88
fqnRelativeTo,
99
IsAllowedParams,
10+
MissingContextException,
1011
} from '../../policy/conditions';
1112

1213
const sensitivityRank = { High: 3, Medium: 2, Low: 1 };
@@ -32,14 +33,14 @@ export class SensitivityCondition<
3233
// Double check at runtime that object has these, since they are usually
3334
// declared from DB which cannot be verified.
3435
if (!object) {
35-
throw new Error("Needed object's sensitivity but object wasn't given");
36+
throw new MissingContextException();
3637
}
3738
const actual: Sensitivity | undefined =
3839
Reflect.get(object, EffectiveSensitivity) ??
3940
Reflect.get(object, 'sensitivity');
4041

4142
if (!actual) {
42-
throw new Error(
43+
throw new MissingContextException(
4344
"Needed object's sensitivity but object's sensitivity wasn't given",
4445
);
4546
}

src/components/authorization/policies/conditions/variant.condition.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
Condition,
77
eqlInLiteralSet,
88
IsAllowedParams,
9+
MissingContextException,
910
} from '../../policy/conditions';
1011

1112
const VariantForCondition = Symbol('Variant');
@@ -21,7 +22,7 @@ export class VariantCondition<TResourceStatic extends ResourceShape<any>>
2122

2223
isAllowed({ object }: IsAllowedParams<TResourceStatic>) {
2324
if (!object) {
24-
throw new Error("Needed object but wasn't given");
25+
throw new MissingContextException();
2526
}
2627

2728
const current = Reflect.get(

src/components/authorization/policy/conditions/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './condition.interface';
2+
export * from './missing-context.exception';
23
export * from './aggregate.condition';
34
export * from './calculated.condition';
45
export * from './eql.util';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { ServerException } from '~/common';
2+
3+
export class MissingContextException extends ServerException {
4+
constructor(message?: string, cause?: Error) {
5+
super(message ?? "Needed context object but wasn't given", cause);
6+
}
7+
}
File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export * from './execute-progress-report-transition.input';
1+
export * from './execute-project-transition.input';
22
export * from './workflow-event.dto';
33
export * from './workflow-transition.dto';

src/components/project/workflow/project-workflow.service.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ export class ProjectWorkflowService extends WorkflowService(
5757
);
5858
}
5959

60-
canBypass(session: Session) {
61-
return this.privileges.for(session, WorkflowEvent).can('create');
62-
}
63-
6460
async executeTransition(
6561
input: ExecuteProjectTransitionInput,
6662
session: Session,

0 commit comments

Comments
 (0)