From f9709887b63bd1c9259a5cfb9857126d870c1d72 Mon Sep 17 00:00:00 2001 From: Stephan Girod Date: Fri, 23 Aug 2024 11:53:47 +0200 Subject: [PATCH] refactor: currying isAllowed to clean up callers --- AMW_angular/io/src/app/auth/auth.service.ts | 7 +++++-- .../deployment-parameter/deployment-parameter.component.ts | 4 ++-- .../io/src/app/settings/releases/releases.component.ts | 6 +++--- AMW_angular/io/src/app/settings/tags/tags.component.ts | 4 ++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/AMW_angular/io/src/app/auth/auth.service.ts b/AMW_angular/io/src/app/auth/auth.service.ts index e98d58b86..23b8e518f 100644 --- a/AMW_angular/io/src/app/auth/auth.service.ts +++ b/AMW_angular/io/src/app/auth/auth.service.ts @@ -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; + }; } diff --git a/AMW_angular/io/src/app/settings/deployment-parameter/deployment-parameter.component.ts b/AMW_angular/io/src/app/settings/deployment-parameter/deployment-parameter.component.ts index 8e862d36b..5ae6f5dfc 100644 --- a/AMW_angular/io/src/app/settings/deployment-parameter/deployment-parameter.component.ts +++ b/AMW_angular/io/src/app/settings/deployment-parameter/deployment-parameter.component.ts @@ -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 { diff --git a/AMW_angular/io/src/app/settings/releases/releases.component.ts b/AMW_angular/io/src/app/settings/releases/releases.component.ts index 2610f8707..dc8769dec 100644 --- a/AMW_angular/io/src/app/settings/releases/releases.component.ts +++ b/AMW_angular/io/src/app/settings/releases/releases.component.ts @@ -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() { diff --git a/AMW_angular/io/src/app/settings/tags/tags.component.ts b/AMW_angular/io/src/app/settings/tags/tags.component.ts index 4c0631994..014e899ac 100644 --- a/AMW_angular/io/src/app/settings/tags/tags.component.ts +++ b/AMW_angular/io/src/app/settings/tags/tags.component.ts @@ -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 {