import { Injectable } from '@angular/core' ; import { CanActivate , ActivatedRouteSnapshot , RouterStateSnapshot , UrlTree , CanActivateChild } from '@angular/router' ; import { Observable } from 'rxjs' ; import { PermissionService } from '../services/permission.service' ; @ Injectable ( { providedIn : 'root' } ) export class PermissionGuard implements CanActivate , CanActivateChild { public constructor ( private permissionService ) { } public canActivate ( next , state ) { const right = next . data . right as string ; return this . hasRequiredPermission ( right ) ; } public canActivateChild ( childRoute , state ) { const right = childRoute . data . right as string ; return this . hasRequiredPermission ( right ) ; } public hasRequiredPermission ( right ) { if ( right === undefined || this . permissionService . hasRight ( right ) ) { return true ; } else { return this . permissionService . hasExtendedRight ( right ) ; } } }