mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2024-11-26 02:30:37 -06:00
Client: add guard to admin routes
This commit is contained in:
parent
6599f096d5
commit
7ca86c864e
23
client/src/app/+admin/admin-guard.service.ts
Normal file
23
client/src/app/+admin/admin-guard.service.ts
Normal 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)
|
||||
}
|
||||
}
|
@ -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: '',
|
||||
|
@ -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 { }
|
||||
|
@ -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">×</span>
|
||||
</button>
|
||||
<h4 class="modal-title">{{ title }}</h4>
|
||||
|
Loading…
Reference in New Issue
Block a user