[master]: Fix sandbox guard for researhcer

This commit is contained in:
Konstantinos Triantafyllou 2024-01-18 09:59:02 +02:00
parent 08ad6fbeb0
commit b0f6b9101b
3 changed files with 24 additions and 3 deletions

@ -1 +1 @@
Subproject commit 037c32c545c772c06f8a7a9a5d1da84d95b96522
Subproject commit e1f6549e891fab346b0f98448c7700aeab09fb99

View File

@ -15,7 +15,8 @@ const routes: Route[] = [
path: '', component: ResearcherComponent, children: [
{path: '', loadChildren: () => import('./search-researcher/search-researcher.module').then(m => m.SearchResearcherModule)},
{path: ':stakeholder/search', loadChildren: () => import('../search/resultLanding.module').then(m => m.ResultLandingModule)},
{path: ':stakeholder', loadChildren: () => import('../shared/monitor/monitor.module').then(m => m.MonitorModule), canActivateChild: [SandboxGuard]}
{path: ':stakeholder', loadChildren: () => import('../shared/monitor/monitor.module').then(m => m.MonitorModule), canActivateChild: [SandboxGuard],
data: {"researcher": true}}
]
}
];

View File

@ -3,6 +3,9 @@ import {Injectable} from "@angular/core";
import {ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree} from "@angular/router";
import {Observable} from "rxjs";
import {properties} from "../../environments/environment";
import {LoginErrorCodes} from "../openaireLibrary/login/utils/guardHelper.class";
import {map, tap} from "rxjs/operators";
import {Session} from "../openaireLibrary/login/utils/helper.class";
@Injectable({
providedIn: 'root'
@ -10,6 +13,23 @@ import {properties} from "../../environments/environment";
export class SandboxGuard extends AdminDashboardGuard {
canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
return properties.environment != 'beta' || super.canActivateChild(childRoute, state);
let sandbox = properties.environment !== 'beta'
if(childRoute.data['researcher'] && childRoute.params.stakeholder && sandbox) {
let errorCode = LoginErrorCodes.NOT_LOGIN;
let alias = childRoute.params.stakeholder;
return this.userManagementService.getUserInfo().pipe(map(user => {
if(user) {
errorCode = LoginErrorCodes.NOT_ADMIN;
}
return user && (Session.isPortalAdministrator(user) ||
Session.isCurator('researcher', user) || user?.orcid === alias);
}), tap(authorized => {
if(!authorized){
this.router.navigate(['/user-info'], {queryParams: {'errorCode': errorCode, 'redirectUrl':state.url}});
}
}));
} else {
return !sandbox || super.canActivateChild(childRoute, state);
}
}
}