Skip to content

Commit 2909183

Browse files
committed
HACK a custom label/id for momentum condition
1 parent 55777cd commit 2909183

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/components/authorization/policies/by-role/project-manager.policy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export const momentumProjectsTransitions = () =>
138138
).execute,
139139
// PMs can also endorse for consultant for momentum projects
140140
r.ProjectWorkflowEvent.whenAll(
141-
field('project.type', 'MomentumTranslation'),
141+
field('project.type', 'MomentumTranslation', 'Momentum'),
142142
member,
143143
r.ProjectWorkflowEvent.isTransitions(momentumProjectsTransitions),
144144
).execute,

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export class EnumFieldCondition<
1818
constructor(
1919
private readonly path: Path,
2020
private readonly allowed: ReadonlySet<ValueOfPath<TResourceStatic, Path>>,
21+
private readonly customId?: string,
2122
) {}
2223

2324
isAllowed({ object }: IsAllowedParams<TResourceStatic>) {
@@ -51,6 +52,7 @@ export class EnumFieldCondition<
5152
return new EnumFieldCondition(
5253
conditionsForField[0].path,
5354
new Set(unioned),
55+
conditions.length === 1 ? conditions[0].customId : undefined,
5456
);
5557
});
5658
}
@@ -63,11 +65,15 @@ export class EnumFieldCondition<
6365
return new EnumFieldCondition(
6466
conditionsForField[0].path,
6567
new Set(intersected),
68+
conditions.length === 1 ? conditions[0].customId : undefined,
6669
);
6770
});
6871
}
6972

7073
[inspect.custom](_depth: number, _options: InspectOptionsStylized) {
74+
if (this.customId) {
75+
return this.customId;
76+
}
7177
return `${startCase(this.path)} { ${[...this.allowed]
7278
.map((s) => startCase(s))
7379
.join(', ')} }`;
@@ -83,17 +89,19 @@ export function field<
8389
>(
8490
path: Path,
8591
allowed: ManyIn<ValueOfPath<TResourceStatic, Path>>,
86-
...allowedMore: Array<ManyIn<ValueOfPath<TResourceStatic, Path>>>
92+
customId?: string,
8793
) {
8894
const flattened = new Set(
89-
[allowed, ...allowedMore].flatMap((v) =>
90-
// Assume values are strings to normalize cardinality.
91-
typeof v === 'string'
92-
? [v]
93-
: [...(v as Array<ValueOfPath<TResourceStatic, Path>>)],
94-
),
95+
// Assume values are strings to normalize cardinality.
96+
typeof allowed === 'string'
97+
? [allowed]
98+
: [...(allowed as Array<ValueOfPath<TResourceStatic, Path>>)],
99+
);
100+
return new EnumFieldCondition<TResourceStatic, Path>(
101+
path,
102+
flattened,
103+
customId,
95104
);
96-
return new EnumFieldCondition<TResourceStatic, Path>(path, flattened);
97105
}
98106

99107
type ManyIn<T extends string> = T | Iterable<T>;

0 commit comments

Comments
 (0)