From fcde529e5a82c2f11c36461e567f1c090c96aa22 Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Fri, 22 Dec 2023 19:13:26 +0200 Subject: [PATCH] [master | ADDED | WIP]: Add sandbox guard for managers. --- src/app/national/national.module.ts | 5 +++-- src/app/repository/repository.module.ts | 5 +++-- src/app/rfo/rfo.module.ts | 5 +++-- src/app/rpo/rpo.module.ts | 5 +++-- src/app/shared/sandbox.guard.ts | 15 +++++++++++++++ 5 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 src/app/shared/sandbox.guard.ts diff --git a/src/app/national/national.module.ts b/src/app/national/national.module.ts index 822f62f..d229aa0 100644 --- a/src/app/national/national.module.ts +++ b/src/app/national/national.module.ts @@ -7,12 +7,13 @@ import {RoleVerificationModule} from "../openaireLibrary/role-verification/role- import {IconsModule} from "../openaireLibrary/utils/icons/icons.module"; import {IconsService} from "../openaireLibrary/utils/icons/icons.service"; import {open_access} from "../openaireLibrary/utils/icons/icons"; +import {SandboxGuard} from "../shared/sandbox.guard"; const routes: Route[] = [ { path: '', component: NationalComponent, children: [ - {path: 'search', loadChildren: () => import('../search/search.module').then(m => m.SearchModule), data: {activeMenuItem: "national"}}, - {path: '', loadChildren: () => import('../shared/monitor/monitor.module').then(m => m.MonitorModule), data: {activeMenuItem: "national"}}, + {path: 'search', loadChildren: () => import('../search/search.module').then(m => m.SearchModule), data: {activeMenuItem: "national"}, canActivateChild: [SandboxGuard]}, + {path: '', loadChildren: () => import('../shared/monitor/monitor.module').then(m => m.MonitorModule), data: {activeMenuItem: "national"}, canActivateChild: [SandboxGuard]}, ], data: {stakeholder: 'irish'} } ]; diff --git a/src/app/repository/repository.module.ts b/src/app/repository/repository.module.ts index ab20215..57ea18b 100644 --- a/src/app/repository/repository.module.ts +++ b/src/app/repository/repository.module.ts @@ -10,13 +10,14 @@ import {EntityMetadataModule} from "../openaireLibrary/landingPages/landing-util import {IconsService} from "../openaireLibrary/utils/icons/icons.service"; import {open_access} from "../openaireLibrary/utils/icons/icons"; import {LogoUrlPipeModule} from "../openaireLibrary/utils/pipes/logoUrlPipe.module"; +import {SandboxGuard} from "../shared/sandbox.guard"; const routes: Route[] = [ { path: '', component: RepositoryComponent, children: [ {path: '', loadChildren: () => import('./browse-repositories/browse-repositories.module').then(m => m.BrowseRepositoriesModule)}, - {path: ':stakeholder/search', loadChildren: () => import('../search/resultLanding.module').then(m => m.ResultLandingModule)}, - {path: ':stakeholder', loadChildren: () => import('../shared/monitor/monitor.module').then(m => m.MonitorModule)} + {path: ':stakeholder/search', loadChildren: () => import('../search/resultLanding.module').then(m => m.ResultLandingModule), canActivateChild: [SandboxGuard]}, + {path: ':stakeholder', loadChildren: () => import('../shared/monitor/monitor.module').then(m => m.MonitorModule), canActivateChild: [SandboxGuard]} ] } ]; diff --git a/src/app/rfo/rfo.module.ts b/src/app/rfo/rfo.module.ts index 7c01cea..728c823 100644 --- a/src/app/rfo/rfo.module.ts +++ b/src/app/rfo/rfo.module.ts @@ -8,13 +8,14 @@ import {IconsModule} from "../openaireLibrary/utils/icons/icons.module"; import {LogoUrlPipeModule} from "../openaireLibrary/utils/pipes/logoUrlPipe.module"; import {IconsService} from "../openaireLibrary/utils/icons/icons.service"; import {open_access} from "../openaireLibrary/utils/icons/icons"; +import {SandboxGuard} from "../shared/sandbox.guard"; const routes: Route[] = [ { path: '', component: RfoComponent, children: [ {path: '', loadChildren: () => import('../shared/browse-stakeholders/browse-stakeholders.module').then(m => m.BrowseStakeholdersModule)}, - {path: ':stakeholder/search', loadChildren: () => import('../search/resultLanding.module').then(m => m.ResultLandingModule)}, - {path: ':stakeholder', loadChildren: () => import('../shared/monitor/monitor.module').then(m => m.MonitorModule)} + {path: ':stakeholder/search', loadChildren: () => import('../search/resultLanding.module').then(m => m.ResultLandingModule), canActivateChild: [SandboxGuard]}, + {path: ':stakeholder', loadChildren: () => import('../shared/monitor/monitor.module').then(m => m.MonitorModule), canActivateChild: [SandboxGuard]} ] } ]; diff --git a/src/app/rpo/rpo.module.ts b/src/app/rpo/rpo.module.ts index 0cdced4..a8fc9d8 100644 --- a/src/app/rpo/rpo.module.ts +++ b/src/app/rpo/rpo.module.ts @@ -8,13 +8,14 @@ import {IconsModule} from "../openaireLibrary/utils/icons/icons.module"; import {LogoUrlPipeModule} from "../openaireLibrary/utils/pipes/logoUrlPipe.module"; import {IconsService} from "../openaireLibrary/utils/icons/icons.service"; import {open_access} from "../openaireLibrary/utils/icons/icons"; +import {SandboxGuard} from "../shared/sandbox.guard"; const routes: Route[] = [ { path: '', component: RpoComponent, children: [ {path: '', loadChildren: () => import('../shared/browse-stakeholders/browse-stakeholders.module').then(m => m.BrowseStakeholdersModule)}, - {path: ':stakeholder/search', loadChildren: () => import('../search/resultLanding.module').then(m => m.ResultLandingModule)}, - {path: ':stakeholder', loadChildren: () => import('../shared/monitor/monitor.module').then(m => m.MonitorModule)} + {path: ':stakeholder/search', loadChildren: () => import('../search/resultLanding.module').then(m => m.ResultLandingModule), canActivateChild: [SandboxGuard]}, + {path: ':stakeholder', loadChildren: () => import('../shared/monitor/monitor.module').then(m => m.MonitorModule), canActivateChild: [SandboxGuard]} ] } ]; diff --git a/src/app/shared/sandbox.guard.ts b/src/app/shared/sandbox.guard.ts new file mode 100644 index 0000000..be96cb6 --- /dev/null +++ b/src/app/shared/sandbox.guard.ts @@ -0,0 +1,15 @@ +import {AdminDashboardGuard} from "../openaireLibrary/monitor-admin/utils/adminDashboard.guard"; +import {Injectable} from "@angular/core"; +import {ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree} from "@angular/router"; +import {Observable} from "rxjs"; +import {properties} from "../../environments/environment"; + +@Injectable({ + providedIn: 'root' +}) +export class SandboxGuard extends AdminDashboardGuard { + + canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | Promise | boolean | UrlTree { + return properties.environment != 'beta' || super.canActivateChild(childRoute, state); + } +}