Client: add guard to admin routes

pull/97/head
Chocobozzz 2017-09-10 09:24:50 +02:00
parent 6599f096d5
commit 7ca86c864e
4 changed files with 30 additions and 3 deletions

View File

@ -0,0 +1,23 @@
import { Injectable } from '@angular/core'
import {
ActivatedRouteSnapshot,
CanActivateChild,
RouterStateSnapshot,
CanActivate
} from '@angular/router'
import { AuthService } from '../core'
@Injectable()
export class AdminGuard implements CanActivate, CanActivateChild {
constructor (private auth: AuthService) {}
canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
return this.auth.isAdmin()
}
canActivateChild (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
return this.canActivate(route, state)
}
}

View File

@ -8,12 +8,14 @@ import { FriendsRoutes } from './friends'
import { RequestSchedulersRoutes } from './request-schedulers'
import { UsersRoutes } from './users'
import { VideoAbusesRoutes } from './video-abuses'
import { AdminGuard } from './admin-guard.service'
const adminRoutes: Routes = [
{
path: '',
component: AdminComponent,
canActivateChild: [ MetaGuard ],
canActivate: [ MetaGuard, AdminGuard ],
canActivateChild: [ MetaGuard, AdminGuard ],
children: [
{
path: '',

View File

@ -7,6 +7,7 @@ import { RequestSchedulersComponent, RequestSchedulersStatsComponent, RequestSch
import { UsersComponent, UserAddComponent, UserUpdateComponent, UserListComponent, UserService } from './users'
import { VideoAbusesComponent, VideoAbuseListComponent } from './video-abuses'
import { SharedModule } from '../shared'
import { AdminGuard } from './admin-guard.service'
@NgModule({
imports: [
@ -40,7 +41,8 @@ import { SharedModule } from '../shared'
providers: [
FriendService,
RequestSchedulersService,
UserService
UserService,
AdminGuard
]
})
export class AdminModule { }

View File

@ -3,7 +3,7 @@
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" aria-label="Close" (click)="abort()">
<button type="button" class="close" aria-label="Close" (click)="cancel()">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title">{{ title }}</h4>