]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/core/routing/user-right-guard.service.ts
Refractor notification service
[github/Chocobozzz/PeerTube.git] / client / src / app / core / routing / user-right-guard.service.ts
CommitLineData
7ca86c86
C
1import { Injectable } from '@angular/core'
2import {
3 ActivatedRouteSnapshot,
4 CanActivateChild,
5 RouterStateSnapshot,
f47bf2e1
C
6 CanActivate,
7 Router
7ca86c86
C
8} from '@angular/router'
9
f8b2c1b4 10import { AuthService } from '../auth/auth.service'
7ca86c86
C
11
12@Injectable()
954605a8 13export class UserRightGuard implements CanActivate, CanActivateChild {
7ca86c86 14
f47bf2e1
C
15 constructor (
16 private router: Router,
17 private auth: AuthService
18 ) {}
7ca86c86
C
19
20 canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
954605a8
C
21 const user = this.auth.getUser()
22 if (user) {
23 const neededUserRight = route.data.userRight
24
25 if (user.hasRight(neededUserRight)) return true
26 }
f47bf2e1
C
27
28 this.router.navigate([ '/login' ])
29 return false
7ca86c86
C
30 }
31
32 canActivateChild (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
33 return this.canActivate(route, state)
34 }
35}