From: Chocobozzz Date: Sun, 10 Sep 2017 07:24:50 +0000 (+0200) Subject: Client: add guard to admin routes X-Git-Tag: v0.0.1-alpha~327 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=7ca86c864e102b65e4ff3224a06554a66148fef8;p=oweals%2Fpeertube.git Client: add guard to admin routes --- diff --git a/client/src/app/+admin/admin-guard.service.ts b/client/src/app/+admin/admin-guard.service.ts new file mode 100644 index 000000000..a0ad48175 --- /dev/null +++ b/client/src/app/+admin/admin-guard.service.ts @@ -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) + } +} diff --git a/client/src/app/+admin/admin-routing.module.ts b/client/src/app/+admin/admin-routing.module.ts index 03782c258..a3845b72c 100644 --- a/client/src/app/+admin/admin-routing.module.ts +++ b/client/src/app/+admin/admin-routing.module.ts @@ -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: '', diff --git a/client/src/app/+admin/admin.module.ts b/client/src/app/+admin/admin.module.ts index 853085a83..786dbc15c 100644 --- a/client/src/app/+admin/admin.module.ts +++ b/client/src/app/+admin/admin.module.ts @@ -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 { } diff --git a/client/src/app/core/confirm/confirm.component.html b/client/src/app/core/confirm/confirm.component.html index 8e5443c6a..2726af6cc 100644 --- a/client/src/app/core/confirm/confirm.component.html +++ b/client/src/app/core/confirm/confirm.component.html @@ -3,7 +3,7 @@