Skip to content

Commit e2e1ac7

Browse files
committed
Polish EngagementRules current roles handling
1 parent decf62e commit e2e1ac7

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

src/components/engagement/engagement-status.resolver.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export class EngagementStatusResolver {
2020
}
2121
return await this.engagementRules.getAvailableTransitions(
2222
status.parentId,
23-
undefined,
2423
status.changeset,
2524
);
2625
}
@@ -31,7 +30,7 @@ export class EngagementStatusResolver {
3130
and change the status to any other status?
3231
`,
3332
})
34-
async canBypassTransitions(): Promise<boolean> {
35-
return await this.engagementRules.canBypassWorkflow();
33+
canBypassTransitions(): boolean {
34+
return this.engagementRules.canBypassWorkflow();
3635
}
3736
}

src/components/engagement/engagement.rules.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ export class EngagementRules {
313313

314314
async getAvailableTransitions(
315315
engagementId: ID,
316-
currentUserRoles?: readonly Role[],
317316
changeset?: ID,
318317
): Promise<EngagementStatusTransition[]> {
319318
const session = this.identity.current;
@@ -329,7 +328,7 @@ export class EngagementRules {
329328
);
330329

331330
// If current user is not an approver (based on roles) then don't allow any transitions
332-
currentUserRoles ??= session.roles;
331+
const currentUserRoles = session.roles;
333332
if (intersection(approvers, currentUserRoles).length === 0) {
334333
return [];
335334
}
@@ -355,9 +354,8 @@ export class EngagementRules {
355354
return availableTransitionsAccordingToProject;
356355
}
357356

358-
async canBypassWorkflow() {
359-
const session = this.identity.current;
360-
const roles = session.roles;
357+
canBypassWorkflow() {
358+
const { roles } = this.identity.current;
361359
return intersection(rolesThatCanBypassWorkflow, roles).length > 0;
362360
}
363361

@@ -366,17 +364,12 @@ export class EngagementRules {
366364
nextStatus: EngagementStatus,
367365
changeset?: ID,
368366
) {
369-
// If current user's roles include a role that can bypass workflow
370-
// stop the check here.
371-
const session = this.identity.current;
372-
const currentUserRoles = session.roles;
373-
if (intersection(rolesThatCanBypassWorkflow, currentUserRoles).length > 0) {
367+
if (this.canBypassWorkflow()) {
374368
return;
375369
}
376370

377371
const transitions = await this.getAvailableTransitions(
378372
engagementId,
379-
currentUserRoles,
380373
changeset,
381374
);
382375

0 commit comments

Comments
 (0)