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