diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-09-10 09:24:50 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-09-10 09:24:50 +0200 |
commit | 7ca86c864e102b65e4ff3224a06554a66148fef8 (patch) | |
tree | 8554b9069257d94cf567981140a0881b566d8b3d /client/src/app | |
parent | 6599f096d5a26f2cc9624359d92cc501ec189586 (diff) | |
download | PeerTube-7ca86c864e102b65e4ff3224a06554a66148fef8.tar.gz PeerTube-7ca86c864e102b65e4ff3224a06554a66148fef8.tar.zst PeerTube-7ca86c864e102b65e4ff3224a06554a66148fef8.zip |
Client: add guard to admin routes
Diffstat (limited to 'client/src/app')
-rw-r--r-- | client/src/app/+admin/admin-guard.service.ts | 23 | ||||
-rw-r--r-- | client/src/app/+admin/admin-routing.module.ts | 4 | ||||
-rw-r--r-- | client/src/app/+admin/admin.module.ts | 4 | ||||
-rw-r--r-- | client/src/app/core/confirm/confirm.component.html | 2 |
4 files changed, 30 insertions, 3 deletions
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 @@ | |||
1 | import { Injectable } from '@angular/core' | ||
2 | import { | ||
3 | ActivatedRouteSnapshot, | ||
4 | CanActivateChild, | ||
5 | RouterStateSnapshot, | ||
6 | CanActivate | ||
7 | } from '@angular/router' | ||
8 | |||
9 | import { AuthService } from '../core' | ||
10 | |||
11 | @Injectable() | ||
12 | export class AdminGuard implements CanActivate, CanActivateChild { | ||
13 | |||
14 | constructor (private auth: AuthService) {} | ||
15 | |||
16 | canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { | ||
17 | return this.auth.isAdmin() | ||
18 | } | ||
19 | |||
20 | canActivateChild (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { | ||
21 | return this.canActivate(route, state) | ||
22 | } | ||
23 | } | ||
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' | |||
8 | import { RequestSchedulersRoutes } from './request-schedulers' | 8 | import { RequestSchedulersRoutes } from './request-schedulers' |
9 | import { UsersRoutes } from './users' | 9 | import { UsersRoutes } from './users' |
10 | import { VideoAbusesRoutes } from './video-abuses' | 10 | import { VideoAbusesRoutes } from './video-abuses' |
11 | import { AdminGuard } from './admin-guard.service' | ||
11 | 12 | ||
12 | const adminRoutes: Routes = [ | 13 | const adminRoutes: Routes = [ |
13 | { | 14 | { |
14 | path: '', | 15 | path: '', |
15 | component: AdminComponent, | 16 | component: AdminComponent, |
16 | canActivateChild: [ MetaGuard ], | 17 | canActivate: [ MetaGuard, AdminGuard ], |
18 | canActivateChild: [ MetaGuard, AdminGuard ], | ||
17 | children: [ | 19 | children: [ |
18 | { | 20 | { |
19 | path: '', | 21 | 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 | |||
7 | import { UsersComponent, UserAddComponent, UserUpdateComponent, UserListComponent, UserService } from './users' | 7 | import { UsersComponent, UserAddComponent, UserUpdateComponent, UserListComponent, UserService } from './users' |
8 | import { VideoAbusesComponent, VideoAbuseListComponent } from './video-abuses' | 8 | import { VideoAbusesComponent, VideoAbuseListComponent } from './video-abuses' |
9 | import { SharedModule } from '../shared' | 9 | import { SharedModule } from '../shared' |
10 | import { AdminGuard } from './admin-guard.service' | ||
10 | 11 | ||
11 | @NgModule({ | 12 | @NgModule({ |
12 | imports: [ | 13 | imports: [ |
@@ -40,7 +41,8 @@ import { SharedModule } from '../shared' | |||
40 | providers: [ | 41 | providers: [ |
41 | FriendService, | 42 | FriendService, |
42 | RequestSchedulersService, | 43 | RequestSchedulersService, |
43 | UserService | 44 | UserService, |
45 | AdminGuard | ||
44 | ] | 46 | ] |
45 | }) | 47 | }) |
46 | export class AdminModule { } | 48 | 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 @@ | |||
3 | <div class="modal-content"> | 3 | <div class="modal-content"> |
4 | 4 | ||
5 | <div class="modal-header"> | 5 | <div class="modal-header"> |
6 | <button type="button" class="close" aria-label="Close" (click)="abort()"> | 6 | <button type="button" class="close" aria-label="Close" (click)="cancel()"> |
7 | <span aria-hidden="true">×</span> | 7 | <span aria-hidden="true">×</span> |
8 | </button> | 8 | </button> |
9 | <h4 class="modal-title">{{ title }}</h4> | 9 | <h4 class="modal-title">{{ title }}</h4> |