Fix a bug in guard regarding deprecated method isLoggedIn

This commit is contained in:
Konstantinos Triantafyllou 2022-04-13 13:51:25 +03:00
parent 56a877461d
commit 01b5d26b62
2 changed files with 12 additions and 18 deletions

@ -1 +1 @@
Subproject commit e6b2f41c8c858f860ed4bf48d7a31e5a04d7a088 Subproject commit d9a2f3b0eee5348accb910e304006ccb38804775

View File

@ -24,23 +24,17 @@ export class AdminDashboardGuard implements CanActivate, CanActivateChild {
} }
check(path: string, alias: string): Observable<boolean> | boolean { check(path: string, alias: string): Observable<boolean> | boolean {
if (Session.isLoggedIn()) { return zip(
return zip( this.userManagementService.getUserInfo(false)
this.userManagementService.getUserInfo(false) ,this.stakeholderService.getStakeholder(alias)
,this.stakeholderService.getStakeholder(alias) ).pipe(take(1),map(res =>{
).pipe(take(1),map(res =>{ return res[0] && res[1] && (Session.isPortalAdministrator(res[0]) ||
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]));
Session.isCurator(res[1].type, res[0]) || Session.isManager(res[1].type, res[1].alias, res[0])); }),tap(authorized => {
}),tap(authorized => { if(!authorized){
if(!authorized){ this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_ADMIN, 'redirectUrl':path}});
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;
}
} }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree { canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {