]>
Commit | Line | Data |
---|---|---|
7ca86c86 | 1 | import { Injectable } from '@angular/core' |
52798aa5 | 2 | import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router' |
f8b2c1b4 | 3 | import { AuthService } from '../auth/auth.service' |
98bd5e22 | 4 | import { RedirectService } from './redirect.service' |
7ca86c86 C |
5 | |
6 | @Injectable() | |
52798aa5 | 7 | export class UserRightGuard { |
7ca86c86 | 8 | |
f47bf2e1 | 9 | constructor ( |
98bd5e22 | 10 | private redirectService: RedirectService, |
f47bf2e1 C |
11 | private auth: AuthService |
12 | ) {} | |
7ca86c86 C |
13 | |
14 | canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { | |
954605a8 C |
15 | const user = this.auth.getUser() |
16 | if (user) { | |
17 | const neededUserRight = route.data.userRight | |
18 | ||
19 | if (user.hasRight(neededUserRight)) return true | |
20 | } | |
f47bf2e1 | 21 | |
98bd5e22 | 22 | this.redirectService.redirectToLogin() |
f47bf2e1 | 23 | return false |
7ca86c86 C |
24 | } |
25 | ||
26 | canActivateChild (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { | |
27 | return this.canActivate(route, state) | |
28 | } | |
29 | } |