Client: add guard to admin routes
authorChocobozzz <florian.bigard@gmail.com>
Sun, 10 Sep 2017 07:24:50 +0000 (09:24 +0200)
committerChocobozzz <florian.bigard@gmail.com>
Sun, 10 Sep 2017 07:24:50 +0000 (09:24 +0200)
client/src/app/+admin/admin-guard.service.ts [new file with mode: 0644]
client/src/app/+admin/admin-routing.module.ts
client/src/app/+admin/admin.module.ts
client/src/app/core/confirm/confirm.component.html

diff --git a/client/src/app/+admin/admin-guard.service.ts b/client/src/app/+admin/admin-guard.service.ts
new file mode 100644 (file)
index 0000000..a0ad481
--- /dev/null
@@ -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)
+  }
+}
index 03782c258fbf0bf14ff72cf7d9646e5a64c52003..a3845b72c936ae3d0868b364a6f6c13a14c16f44 100644 (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: '',
index 853085a8309f447635935e8d73beef8b5211d4cd..786dbc15c3d70bf5d2f245402050a97e7f510708 100644 (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 { }
index 8e5443c6a87007d55d4d0428faacd34cd21c9ac5..2726af6cc1428daa768f33223d80357122827607 100644 (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>