]>
Commit | Line | Data |
---|---|---|
11fdf7f2 | 1 | import { Injectable } from '@angular/core'; |
f67539c2 | 2 | import { ActivatedRouteSnapshot, CanActivate, CanActivateChild } from '@angular/router'; |
11fdf7f2 TL |
3 | |
4 | import { map } from 'rxjs/operators'; | |
5 | ||
f67539c2 | 6 | import { DashboardNotFoundError } from '~/app/core/error/error'; |
11fdf7f2 | 7 | import { FeatureTogglesMap, FeatureTogglesService } from './feature-toggles.service'; |
11fdf7f2 TL |
8 | |
9 | @Injectable({ | |
81eedcae | 10 | providedIn: 'root' |
11fdf7f2 TL |
11 | }) |
12 | export 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 | } |