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