From 01b5d26b62d8fb515acd08cb2d4eea5240b72d71 Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Wed, 13 Apr 2022 13:51:25 +0300 Subject: [PATCH] Fix a bug in guard regarding deprecated method isLoggedIn --- src/app/openaireLibrary | 2 +- src/app/utils/adminDashboard.guard.ts | 28 +++++++++++---------------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/app/openaireLibrary b/src/app/openaireLibrary index e6b2f41..d9a2f3b 160000 --- a/src/app/openaireLibrary +++ b/src/app/openaireLibrary @@ -1 +1 @@ -Subproject commit e6b2f41c8c858f860ed4bf48d7a31e5a04d7a088 +Subproject commit d9a2f3b0eee5348accb910e304006ccb38804775 diff --git a/src/app/utils/adminDashboard.guard.ts b/src/app/utils/adminDashboard.guard.ts index c440582..99d3b33 100644 --- a/src/app/utils/adminDashboard.guard.ts +++ b/src/app/utils/adminDashboard.guard.ts @@ -24,23 +24,17 @@ export class AdminDashboardGuard implements CanActivate, CanActivateChild { } check(path: string, alias: string): Observable | boolean { - if (Session.isLoggedIn()) { - return zip( - this.userManagementService.getUserInfo(false) - ,this.stakeholderService.getStakeholder(alias) - ).pipe(take(1),map(res =>{ - return res[0] && res[1] && (Session.isPortalAdministrator(res[0]) || - Session.isCurator(res[1].type, res[0]) || Session.isManager(res[1].type, res[1].alias, res[0])); - }),tap(authorized => { - if(!authorized){ - this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_ADMIN, 'redirectUrl':path}}); - } - })); - - } else { - this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_LOGIN, 'redirectUrl':path}}); - return false; - } + return zip( + this.userManagementService.getUserInfo(false) + ,this.stakeholderService.getStakeholder(alias) + ).pipe(take(1),map(res =>{ + return res[0] && res[1] && (Session.isPortalAdministrator(res[0]) || + Session.isCurator(res[1].type, res[0]) || Session.isManager(res[1].type, res[1].alias, res[0])); + }),tap(authorized => { + if(!authorized){ + this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_ADMIN, 'redirectUrl':path}}); + } + })); } canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | Promise | boolean | UrlTree {