aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core/menu/menu.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/core/menu/menu.component.ts')
-rw-r--r--client/src/app/core/menu/menu.component.ts46
1 files changed, 44 insertions, 2 deletions
diff --git a/client/src/app/core/menu/menu.component.ts b/client/src/app/core/menu/menu.component.ts
index 8f15d8838..c66a5eccc 100644
--- a/client/src/app/core/menu/menu.component.ts
+++ b/client/src/app/core/menu/menu.component.ts
@@ -3,6 +3,7 @@ import { Router } from '@angular/router'
3 3
4import { AuthService, AuthStatus } from '../auth' 4import { AuthService, AuthStatus } from '../auth'
5import { ServerService } from '../server' 5import { ServerService } from '../server'
6import { UserRight } from '../../../../../shared/models/users/user-right.enum'
6 7
7@Component({ 8@Component({
8 selector: 'my-menu', 9 selector: 'my-menu',
@@ -11,6 +12,15 @@ import { ServerService } from '../server'
11}) 12})
12export class MenuComponent implements OnInit { 13export class MenuComponent implements OnInit {
13 isLoggedIn: boolean 14 isLoggedIn: boolean
15 userHasAdminAccess = false
16
17 private routesPerRight = {
18 [UserRight.MANAGE_USERS]: '/admin/users',
19 [UserRight.MANAGE_PODS]: '/admin/friends',
20 [UserRight.MANAGE_REQUEST_SCHEDULERS]: '/admin/requests/stats',
21 [UserRight.MANAGE_VIDEO_ABUSES]: '/admin/video-abuses',
22 [UserRight.MANAGE_VIDEO_BLACKLIST]: '/admin/video-blacklist'
23 }
14 24
15 constructor ( 25 constructor (
16 private authService: AuthService, 26 private authService: AuthService,
@@ -20,14 +30,17 @@ export class MenuComponent implements OnInit {
20 30
21 ngOnInit () { 31 ngOnInit () {
22 this.isLoggedIn = this.authService.isLoggedIn() 32 this.isLoggedIn = this.authService.isLoggedIn()
33 this.computeIsUserHasAdminAccess()
23 34
24 this.authService.loginChangedSource.subscribe( 35 this.authService.loginChangedSource.subscribe(
25 status => { 36 status => {
26 if (status === AuthStatus.LoggedIn) { 37 if (status === AuthStatus.LoggedIn) {
27 this.isLoggedIn = true 38 this.isLoggedIn = true
39 this.computeIsUserHasAdminAccess()
28 console.log('Logged in.') 40 console.log('Logged in.')
29 } else if (status === AuthStatus.LoggedOut) { 41 } else if (status === AuthStatus.LoggedOut) {
30 this.isLoggedIn = false 42 this.isLoggedIn = false
43 this.computeIsUserHasAdminAccess()
31 console.log('Logged out.') 44 console.log('Logged out.')
32 } else { 45 } else {
33 console.error('Unknown auth status: ' + status) 46 console.error('Unknown auth status: ' + status)
@@ -40,8 +53,31 @@ export class MenuComponent implements OnInit {
40 return this.serverService.getConfig().signup.allowed 53 return this.serverService.getConfig().signup.allowed
41 } 54 }
42 55
43 isUserAdmin () { 56 getFirstAdminRightAvailable () {
44 return this.authService.isAdmin() 57 const user = this.authService.getUser()
58 if (!user) return undefined
59
60 const adminRights = [
61 UserRight.MANAGE_USERS,
62 UserRight.MANAGE_PODS,
63 UserRight.MANAGE_REQUEST_SCHEDULERS,
64 UserRight.MANAGE_VIDEO_ABUSES,
65 UserRight.MANAGE_VIDEO_BLACKLIST
66 ]
67
68 for (const adminRight of adminRights) {
69 if (user.hasRight(adminRight)) {
70 return adminRight
71 }
72 }
73
74 return undefined
75 }
76
77 getFirstAdminRouteAvailable () {
78 const right = this.getFirstAdminRightAvailable()
79
80 return this.routesPerRight[right]
45 } 81 }
46 82
47 logout () { 83 logout () {
@@ -49,4 +85,10 @@ export class MenuComponent implements OnInit {
49 // Redirect to home page 85 // Redirect to home page
50 this.router.navigate(['/videos/list']) 86 this.router.navigate(['/videos/list'])
51 } 87 }
88
89 private computeIsUserHasAdminAccess () {
90 const right = this.getFirstAdminRightAvailable()
91
92 this.userHasAdminAccess = right !== undefined
93 }
52} 94}