From 3b73322da7221ce66ac02a2257776e1c4fa9acc6 Mon Sep 17 00:00:00 2001 From: Tobias Soloschenko Date: Mon, 22 May 2023 13:40:47 +0200 Subject: [PATCH 1/2] feat: refactoring security.guard.ts --- ui/src/app/security/support/security.guard.ts | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/ui/src/app/security/support/security.guard.ts b/ui/src/app/security/support/security.guard.ts index 038e960a0..9e4231115 100644 --- a/ui/src/app/security/support/security.guard.ts +++ b/ui/src/app/security/support/security.guard.ts @@ -13,25 +13,27 @@ export class SecurityGuard implements CanActivate { const featureNeeded: string = route.data.feature; if (featureNeeded) { if ((await this.aboutService.isFeatureEnabled(featureNeeded)) === false) { - this.router.navigate(['feature-disabled']); + await this.router.navigate(['feature-disabled']); } } - const canAccess = await this.securityService.canAccess(rolesNeeded); - if (canAccess) { + // Check if the role requirements are met + if (await this.securityService.canAccess(rolesNeeded)) { return true; } - const securityEnabled = await this.securityService.securityEnabled().pipe(take(1)).toPromise(); - if (securityEnabled) { - const loggedInUser = await this.securityService.loggedinUser().pipe(take(1)).toPromise(); - if (loggedInUser) { - this.router.navigate(['roles-missing']); - } else { - this.router.navigate(['authentication-required']); - } - } else { + + // Check if security is disabled + if (!(await this.securityService.securityEnabled().pipe(take(1)))) { return true; } + + // Check if the user is authenticated, otherwise navigate to authentication / role missing page + if (await this.securityService.loggedinUser().pipe(take(1))) { + await this.router.navigate(['roles-missing']); + } else { + await this.router.navigate(['authentication-required']); + } + return false; } } From c99c4641285a61f7266a63a0d09e6f297e993c6f Mon Sep 17 00:00:00 2001 From: Tobias Soloschenko Date: Mon, 22 May 2023 19:25:27 +0200 Subject: [PATCH 2/2] test: trigger rebuild --- ui/src/app/security/support/security.guard.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/src/app/security/support/security.guard.ts b/ui/src/app/security/support/security.guard.ts index 9e4231115..df1b6fae6 100644 --- a/ui/src/app/security/support/security.guard.ts +++ b/ui/src/app/security/support/security.guard.ts @@ -17,17 +17,17 @@ export class SecurityGuard implements CanActivate { } } - // Check if the role requirements are met + // Check if the role requirements are met. if (await this.securityService.canAccess(rolesNeeded)) { return true; } - // Check if security is disabled + // Check if security is disabled. if (!(await this.securityService.securityEnabled().pipe(take(1)))) { return true; } - // Check if the user is authenticated, otherwise navigate to authentication / role missing page + // Check if the user is authenticated, otherwise navigate to authentication / role missing page. if (await this.securityService.loggedinUser().pipe(take(1))) { await this.router.navigate(['roles-missing']); } else {