aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/moderation
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-06-23 14:10:17 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-06-23 16:00:49 +0200
commit67ed6552b831df66713bac9e672738796128d33f (patch)
tree59c97d41e0b49d75a90aa3de987968ab9b1ff447 /client/src/app/shared/moderation
parent0c4bacbff53bc732f5a2677d62a6ead7752e2405 (diff)
downloadPeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.gz
PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.zst
PeerTube-67ed6552b831df66713bac9e672738796128d33f.zip
Reorganize client shared modules
Diffstat (limited to 'client/src/app/shared/moderation')
-rw-r--r--client/src/app/shared/moderation/index.ts2
-rw-r--r--client/src/app/shared/moderation/user-ban-modal.component.html38
-rw-r--r--client/src/app/shared/moderation/user-ban-modal.component.scss6
-rw-r--r--client/src/app/shared/moderation/user-ban-modal.component.ts70
-rw-r--r--client/src/app/shared/moderation/user-moderation-dropdown.component.html9
-rw-r--r--client/src/app/shared/moderation/user-moderation-dropdown.component.ts382
6 files changed, 0 insertions, 507 deletions
diff --git a/client/src/app/shared/moderation/index.ts b/client/src/app/shared/moderation/index.ts
deleted file mode 100644
index 9a77c64c0..000000000
--- a/client/src/app/shared/moderation/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
1export * from './user-ban-modal.component'
2export * from './user-moderation-dropdown.component'
diff --git a/client/src/app/shared/moderation/user-ban-modal.component.html b/client/src/app/shared/moderation/user-ban-modal.component.html
deleted file mode 100644
index 365eb1938..000000000
--- a/client/src/app/shared/moderation/user-ban-modal.component.html
+++ /dev/null
@@ -1,38 +0,0 @@
1<ng-template #modal>
2 <div class="modal-header">
3 <h4 i18n class="modal-title">Ban</h4>
4
5 <my-global-icon iconName="cross" aria-label="Close" role="button" (click)="hide()"></my-global-icon>
6 </div>
7
8 <div class="modal-body">
9 <form novalidate [formGroup]="form" (ngSubmit)="banUser()">
10 <div class="form-group">
11 <textarea
12 i18n-placeholder placeholder="Reason..." formControlName="reason"
13 class="form-control" [ngClass]="{ 'input-error': formErrors['reason'] }"
14 ></textarea>
15 <div *ngIf="formErrors.reason" class="form-error">
16 {{ formErrors.reason }}
17 </div>
18 </div>
19
20 <div i18n>
21 A banned user will no longer be able to login.
22 </div>
23
24 <div class="form-group inputs">
25 <input
26 type="button" role="button" i18n-value value="Cancel" class="action-button action-button-cancel"
27 (click)="hide()" (key.enter)="hide()"
28 >
29
30 <input
31 type="submit" i18n-value value="Ban this user" class="action-button-submit"
32 [disabled]="!form.valid"
33 >
34 </div>
35 </form>
36 </div>
37
38</ng-template>
diff --git a/client/src/app/shared/moderation/user-ban-modal.component.scss b/client/src/app/shared/moderation/user-ban-modal.component.scss
deleted file mode 100644
index 84562f15c..000000000
--- a/client/src/app/shared/moderation/user-ban-modal.component.scss
+++ /dev/null
@@ -1,6 +0,0 @@
1@import 'variables';
2@import 'mixins';
3
4textarea {
5 @include peertube-textarea(100%, 60px);
6}
diff --git a/client/src/app/shared/moderation/user-ban-modal.component.ts b/client/src/app/shared/moderation/user-ban-modal.component.ts
deleted file mode 100644
index 1647e3691..000000000
--- a/client/src/app/shared/moderation/user-ban-modal.component.ts
+++ /dev/null
@@ -1,70 +0,0 @@
1import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core'
2import { Notifier } from '@app/core'
3import { I18n } from '@ngx-translate/i18n-polyfill'
4import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
5import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
6import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
7import { FormReactive, UserValidatorsService } from '@app/shared/forms'
8import { UserService } from '@app/shared/users'
9import { 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})
16export class UserBanModalComponent extends FormReactive implements OnInit {
17 @ViewChild('modal', { static: true }) modal: NgbModal
18 @Output() userBanned = new EventEmitter<User | User[]>()
19
20 private usersToBan: User | User[]
21 private openedModal: NgbModalRef
22
23 constructor (
24 protected formValidatorService: FormValidatorService,
25 private modalService: NgbModal,
26 private notifier: Notifier,
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 | User[]) {
41 this.usersToBan = user
42 this.openedModal = this.modalService.open(this.modal, { centered: true })
43 }
44
45 hide () {
46 this.usersToBan = undefined
47 this.openedModal.close()
48 }
49
50 async banUser () {
51 const reason = this.form.value['reason'] || undefined
52
53 this.userService.banUsers(this.usersToBan, reason)
54 .subscribe(
55 () => {
56 const message = Array.isArray(this.usersToBan)
57 ? this.i18n('{{num}} users banned.', { num: this.usersToBan.length })
58 : this.i18n('User {{username}} banned.', { username: this.usersToBan.username })
59
60 this.notifier.success(message)
61
62 this.userBanned.emit(this.usersToBan)
63 this.hide()
64 },
65
66 err => this.notifier.error(err.message)
67 )
68 }
69
70}
diff --git a/client/src/app/shared/moderation/user-moderation-dropdown.component.html b/client/src/app/shared/moderation/user-moderation-dropdown.component.html
deleted file mode 100644
index 4d562387a..000000000
--- a/client/src/app/shared/moderation/user-moderation-dropdown.component.html
+++ /dev/null
@@ -1,9 +0,0 @@
1<ng-container *ngIf="userActions.length !== 0">
2 <my-user-ban-modal #userBanModal (userBanned)="onUserBanned()"></my-user-ban-modal>
3
4 <my-action-dropdown
5 [actions]="userActions" [entry]="{ user: user, account: account }"
6 [buttonSize]="buttonSize" [placement]="placement" [label]="label"
7 [container]="container"
8 ></my-action-dropdown>
9</ng-container>
diff --git a/client/src/app/shared/moderation/user-moderation-dropdown.component.ts b/client/src/app/shared/moderation/user-moderation-dropdown.component.ts
deleted file mode 100644
index 82f39050e..000000000
--- a/client/src/app/shared/moderation/user-moderation-dropdown.component.ts
+++ /dev/null
@@ -1,382 +0,0 @@
1import { Component, EventEmitter, Input, OnChanges, OnInit, Output, ViewChild } from '@angular/core'
2import { I18n } from '@ngx-translate/i18n-polyfill'
3import { DropdownAction } from '@app/shared/buttons/action-dropdown.component'
4import { UserBanModalComponent } from '@app/shared/moderation/user-ban-modal.component'
5import { UserService } from '@app/shared/users'
6import { AuthService, ConfirmService, Notifier, ServerService } from '@app/core'
7import { User, UserRight } from '../../../../../shared/models/users'
8import { Account } from '@app/shared/account/account.model'
9import { BlocklistService } from '@app/shared/blocklist'
10import { ServerConfig, BulkRemoveCommentsOfBody } from '@shared/models'
11import { BulkService } from '../bulk/bulk.service'
12
13@Component({
14 selector: 'my-user-moderation-dropdown',
15 templateUrl: './user-moderation-dropdown.component.html'
16})
17export class UserModerationDropdownComponent implements OnInit, OnChanges {
18 @ViewChild('userBanModal') userBanModal: UserBanModalComponent
19
20 @Input() user: User
21 @Input() account: Account
22
23 @Input() buttonSize: 'normal' | 'small' = 'normal'
24 @Input() placement = 'left-top left-bottom auto'
25 @Input() label: string
26 @Input() container: 'body' | undefined = undefined
27
28 @Output() userChanged = new EventEmitter()
29 @Output() userDeleted = new EventEmitter()
30
31 userActions: DropdownAction<{ user: User, account: Account }>[][] = []
32
33 private serverConfig: ServerConfig
34
35 constructor (
36 private authService: AuthService,
37 private notifier: Notifier,
38 private confirmService: ConfirmService,
39 private serverService: ServerService,
40 private userService: UserService,
41 private blocklistService: BlocklistService,
42 private bulkService: BulkService,
43 private i18n: I18n
44 ) { }
45
46 get requiresEmailVerification () {
47 return this.serverConfig.signup.requiresEmailVerification
48 }
49
50 ngOnInit (): void {
51 this.serverConfig = this.serverService.getTmpConfig()
52 this.serverService.getConfig()
53 .subscribe(config => this.serverConfig = config)
54 }
55
56 ngOnChanges () {
57 this.buildActions()
58 }
59
60 openBanUserModal (user: User) {
61 if (user.username === 'root') {
62 this.notifier.error(this.i18n('You cannot ban root.'))
63 return
64 }
65
66 this.userBanModal.openModal(user)
67 }
68
69 onUserBanned () {
70 this.userChanged.emit()
71 }
72
73 async unbanUser (user: User) {
74 const message = this.i18n('Do you really want to unban {{username}}?', { username: user.username })
75 const res = await this.confirmService.confirm(message, this.i18n('Unban'))
76 if (res === false) return
77
78 this.userService.unbanUsers(user)
79 .subscribe(
80 () => {
81 this.notifier.success(this.i18n('User {{username}} unbanned.', { username: user.username }))
82
83 this.userChanged.emit()
84 },
85
86 err => this.notifier.error(err.message)
87 )
88 }
89
90 async removeUser (user: User) {
91 if (user.username === 'root') {
92 this.notifier.error(this.i18n('You cannot delete root.'))
93 return
94 }
95
96 const message = this.i18n('If you remove this user, you will not be able to create another with the same username!')
97 const res = await this.confirmService.confirm(message, this.i18n('Delete'))
98 if (res === false) return
99
100 this.userService.removeUser(user).subscribe(
101 () => {
102 this.notifier.success(this.i18n('User {{username}} deleted.', { username: user.username }))
103 this.userDeleted.emit()
104 },
105
106 err => this.notifier.error(err.message)
107 )
108 }
109
110 setEmailAsVerified (user: User) {
111 this.userService.updateUser(user.id, { emailVerified: true }).subscribe(
112 () => {
113 this.notifier.success(this.i18n('User {{username}} email set as verified', { username: user.username }))
114
115 this.userChanged.emit()
116 },
117
118 err => this.notifier.error(err.message)
119 )
120 }
121
122 blockAccountByUser (account: Account) {
123 this.blocklistService.blockAccountByUser(account)
124 .subscribe(
125 () => {
126 this.notifier.success(this.i18n('Account {{nameWithHost}} muted.', { nameWithHost: account.nameWithHost }))
127
128 this.account.mutedByUser = true
129 this.userChanged.emit()
130 },
131
132 err => this.notifier.error(err.message)
133 )
134 }
135
136 unblockAccountByUser (account: Account) {
137 this.blocklistService.unblockAccountByUser(account)
138 .subscribe(
139 () => {
140 this.notifier.success(this.i18n('Account {{nameWithHost}} unmuted.', { nameWithHost: account.nameWithHost }))
141
142 this.account.mutedByUser = false
143 this.userChanged.emit()
144 },
145
146 err => this.notifier.error(err.message)
147 )
148 }
149
150 blockServerByUser (host: string) {
151 this.blocklistService.blockServerByUser(host)
152 .subscribe(
153 () => {
154 this.notifier.success(this.i18n('Instance {{host}} muted.', { host }))
155
156 this.account.mutedServerByUser = true
157 this.userChanged.emit()
158 },
159
160 err => this.notifier.error(err.message)
161 )
162 }
163
164 unblockServerByUser (host: string) {
165 this.blocklistService.unblockServerByUser(host)
166 .subscribe(
167 () => {
168 this.notifier.success(this.i18n('Instance {{host}} unmuted.', { host }))
169
170 this.account.mutedServerByUser = false
171 this.userChanged.emit()
172 },
173
174 err => this.notifier.error(err.message)
175 )
176 }
177
178 blockAccountByInstance (account: Account) {
179 this.blocklistService.blockAccountByInstance(account)
180 .subscribe(
181 () => {
182 this.notifier.success(this.i18n('Account {{nameWithHost}} muted by the instance.', { nameWithHost: account.nameWithHost }))
183
184 this.account.mutedByInstance = true
185 this.userChanged.emit()
186 },
187
188 err => this.notifier.error(err.message)
189 )
190 }
191
192 unblockAccountByInstance (account: Account) {
193 this.blocklistService.unblockAccountByInstance(account)
194 .subscribe(
195 () => {
196 this.notifier.success(this.i18n('Account {{nameWithHost}} unmuted by the instance.', { nameWithHost: account.nameWithHost }))
197
198 this.account.mutedByInstance = false
199 this.userChanged.emit()
200 },
201
202 err => this.notifier.error(err.message)
203 )
204 }
205
206 blockServerByInstance (host: string) {
207 this.blocklistService.blockServerByInstance(host)
208 .subscribe(
209 () => {
210 this.notifier.success(this.i18n('Instance {{host}} muted by the instance.', { host }))
211
212 this.account.mutedServerByInstance = true
213 this.userChanged.emit()
214 },
215
216 err => this.notifier.error(err.message)
217 )
218 }
219
220 unblockServerByInstance (host: string) {
221 this.blocklistService.unblockServerByInstance(host)
222 .subscribe(
223 () => {
224 this.notifier.success(this.i18n('Instance {{host}} unmuted by the instance.', { host }))
225
226 this.account.mutedServerByInstance = false
227 this.userChanged.emit()
228 },
229
230 err => this.notifier.error(err.message)
231 )
232 }
233
234 async bulkRemoveCommentsOf (body: BulkRemoveCommentsOfBody) {
235 const message = this.i18n('Are you sure you want to remove all the comments of this account?')
236 const res = await this.confirmService.confirm(message, this.i18n('Delete account comments'))
237 if (res === false) return
238
239 this.bulkService.removeCommentsOf(body)
240 .subscribe(
241 () => {
242 this.notifier.success(this.i18n('Will remove comments of this account (may take several minutes).'))
243 },
244
245 err => this.notifier.error(err.message)
246 )
247 }
248
249 getRouterUserEditLink (user: User) {
250 return [ '/admin', 'users', 'update', user.id ]
251 }
252
253 private buildActions () {
254 this.userActions = []
255
256 if (this.authService.isLoggedIn()) {
257 const authUser = this.authService.getUser()
258
259 if (this.user && authUser.id === this.user.id) return
260
261 if (this.user && authUser.hasRight(UserRight.MANAGE_USERS) && authUser.canManage(this.user)) {
262 this.userActions.push([
263 {
264 label: this.i18n('Edit user'),
265 description: this.i18n('Change quota, role, and more.'),
266 linkBuilder: ({ user }) => this.getRouterUserEditLink(user)
267 },
268 {
269 label: this.i18n('Delete user'),
270 description: this.i18n('Videos will be deleted, comments will be tombstoned.'),
271 handler: ({ user }) => this.removeUser(user)
272 },
273 {
274 label: this.i18n('Ban'),
275 description: this.i18n('User won\'t be able to login anymore, but videos and comments will be kept as is.'),
276 handler: ({ user }) => this.openBanUserModal(user),
277 isDisplayed: ({ user }) => !user.blocked
278 },
279 {
280 label: this.i18n('Unban user'),
281 description: this.i18n('Allow the user to login and create videos/comments again'),
282 handler: ({ user }) => this.unbanUser(user),
283 isDisplayed: ({ user }) => user.blocked
284 },
285 {
286 label: this.i18n('Set Email as Verified'),
287 handler: ({ user }) => this.setEmailAsVerified(user),
288 isDisplayed: ({ user }) => this.requiresEmailVerification && !user.blocked && user.emailVerified === false
289 }
290 ])
291 }
292
293 // Actions on accounts/servers
294 if (this.account) {
295 // User actions
296 this.userActions.push([
297 {
298 label: this.i18n('Mute this account'),
299 description: this.i18n('Hide any content from that user for you.'),
300 isDisplayed: ({ account }) => account.mutedByUser === false,
301 handler: ({ account }) => this.blockAccountByUser(account)
302 },
303 {
304 label: this.i18n('Unmute this account'),
305 description: this.i18n('Show back content from that user for you.'),
306 isDisplayed: ({ account }) => account.mutedByUser === true,
307 handler: ({ account }) => this.unblockAccountByUser(account)
308 },
309 {
310 label: this.i18n('Mute the instance'),
311 description: this.i18n('Hide any content from that instance for you.'),
312 isDisplayed: ({ account }) => !account.userId && account.mutedServerByInstance === false,
313 handler: ({ account }) => this.blockServerByUser(account.host)
314 },
315 {
316 label: this.i18n('Unmute the instance'),
317 description: this.i18n('Show back content from that instance for you.'),
318 isDisplayed: ({ account }) => !account.userId && account.mutedServerByInstance === true,
319 handler: ({ account }) => this.unblockServerByUser(account.host)
320 },
321 {
322 label: this.i18n('Remove comments from your videos'),
323 description: this.i18n('Remove comments of this account from your videos.'),
324 handler: ({ account }) => this.bulkRemoveCommentsOf({ accountName: account.nameWithHost, scope: 'my-videos' })
325 }
326 ])
327
328 let instanceActions: DropdownAction<{ user: User, account: Account }>[] = []
329
330 // Instance actions on account blocklists
331 if (authUser.hasRight(UserRight.MANAGE_ACCOUNTS_BLOCKLIST)) {
332 instanceActions = instanceActions.concat([
333 {
334 label: this.i18n('Mute this account by your instance'),
335 description: this.i18n('Hide any content from that user for you, your instance and its users.'),
336 isDisplayed: ({ account }) => account.mutedByInstance === false,
337 handler: ({ account }) => this.blockAccountByInstance(account)
338 },
339 {
340 label: this.i18n('Unmute this account by your instance'),
341 description: this.i18n('Show back content from that user for you, your instance and its users.'),
342 isDisplayed: ({ account }) => account.mutedByInstance === true,
343 handler: ({ account }) => this.unblockAccountByInstance(account)
344 }
345 ])
346 }
347
348 // Instance actions on server blocklists
349 if (authUser.hasRight(UserRight.MANAGE_SERVERS_BLOCKLIST)) {
350 instanceActions = instanceActions.concat([
351 {
352 label: this.i18n('Mute the instance by your instance'),
353 description: this.i18n('Hide any content from that instance for you, your instance and its users.'),
354 isDisplayed: ({ account }) => !account.userId && account.mutedServerByInstance === false,
355 handler: ({ account }) => this.blockServerByInstance(account.host)
356 },
357 {
358 label: this.i18n('Unmute the instance by your instance'),
359 description: this.i18n('Show back content from that instance for you, your instance and its users.'),
360 isDisplayed: ({ account }) => !account.userId && account.mutedServerByInstance === true,
361 handler: ({ account }) => this.unblockServerByInstance(account.host)
362 }
363 ])
364 }
365
366 if (authUser.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT)) {
367 instanceActions = instanceActions.concat([
368 {
369 label: this.i18n('Remove comments from your instance'),
370 description: this.i18n('Remove comments of this account from your instance.'),
371 handler: ({ account }) => this.bulkRemoveCommentsOf({ accountName: account.nameWithHost, scope: 'instance' })
372 }
373 ])
374 }
375
376 if (instanceActions.length !== 0) {
377 this.userActions.push(instanceActions)
378 }
379 }
380 }
381 }
382}