diff options
author | Chocobozzz <me@florianbigard.com> | 2018-10-05 15:24:29 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-10-05 17:02:09 +0200 |
commit | e724fa93c71d76d709e819a05e5e2904a3c4205b (patch) | |
tree | c9bd410253f4ceac8e330541580445ca313583ac /client/src/app/+admin/users/user-list | |
parent | 21c54ac5f684f8b72bcde45cd8327ee21f574f22 (diff) | |
download | PeerTube-e724fa93c71d76d709e819a05e5e2904a3c4205b.tar.gz PeerTube-e724fa93c71d76d709e819a05e5e2904a3c4205b.tar.zst PeerTube-e724fa93c71d76d709e819a05e5e2904a3c4205b.zip |
Move user moderation tool in a separate component
Diffstat (limited to 'client/src/app/+admin/users/user-list')
5 files changed, 4 insertions, 201 deletions
diff --git a/client/src/app/+admin/users/user-list/user-ban-modal.component.html b/client/src/app/+admin/users/user-list/user-ban-modal.component.html deleted file mode 100644 index b2958caa4..000000000 --- a/client/src/app/+admin/users/user-list/user-ban-modal.component.html +++ /dev/null | |||
@@ -1,32 +0,0 @@ | |||
1 | <ng-template #modal> | ||
2 | <div class="modal-header"> | ||
3 | <h4 i18n class="modal-title">Ban {{ userToBan.username }}</h4> | ||
4 | <span class="close" aria-hidden="true" (click)="hideBanUserModal()"></span> | ||
5 | </div> | ||
6 | |||
7 | <div class="modal-body"> | ||
8 | <form novalidate [formGroup]="form" (ngSubmit)="banUser()"> | ||
9 | <div class="form-group"> | ||
10 | <textarea i18n-placeholder placeholder="Reason..." formControlName="reason" [ngClass]="{ 'input-error': formErrors['reason'] }"> | ||
11 | </textarea> | ||
12 | <div *ngIf="formErrors.reason" class="form-error"> | ||
13 | {{ formErrors.reason }} | ||
14 | </div> | ||
15 | </div> | ||
16 | |||
17 | <div i18n> | ||
18 | A banned user will no longer be able to login. | ||
19 | </div> | ||
20 | |||
21 | <div class="form-group inputs"> | ||
22 | <span i18n class="action-button action-button-cancel" (click)="hideBanUserModal()">Cancel</span> | ||
23 | |||
24 | <input | ||
25 | type="submit" i18n-value value="Ban this user" class="action-button-submit" | ||
26 | [disabled]="!form.valid" | ||
27 | > | ||
28 | </div> | ||
29 | </form> | ||
30 | </div> | ||
31 | |||
32 | </ng-template> \ No newline at end of file | ||
diff --git a/client/src/app/+admin/users/user-list/user-ban-modal.component.scss b/client/src/app/+admin/users/user-list/user-ban-modal.component.scss deleted file mode 100644 index 84562f15c..000000000 --- a/client/src/app/+admin/users/user-list/user-ban-modal.component.scss +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | @import 'variables'; | ||
2 | @import 'mixins'; | ||
3 | |||
4 | textarea { | ||
5 | @include peertube-textarea(100%, 60px); | ||
6 | } | ||
diff --git a/client/src/app/+admin/users/user-list/user-ban-modal.component.ts b/client/src/app/+admin/users/user-list/user-ban-modal.component.ts deleted file mode 100644 index 4fd4d561c..000000000 --- a/client/src/app/+admin/users/user-list/user-ban-modal.component.ts +++ /dev/null | |||
@@ -1,69 +0,0 @@ | |||
1 | import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core' | ||
2 | import { NotificationsService } from 'angular2-notifications' | ||
3 | import { FormReactive, UserValidatorsService } from '../../../shared' | ||
4 | import { UserService } from '../shared' | ||
5 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
6 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' | ||
7 | import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' | ||
8 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' | ||
9 | import { User } from '../../../../../../shared' | ||
10 | |||
11 | @Component({ | ||
12 | selector: 'my-user-ban-modal', | ||
13 | templateUrl: './user-ban-modal.component.html', | ||
14 | styleUrls: [ './user-ban-modal.component.scss' ] | ||
15 | }) | ||
16 | export class UserBanModalComponent extends FormReactive implements OnInit { | ||
17 | @ViewChild('modal') modal: NgbModal | ||
18 | @Output() userBanned = new EventEmitter<User>() | ||
19 | |||
20 | private userToBan: User | ||
21 | private openedModal: NgbModalRef | ||
22 | |||
23 | constructor ( | ||
24 | protected formValidatorService: FormValidatorService, | ||
25 | private modalService: NgbModal, | ||
26 | private notificationsService: NotificationsService, | ||
27 | private userService: UserService, | ||
28 | private userValidatorsService: UserValidatorsService, | ||
29 | private i18n: I18n | ||
30 | ) { | ||
31 | super() | ||
32 | } | ||
33 | |||
34 | ngOnInit () { | ||
35 | this.buildForm({ | ||
36 | reason: this.userValidatorsService.USER_BAN_REASON | ||
37 | }) | ||
38 | } | ||
39 | |||
40 | openModal (user: User) { | ||
41 | this.userToBan = user | ||
42 | this.openedModal = this.modalService.open(this.modal) | ||
43 | } | ||
44 | |||
45 | hideBanUserModal () { | ||
46 | this.userToBan = undefined | ||
47 | this.openedModal.close() | ||
48 | } | ||
49 | |||
50 | async banUser () { | ||
51 | const reason = this.form.value['reason'] || undefined | ||
52 | |||
53 | this.userService.banUser(this.userToBan, reason) | ||
54 | .subscribe( | ||
55 | () => { | ||
56 | this.notificationsService.success( | ||
57 | this.i18n('Success'), | ||
58 | this.i18n('User {{username}} banned.', { username: this.userToBan.username }) | ||
59 | ) | ||
60 | |||
61 | this.userBanned.emit(this.userToBan) | ||
62 | this.hideBanUserModal() | ||
63 | }, | ||
64 | |||
65 | err => this.notificationsService.error(this.i18n('Error'), err.message) | ||
66 | ) | ||
67 | } | ||
68 | |||
69 | } | ||
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 bb1b26442..2479ce9e4 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 | |||
@@ -40,7 +40,7 @@ | |||
40 | <td>{{ user.roleLabel }}</td> | 40 | <td>{{ user.roleLabel }}</td> |
41 | <td>{{ user.createdAt }}</td> | 41 | <td>{{ user.createdAt }}</td> |
42 | <td class="action-cell"> | 42 | <td class="action-cell"> |
43 | <my-action-dropdown i18n-label label="Actions" [actions]="userActions" [entry]="user"></my-action-dropdown> | 43 | <my-user-moderation-dropdown [user]="user" (userChanged)="onUserChanged()"></my-user-moderation-dropdown> |
44 | </td> | 44 | </td> |
45 | </tr> | 45 | </tr> |
46 | </ng-template> | 46 | </ng-template> |
@@ -55,4 +55,3 @@ | |||
55 | </ng-template> | 55 | </ng-template> |
56 | </p-table> | 56 | </p-table> |
57 | 57 | ||
58 | <my-user-ban-modal #userBanModal (userBanned)="onUserBanned()"></my-user-ban-modal> \ No newline at end of file | ||
diff --git a/client/src/app/+admin/users/user-list/user-list.component.ts b/client/src/app/+admin/users/user-list/user-list.component.ts index 100ffc00e..dee3ed643 100644 --- a/client/src/app/+admin/users/user-list/user-list.component.ts +++ b/client/src/app/+admin/users/user-list/user-list.component.ts | |||
@@ -1,13 +1,9 @@ | |||
1 | import { Component, OnInit, ViewChild } from '@angular/core' | 1 | import { Component, OnInit } from '@angular/core' |
2 | import { NotificationsService } from 'angular2-notifications' | 2 | import { NotificationsService } from 'angular2-notifications' |
3 | import { SortMeta } from 'primeng/components/common/sortmeta' | 3 | import { SortMeta } from 'primeng/components/common/sortmeta' |
4 | import { ConfirmService } from '../../../core' | 4 | import { ConfirmService } from '../../../core' |
5 | import { RestPagination, RestTable } from '../../../shared' | 5 | import { RestPagination, RestTable, UserService } from '../../../shared' |
6 | import { UserService } from '../shared' | ||
7 | import { I18n } from '@ngx-translate/i18n-polyfill' | 6 | import { I18n } from '@ngx-translate/i18n-polyfill' |
8 | import { DropdownAction } from '@app/shared/buttons/action-dropdown.component' | ||
9 | import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' | ||
10 | import { UserBanModalComponent } from '@app/+admin/users/user-list/user-ban-modal.component' | ||
11 | import { User } from '../../../../../../shared' | 7 | import { User } from '../../../../../../shared' |
12 | 8 | ||
13 | @Component({ | 9 | @Component({ |
@@ -16,16 +12,11 @@ import { User } from '../../../../../../shared' | |||
16 | styleUrls: [ './user-list.component.scss' ] | 12 | styleUrls: [ './user-list.component.scss' ] |
17 | }) | 13 | }) |
18 | export class UserListComponent extends RestTable implements OnInit { | 14 | export class UserListComponent extends RestTable implements OnInit { |
19 | @ViewChild('userBanModal') userBanModal: UserBanModalComponent | ||
20 | |||
21 | users: User[] = [] | 15 | users: User[] = [] |
22 | totalRecords = 0 | 16 | totalRecords = 0 |
23 | rowsPerPage = 10 | 17 | rowsPerPage = 10 |
24 | sort: SortMeta = { field: 'createdAt', order: 1 } | 18 | sort: SortMeta = { field: 'createdAt', order: 1 } |
25 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | 19 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } |
26 | userActions: DropdownAction<User>[] = [] | ||
27 | |||
28 | private openedModal: NgbModalRef | ||
29 | 20 | ||
30 | constructor ( | 21 | constructor ( |
31 | private notificationsService: NotificationsService, | 22 | private notificationsService: NotificationsService, |
@@ -34,96 +25,16 @@ export class UserListComponent extends RestTable implements OnInit { | |||
34 | private i18n: I18n | 25 | private i18n: I18n |
35 | ) { | 26 | ) { |
36 | super() | 27 | super() |
37 | |||
38 | this.userActions = [ | ||
39 | { | ||
40 | label: this.i18n('Edit'), | ||
41 | linkBuilder: this.getRouterUserEditLink | ||
42 | }, | ||
43 | { | ||
44 | label: this.i18n('Delete'), | ||
45 | handler: user => this.removeUser(user) | ||
46 | }, | ||
47 | { | ||
48 | label: this.i18n('Ban'), | ||
49 | handler: user => this.openBanUserModal(user), | ||
50 | isDisplayed: user => !user.blocked | ||
51 | }, | ||
52 | { | ||
53 | label: this.i18n('Unban'), | ||
54 | handler: user => this.unbanUser(user), | ||
55 | isDisplayed: user => user.blocked | ||
56 | } | ||
57 | ] | ||
58 | } | 28 | } |
59 | 29 | ||
60 | ngOnInit () { | 30 | ngOnInit () { |
61 | this.loadSort() | 31 | this.loadSort() |
62 | } | 32 | } |
63 | 33 | ||
64 | hideBanUserModal () { | 34 | onUserChanged () { |
65 | this.openedModal.close() | ||
66 | } | ||
67 | |||
68 | openBanUserModal (user: User) { | ||
69 | if (user.username === 'root') { | ||
70 | this.notificationsService.error(this.i18n('Error'), this.i18n('You cannot ban root.')) | ||
71 | return | ||
72 | } | ||
73 | |||
74 | this.userBanModal.openModal(user) | ||
75 | } | ||
76 | |||
77 | onUserBanned () { | ||
78 | this.loadData() | 35 | this.loadData() |
79 | } | 36 | } |
80 | 37 | ||
81 | async unbanUser (user: User) { | ||
82 | const message = this.i18n('Do you really want to unban {{username}}?', { username: user.username }) | ||
83 | const res = await this.confirmService.confirm(message, this.i18n('Unban')) | ||
84 | if (res === false) return | ||
85 | |||
86 | this.userService.unbanUser(user) | ||
87 | .subscribe( | ||
88 | () => { | ||
89 | this.notificationsService.success( | ||
90 | this.i18n('Success'), | ||
91 | this.i18n('User {{username}} unbanned.', { username: user.username }) | ||
92 | ) | ||
93 | this.loadData() | ||
94 | }, | ||
95 | |||
96 | err => this.notificationsService.error(this.i18n('Error'), err.message) | ||
97 | ) | ||
98 | } | ||
99 | |||
100 | async removeUser (user: User) { | ||
101 | if (user.username === 'root') { | ||
102 | this.notificationsService.error(this.i18n('Error'), this.i18n('You cannot delete root.')) | ||
103 | return | ||
104 | } | ||
105 | |||
106 | const message = this.i18n('If you remove this user, you will not be able to create another with the same username!') | ||
107 | const res = await this.confirmService.confirm(message, this.i18n('Delete')) | ||
108 | if (res === false) return | ||
109 | |||
110 | this.userService.removeUser(user).subscribe( | ||
111 | () => { | ||
112 | this.notificationsService.success( | ||
113 | this.i18n('Success'), | ||
114 | this.i18n('User {{username}} deleted.', { username: user.username }) | ||
115 | ) | ||
116 | this.loadData() | ||
117 | }, | ||
118 | |||
119 | err => this.notificationsService.error(this.i18n('Error'), err.message) | ||
120 | ) | ||
121 | } | ||
122 | |||
123 | getRouterUserEditLink (user: User) { | ||
124 | return [ '/admin', 'users', 'update', user.id ] | ||
125 | } | ||
126 | |||
127 | protected loadData () { | 38 | protected loadData () { |
128 | this.userService.getUsers(this.pagination, this.sort) | 39 | this.userService.getUsers(this.pagination, this.sort) |
129 | .subscribe( | 40 | .subscribe( |