From 91176e42ea2ad56fedf7c5dfeaac9775d8d0482b Mon Sep 17 00:00:00 2001 From: Mitch Miller Date: Wed, 18 Feb 2026 22:46:55 -0500 Subject: [PATCH] made hasRoles work again --- src/app/core/auth/auth.model.ts | 4 +++- src/app/core/auth/auth.service.ts | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/app/core/auth/auth.model.ts b/src/app/core/auth/auth.model.ts index 58b908346..c9ceaae74 100644 --- a/src/app/core/auth/auth.model.ts +++ b/src/app/core/auth/auth.model.ts @@ -52,4 +52,6 @@ export interface Privilege { privilege: string; } -export type Role = 'Updater'|'Admin'|'Query'|'SuperUpdate'|'DataEntry'|'SuperDataEntry'|'Approver'; +export type Role ={ + role: string; +} diff --git a/src/app/core/auth/auth.service.ts b/src/app/core/auth/auth.service.ts index 1cf0f8e69..00828d025 100644 --- a/src/app/core/auth/auth.service.ts +++ b/src/app/core/auth/auth.service.ts @@ -156,14 +156,14 @@ get auth(): Auth { } } - hasRoles(...roles: Array): boolean { + hasRoles(...roles: Array): boolean { const rolesList = [...roles]; - + const checkableRoles = this._auth.roles.map((x: Role) => x.role.toUpperCase()); + if (this._auth && this._auth.roles && rolesList && rolesList.length) { for (const r of rolesList) { - let role = r.charAt(0).toLowerCase() + r.slice(1); - role = role.charAt(0).toUpperCase() + role.slice(1); - if (this._auth.roles.indexOf(role as Role) === -1) { + let role = r.toUpperCase(); + if (checkableRoles.indexOf(role) === -1) { return false; } } @@ -193,7 +193,7 @@ get auth(): Auth { return true; } - hasRolesAsync(...roles: Array): Observable { + hasRolesAsync(...roles: Array< string>): Observable { return new Observable(observer => { if (this.auth != null) { observer.next(this.hasRoles(...roles)); @@ -207,13 +207,13 @@ get auth(): Auth { }); } - hasAnyRoles(...roles: Array): boolean { + hasAnyRoles(...roles: Array): boolean { const rolesList = [...roles]; + const checkableRoles = this._auth.roles.map((x: Role) => x.role.toUpperCase()); if (this._auth && this._auth.roles && rolesList && rolesList.length) { for (const r of rolesList) { - let role = r.charAt(0).toLowerCase() + r.slice(1); - role = role.charAt(0).toUpperCase() + role.slice(1); - if (this._auth.roles.indexOf(role as Role) > -1) { + let role = r.toUpperCase(); + if (checkableRoles.indexOf(role) === -1) { return true; } } @@ -248,7 +248,7 @@ get auth(): Auth { return this._privileges != null && this._privileges.some(p=>p.privilege==requestedPrivilege); } - hasAnyRolesAsync(...roles: Array): Observable { + hasAnyRolesAsync(...roles: Array): Observable { return new Observable(observer => { if (this.auth != null) { observer.next(this.hasAnyRoles(...roles));