]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/services/feature-toggles-guard.service.ts
import ceph 16.2.6
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / services / feature-toggles-guard.service.ts
CommitLineData
11fdf7f2 1import { Injectable } from '@angular/core';
f67539c2 2import { ActivatedRouteSnapshot, CanActivate, CanActivateChild } from '@angular/router';
11fdf7f2
TL
3
4import { map } from 'rxjs/operators';
5
f67539c2 6import { DashboardNotFoundError } from '~/app/core/error/error';
11fdf7f2 7import { FeatureTogglesMap, FeatureTogglesService } from './feature-toggles.service';
11fdf7f2
TL
8
9@Injectable({
81eedcae 10 providedIn: 'root'
11fdf7f2
TL
11})
12export class FeatureTogglesGuardService implements CanActivate, CanActivateChild {
f67539c2 13 constructor(private featureToggles: FeatureTogglesService) {}
11fdf7f2
TL
14
15 canActivate(route: ActivatedRouteSnapshot) {
16 return this.featureToggles.get().pipe(
17 map((enabledFeatures: FeatureTogglesMap) => {
18 if (enabledFeatures[route.routeConfig.path] === false) {
f67539c2 19 throw new DashboardNotFoundError();
11fdf7f2
TL
20 return false;
21 }
22 return true;
23 })
24 );
25 }
26
27 canActivateChild(route: ActivatedRouteSnapshot) {
28 return this.canActivate(route.parent);
29 }
30}