Skip to content

Commit

Permalink
refactor: currying isAllowed to clean up callers
Browse files Browse the repository at this point in the history
  • Loading branch information
StephGit committed Aug 23, 2024
1 parent 8db243f commit f970988
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
7 changes: 5 additions & 2 deletions AMW_angular/io/src/app/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export class AuthService extends BaseService {
}
}

export function isAllowed(action: string, role: string) {
return action === 'ALL' || action === role;
// currying function which verifies roles in a action
export function isAllowed(role: string) {
return (action: string) => {
return action === 'ALL' || action === role;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export class DeploymentParameterComponent implements OnInit, OnDestroy {

private getUserPermissions() {
const actions = this.authService.getActionsForPermission('MANAGE_DEPLOYMENT_PARAMETER');
this.canCreate.set(actions.some((action) => isAllowed(action, 'CREATE')));
this.canDelete.set(actions.some((action) => isAllowed(action, 'DELETE')));
this.canCreate.set(actions.some(isAllowed('CREATE')));
this.canDelete.set(actions.some(isAllowed('DELETE')));
}

addKey(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ export class ReleasesComponent implements OnInit {

private getUserPermissions() {
const actions = this.authService.getActionsForPermission('RELEASE');
this.canCreate.set(actions.some((action) => isAllowed(action, 'CREATE')));
this.canEdit.set(actions.some((action) => isAllowed(action, 'UPDATE')));
this.canDelete.set(actions.some((action) => isAllowed(action, 'DELETE')));
this.canCreate.set(actions.some(isAllowed('CREATE')));
this.canEdit.set(actions.some(isAllowed('UPDATE')));
this.canDelete.set(actions.some(isAllowed('DELETE')));
}

private getReleases() {
Expand Down
4 changes: 2 additions & 2 deletions AMW_angular/io/src/app/settings/tags/tags.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export class TagsComponent implements OnInit, OnDestroy {

private getUserPermissions() {
const actions = this.authService.getActionsForPermission('MANAGE_GLOBAL_TAGS');
this.canCreate.set(actions.some((action) => isAllowed(action, 'CREATE')));
this.canDelete.set(actions.some((action) => isAllowed(action, 'DELETE')));
this.canCreate.set(actions.some(isAllowed('CREATE')));
this.canDelete.set(actions.some(isAllowed('DELETE')));
}

addTag(): void {
Expand Down

0 comments on commit f970988

Please sign in to comment.