aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-10-27 16:55:03 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-10-27 16:55:03 +0200
commit954605a804da399317ca62afa2fb9244afa11ebf (patch)
treede6ee69280bfb928bc01c29430e13d5b820e921a /client/src/app/+admin
parente02573ad67626210ed279bad321ee139094921a1 (diff)
downloadPeerTube-954605a804da399317ca62afa2fb9244afa11ebf.tar.gz
PeerTube-954605a804da399317ca62afa2fb9244afa11ebf.tar.zst
PeerTube-954605a804da399317ca62afa2fb9244afa11ebf.zip
Support roles with rights and add moderator role
Diffstat (limited to 'client/src/app/+admin')
-rw-r--r--client/src/app/+admin/admin-guard.service.ts30
-rw-r--r--client/src/app/+admin/admin-routing.module.ts5
-rw-r--r--client/src/app/+admin/admin.module.ts4
-rw-r--r--client/src/app/+admin/friends/friends.routes.ts6
-rw-r--r--client/src/app/+admin/request-schedulers/request-schedulers.routes.ts6
-rw-r--r--client/src/app/+admin/users/user-edit/user-add.component.ts8
-rw-r--r--client/src/app/+admin/users/user-edit/user-edit.component.html13
-rw-r--r--client/src/app/+admin/users/user-edit/user-edit.ts4
-rw-r--r--client/src/app/+admin/users/user-edit/user-update.component.ts14
-rw-r--r--client/src/app/+admin/users/user-list/user-list.component.html2
-rw-r--r--client/src/app/+admin/users/users.routes.ts6
-rw-r--r--client/src/app/+admin/video-abuses/video-abuses.routes.ts9
-rw-r--r--client/src/app/+admin/video-blacklist/video-blacklist.routes.ts6
13 files changed, 68 insertions, 45 deletions
diff --git a/client/src/app/+admin/admin-guard.service.ts b/client/src/app/+admin/admin-guard.service.ts
deleted file mode 100644
index 429dc032d..000000000
--- a/client/src/app/+admin/admin-guard.service.ts
+++ /dev/null
@@ -1,30 +0,0 @@
1import { Injectable } from '@angular/core'
2import {
3 ActivatedRouteSnapshot,
4 CanActivateChild,
5 RouterStateSnapshot,
6 CanActivate,
7 Router
8} from '@angular/router'
9
10import { AuthService } from '../core'
11
12@Injectable()
13export class AdminGuard implements CanActivate, CanActivateChild {
14
15 constructor (
16 private router: Router,
17 private auth: AuthService
18 ) {}
19
20 canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
21 if (this.auth.isAdmin() === true) return true
22
23 this.router.navigate([ '/login' ])
24 return false
25 }
26
27 canActivateChild (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
28 return this.canActivate(route, state)
29 }
30}
diff --git a/client/src/app/+admin/admin-routing.module.ts b/client/src/app/+admin/admin-routing.module.ts
index c3e4895ac..7262768fe 100644
--- a/client/src/app/+admin/admin-routing.module.ts
+++ b/client/src/app/+admin/admin-routing.module.ts
@@ -8,15 +8,14 @@ import { FriendsRoutes } from './friends'
8import { RequestSchedulersRoutes } from './request-schedulers' 8import { RequestSchedulersRoutes } from './request-schedulers'
9import { UsersRoutes } from './users' 9import { UsersRoutes } from './users'
10import { VideoAbusesRoutes } from './video-abuses' 10import { VideoAbusesRoutes } from './video-abuses'
11import { AdminGuard } from './admin-guard.service'
12import { VideoBlacklistRoutes } from './video-blacklist' 11import { VideoBlacklistRoutes } from './video-blacklist'
13 12
14const adminRoutes: Routes = [ 13const adminRoutes: Routes = [
15 { 14 {
16 path: '', 15 path: '',
17 component: AdminComponent, 16 component: AdminComponent,
18 canActivate: [ MetaGuard, AdminGuard ], 17 canActivate: [ MetaGuard ],
19 canActivateChild: [ MetaGuard, AdminGuard ], 18 canActivateChild: [ MetaGuard ],
20 children: [ 19 children: [
21 { 20 {
22 path: '', 21 path: '',
diff --git a/client/src/app/+admin/admin.module.ts b/client/src/app/+admin/admin.module.ts
index f29c501b0..6c216e5d8 100644
--- a/client/src/app/+admin/admin.module.ts
+++ b/client/src/app/+admin/admin.module.ts
@@ -8,7 +8,6 @@ import { UsersComponent, UserAddComponent, UserUpdateComponent, UserListComponen
8import { VideoAbusesComponent, VideoAbuseListComponent } from './video-abuses' 8import { VideoAbusesComponent, VideoAbuseListComponent } from './video-abuses'
9import { VideoBlacklistComponent, VideoBlacklistListComponent } from './video-blacklist' 9import { VideoBlacklistComponent, VideoBlacklistListComponent } from './video-blacklist'
10import { SharedModule } from '../shared' 10import { SharedModule } from '../shared'
11import { AdminGuard } from './admin-guard.service'
12 11
13@NgModule({ 12@NgModule({
14 imports: [ 13 imports: [
@@ -45,8 +44,7 @@ import { AdminGuard } from './admin-guard.service'
45 providers: [ 44 providers: [
46 FriendService, 45 FriendService,
47 RequestSchedulersService, 46 RequestSchedulersService,
48 UserService, 47 UserService
49 AdminGuard
50 ] 48 ]
51}) 49})
52export class AdminModule { } 50export class AdminModule { }
diff --git a/client/src/app/+admin/friends/friends.routes.ts b/client/src/app/+admin/friends/friends.routes.ts
index 615b6f4f7..61cfcae19 100644
--- a/client/src/app/+admin/friends/friends.routes.ts
+++ b/client/src/app/+admin/friends/friends.routes.ts
@@ -1,13 +1,19 @@
1import { Routes } from '@angular/router' 1import { Routes } from '@angular/router'
2 2
3import { UserRightGuard } from '../../core'
3import { FriendsComponent } from './friends.component' 4import { FriendsComponent } from './friends.component'
4import { FriendAddComponent } from './friend-add' 5import { FriendAddComponent } from './friend-add'
5import { FriendListComponent } from './friend-list' 6import { FriendListComponent } from './friend-list'
7import { UserRight } from '../../../../../shared'
6 8
7export const FriendsRoutes: Routes = [ 9export const FriendsRoutes: Routes = [
8 { 10 {
9 path: 'friends', 11 path: 'friends',
10 component: FriendsComponent, 12 component: FriendsComponent,
13 canActivate: [ UserRightGuard ],
14 data: {
15 userRight: UserRight.MANAGE_PODS
16 },
11 children: [ 17 children: [
12 { 18 {
13 path: '', 19 path: '',
diff --git a/client/src/app/+admin/request-schedulers/request-schedulers.routes.ts b/client/src/app/+admin/request-schedulers/request-schedulers.routes.ts
index 4961c646b..c2564de15 100644
--- a/client/src/app/+admin/request-schedulers/request-schedulers.routes.ts
+++ b/client/src/app/+admin/request-schedulers/request-schedulers.routes.ts
@@ -1,5 +1,7 @@
1import { Routes } from '@angular/router' 1import { Routes } from '@angular/router'
2 2
3import { UserRightGuard } from '../../core'
4import { UserRight } from '../../../../../shared'
3import { RequestSchedulersComponent } from './request-schedulers.component' 5import { RequestSchedulersComponent } from './request-schedulers.component'
4import { RequestSchedulersStatsComponent } from './request-schedulers-stats' 6import { RequestSchedulersStatsComponent } from './request-schedulers-stats'
5 7
@@ -7,6 +9,10 @@ export const RequestSchedulersRoutes: Routes = [
7 { 9 {
8 path: 'requests', 10 path: 'requests',
9 component: RequestSchedulersComponent, 11 component: RequestSchedulersComponent,
12 canActivate: [ UserRightGuard ],
13 data: {
14 userRight: UserRight.MANAGE_REQUEST_SCHEDULERS
15 },
10 children: [ 16 children: [
11 { 17 {
12 path: '', 18 path: '',
diff --git a/client/src/app/+admin/users/user-edit/user-add.component.ts b/client/src/app/+admin/users/user-edit/user-add.component.ts
index 6d8151b42..8e3e3d53d 100644
--- a/client/src/app/+admin/users/user-edit/user-add.component.ts
+++ b/client/src/app/+admin/users/user-edit/user-add.component.ts
@@ -9,10 +9,11 @@ import {
9 USER_USERNAME, 9 USER_USERNAME,
10 USER_EMAIL, 10 USER_EMAIL,
11 USER_PASSWORD, 11 USER_PASSWORD,
12 USER_VIDEO_QUOTA 12 USER_VIDEO_QUOTA,
13 USER_ROLE
13} from '../../../shared' 14} from '../../../shared'
14import { ServerService } from '../../../core' 15import { ServerService } from '../../../core'
15import { UserCreate } from '../../../../../../shared' 16import { UserCreate, UserRole } from '../../../../../../shared'
16import { UserEdit } from './user-edit' 17import { UserEdit } from './user-edit'
17 18
18@Component({ 19@Component({
@@ -28,12 +29,14 @@ export class UserAddComponent extends UserEdit implements OnInit {
28 'username': '', 29 'username': '',
29 'email': '', 30 'email': '',
30 'password': '', 31 'password': '',
32 'role': '',
31 'videoQuota': '' 33 'videoQuota': ''
32 } 34 }
33 validationMessages = { 35 validationMessages = {
34 'username': USER_USERNAME.MESSAGES, 36 'username': USER_USERNAME.MESSAGES,
35 'email': USER_EMAIL.MESSAGES, 37 'email': USER_EMAIL.MESSAGES,
36 'password': USER_PASSWORD.MESSAGES, 38 'password': USER_PASSWORD.MESSAGES,
39 'role': USER_ROLE.MESSAGES,
37 'videoQuota': USER_VIDEO_QUOTA.MESSAGES 40 'videoQuota': USER_VIDEO_QUOTA.MESSAGES
38 } 41 }
39 42
@@ -52,6 +55,7 @@ export class UserAddComponent extends UserEdit implements OnInit {
52 username: [ '', USER_USERNAME.VALIDATORS ], 55 username: [ '', USER_USERNAME.VALIDATORS ],
53 email: [ '', USER_EMAIL.VALIDATORS ], 56 email: [ '', USER_EMAIL.VALIDATORS ],
54 password: [ '', USER_PASSWORD.VALIDATORS ], 57 password: [ '', USER_PASSWORD.VALIDATORS ],
58 role: [ UserRole.USER, USER_ROLE.VALIDATORS ],
55 videoQuota: [ '-1', USER_VIDEO_QUOTA.VALIDATORS ] 59 videoQuota: [ '-1', USER_VIDEO_QUOTA.VALIDATORS ]
56 }) 60 })
57 61
diff --git a/client/src/app/+admin/users/user-edit/user-edit.component.html b/client/src/app/+admin/users/user-edit/user-edit.component.html
index 6988071ce..349be13c1 100644
--- a/client/src/app/+admin/users/user-edit/user-edit.component.html
+++ b/client/src/app/+admin/users/user-edit/user-edit.component.html
@@ -41,6 +41,19 @@
41 </div> 41 </div>
42 42
43 <div class="form-group"> 43 <div class="form-group">
44 <label for="role">Role</label>
45 <select class="form-control" id="role" formControlName="role">
46 <option *ngFor="let role of roles" [value]="role.value">
47 {{ role.label }}
48 </option>
49 </select>
50
51 <div *ngIf="formErrors.role" class="alert alert-danger">
52 {{ formErrors.role }}
53 </div>
54 </div>
55
56 <div class="form-group">
44 <label for="videoQuota">Video quota</label> 57 <label for="videoQuota">Video quota</label>
45 <select class="form-control" id="videoQuota" formControlName="videoQuota"> 58 <select class="form-control" id="videoQuota" formControlName="videoQuota">
46 <option *ngFor="let videoQuotaOption of videoQuotaOptions" [value]="videoQuotaOption.value"> 59 <option *ngFor="let videoQuotaOption of videoQuotaOptions" [value]="videoQuotaOption.value">
diff --git a/client/src/app/+admin/users/user-edit/user-edit.ts b/client/src/app/+admin/users/user-edit/user-edit.ts
index 76497c9b6..51d90da39 100644
--- a/client/src/app/+admin/users/user-edit/user-edit.ts
+++ b/client/src/app/+admin/users/user-edit/user-edit.ts
@@ -1,6 +1,6 @@
1import { ServerService } from '../../../core' 1import { ServerService } from '../../../core'
2import { FormReactive } from '../../../shared' 2import { FormReactive } from '../../../shared'
3import { VideoResolution } from '../../../../../../shared/models/videos/video-resolution.enum' 3import { USER_ROLE_LABELS, VideoResolution } from '../../../../../../shared'
4 4
5export abstract class UserEdit extends FormReactive { 5export abstract class UserEdit extends FormReactive {
6 videoQuotaOptions = [ 6 videoQuotaOptions = [
@@ -14,6 +14,8 @@ export abstract class UserEdit extends FormReactive {
14 { value: 50 * 1024 * 1024 * 1024, label: '50GB' } 14 { value: 50 * 1024 * 1024 * 1024, label: '50GB' }
15 ] 15 ]
16 16
17 roles = Object.keys(USER_ROLE_LABELS).map(key => ({ value: key, label: USER_ROLE_LABELS[key] }))
18
17 protected abstract serverService: ServerService 19 protected abstract serverService: ServerService
18 abstract isCreation (): boolean 20 abstract isCreation (): boolean
19 abstract getFormButtonTitle (): string 21 abstract getFormButtonTitle (): string
diff --git a/client/src/app/+admin/users/user-edit/user-update.component.ts b/client/src/app/+admin/users/user-edit/user-update.component.ts
index bd901e655..bcba78a35 100644
--- a/client/src/app/+admin/users/user-edit/user-update.component.ts
+++ b/client/src/app/+admin/users/user-edit/user-update.component.ts
@@ -6,11 +6,15 @@ import { Subscription } from 'rxjs/Subscription'
6import { NotificationsService } from 'angular2-notifications' 6import { NotificationsService } from 'angular2-notifications'
7 7
8import { UserService } from '../shared' 8import { UserService } from '../shared'
9import { USER_EMAIL, USER_VIDEO_QUOTA } from '../../../shared' 9import {
10 USER_EMAIL,
11 USER_VIDEO_QUOTA,
12 USER_ROLE,
13 User
14} from '../../../shared'
10import { ServerService } from '../../../core' 15import { ServerService } from '../../../core'
11import { UserUpdate } from '../../../../../../shared/models/users/user-update.model'
12import { User } from '../../../shared/users/user.model'
13import { UserEdit } from './user-edit' 16import { UserEdit } from './user-edit'
17import { UserUpdate, UserRole } from '../../../../../../shared'
14 18
15@Component({ 19@Component({
16 selector: 'my-user-update', 20 selector: 'my-user-update',
@@ -25,10 +29,12 @@ export class UserUpdateComponent extends UserEdit implements OnInit, OnDestroy {
25 form: FormGroup 29 form: FormGroup
26 formErrors = { 30 formErrors = {
27 'email': '', 31 'email': '',
32 'role': '',
28 'videoQuota': '' 33 'videoQuota': ''
29 } 34 }
30 validationMessages = { 35 validationMessages = {
31 'email': USER_EMAIL.MESSAGES, 36 'email': USER_EMAIL.MESSAGES,
37 'role': USER_ROLE.MESSAGES,
32 'videoQuota': USER_VIDEO_QUOTA.MESSAGES 38 'videoQuota': USER_VIDEO_QUOTA.MESSAGES
33 } 39 }
34 40
@@ -48,6 +54,7 @@ export class UserUpdateComponent extends UserEdit implements OnInit, OnDestroy {
48 buildForm () { 54 buildForm () {
49 this.form = this.formBuilder.group({ 55 this.form = this.formBuilder.group({
50 email: [ '', USER_EMAIL.VALIDATORS ], 56 email: [ '', USER_EMAIL.VALIDATORS ],
57 role: [ '', USER_ROLE.VALIDATORS ],
51 videoQuota: [ '-1', USER_VIDEO_QUOTA.VALIDATORS ] 58 videoQuota: [ '-1', USER_VIDEO_QUOTA.VALIDATORS ]
52 }) 59 })
53 60
@@ -103,6 +110,7 @@ export class UserUpdateComponent extends UserEdit implements OnInit, OnDestroy {
103 110
104 this.form.patchValue({ 111 this.form.patchValue({
105 email: userJson.email, 112 email: userJson.email,
113 role: userJson.role,
106 videoQuota: userJson.videoQuota 114 videoQuota: userJson.videoQuota
107 }) 115 })
108 } 116 }
diff --git a/client/src/app/+admin/users/user-list/user-list.component.html b/client/src/app/+admin/users/user-list/user-list.component.html
index 2944e3cbf..16a8a8033 100644
--- a/client/src/app/+admin/users/user-list/user-list.component.html
+++ b/client/src/app/+admin/users/user-list/user-list.component.html
@@ -11,7 +11,7 @@
11 <p-column field="username" header="Username" [sortable]="true"></p-column> 11 <p-column field="username" header="Username" [sortable]="true"></p-column>
12 <p-column field="email" header="Email"></p-column> 12 <p-column field="email" header="Email"></p-column>
13 <p-column field="videoQuota" header="Video quota"></p-column> 13 <p-column field="videoQuota" header="Video quota"></p-column>
14 <p-column field="role" header="Role"></p-column> 14 <p-column field="roleLabel" header="Role"></p-column>
15 <p-column field="createdAt" header="Created date" [sortable]="true"></p-column> 15 <p-column field="createdAt" header="Created date" [sortable]="true"></p-column>
16 <p-column header="Edit" styleClass="action-cell"> 16 <p-column header="Edit" styleClass="action-cell">
17 <ng-template pTemplate="body" let-user="rowData"> 17 <ng-template pTemplate="body" let-user="rowData">
diff --git a/client/src/app/+admin/users/users.routes.ts b/client/src/app/+admin/users/users.routes.ts
index a6a9c4c19..3718dfd5c 100644
--- a/client/src/app/+admin/users/users.routes.ts
+++ b/client/src/app/+admin/users/users.routes.ts
@@ -1,5 +1,7 @@
1import { Routes } from '@angular/router' 1import { Routes } from '@angular/router'
2 2
3import { UserRightGuard } from '../../core'
4import { UserRight } from '../../../../../shared'
3import { UsersComponent } from './users.component' 5import { UsersComponent } from './users.component'
4import { UserAddComponent, UserUpdateComponent } from './user-edit' 6import { UserAddComponent, UserUpdateComponent } from './user-edit'
5import { UserListComponent } from './user-list' 7import { UserListComponent } from './user-list'
@@ -8,6 +10,10 @@ export const UsersRoutes: Routes = [
8 { 10 {
9 path: 'users', 11 path: 'users',
10 component: UsersComponent, 12 component: UsersComponent,
13 canActivate: [ UserRightGuard ],
14 data: {
15 userRight: UserRight.MANAGE_USERS
16 },
11 children: [ 17 children: [
12 { 18 {
13 path: '', 19 path: '',
diff --git a/client/src/app/+admin/video-abuses/video-abuses.routes.ts b/client/src/app/+admin/video-abuses/video-abuses.routes.ts
index a8c1561cd..68b756059 100644
--- a/client/src/app/+admin/video-abuses/video-abuses.routes.ts
+++ b/client/src/app/+admin/video-abuses/video-abuses.routes.ts
@@ -1,13 +1,18 @@
1import { Routes } from '@angular/router' 1import { Routes } from '@angular/router'
2 2
3import { UserRightGuard } from '../../core'
4import { UserRight } from '../../../../../shared'
3import { VideoAbusesComponent } from './video-abuses.component' 5import { VideoAbusesComponent } from './video-abuses.component'
4import { VideoAbuseListComponent } from './video-abuse-list' 6import { VideoAbuseListComponent } from './video-abuse-list'
5 7
6export const VideoAbusesRoutes: Routes = [ 8export const VideoAbusesRoutes: Routes = [
7 { 9 {
8 path: 'video-abuses', 10 path: 'video-abuses',
9 component: VideoAbusesComponent 11 component: VideoAbusesComponent,
10 , 12 canActivate: [ UserRightGuard ],
13 data: {
14 userRight: UserRight.MANAGE_VIDEO_ABUSES
15 },
11 children: [ 16 children: [
12 { 17 {
13 path: '', 18 path: '',
diff --git a/client/src/app/+admin/video-blacklist/video-blacklist.routes.ts b/client/src/app/+admin/video-blacklist/video-blacklist.routes.ts
index 682b6f8bd..b1e0e5049 100644
--- a/client/src/app/+admin/video-blacklist/video-blacklist.routes.ts
+++ b/client/src/app/+admin/video-blacklist/video-blacklist.routes.ts
@@ -1,5 +1,7 @@
1import { Routes } from '@angular/router' 1import { Routes } from '@angular/router'
2 2
3import { UserRightGuard } from '../../core'
4import { UserRight } from '../../../../../shared'
3import { VideoBlacklistComponent } from './video-blacklist.component' 5import { VideoBlacklistComponent } from './video-blacklist.component'
4import { VideoBlacklistListComponent } from './video-blacklist-list' 6import { VideoBlacklistListComponent } from './video-blacklist-list'
5 7
@@ -7,6 +9,10 @@ export const VideoBlacklistRoutes: Routes = [
7 { 9 {
8 path: 'video-blacklist', 10 path: 'video-blacklist',
9 component: VideoBlacklistComponent, 11 component: VideoBlacklistComponent,
12 canActivate: [ UserRightGuard ],
13 data: {
14 userRight: UserRight.MANAGE_VIDEO_BLACKLIST
15 },
10 children: [ 16 children: [
11 { 17 {
12 path: '', 18 path: '',