diff options
author | Chocobozzz <me@florianbigard.com> | 2019-02-11 11:52:34 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-02-11 11:52:34 +0100 |
commit | 88108880bbdba473cfe36ecbebc1c3c4f972e102 (patch) | |
tree | b242efb3b4f0d7e49d88f2d1f2063b5b3b0489c0 /client/src/app/shared/moderation/user-moderation-dropdown.component.ts | |
parent | 53a94c7cfa8368da4cd248d65df8346905938f0c (diff) | |
parent | 9b712a2017e4ab3cf12cd6bd58278905520159d0 (diff) | |
download | PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.tar.gz PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.tar.zst PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.zip |
Merge branch 'develop' into pr/1217
Diffstat (limited to 'client/src/app/shared/moderation/user-moderation-dropdown.component.ts')
-rw-r--r-- | client/src/app/shared/moderation/user-moderation-dropdown.component.ts | 261 |
1 files changed, 227 insertions, 34 deletions
diff --git a/client/src/app/shared/moderation/user-moderation-dropdown.component.ts b/client/src/app/shared/moderation/user-moderation-dropdown.component.ts index 4f88456de..9a2461ebf 100644 --- a/client/src/app/shared/moderation/user-moderation-dropdown.component.ts +++ b/client/src/app/shared/moderation/user-moderation-dropdown.component.ts | |||
@@ -1,50 +1,53 @@ | |||
1 | import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' | 1 | import { Component, EventEmitter, Input, OnChanges, Output, ViewChild } from '@angular/core' |
2 | import { NotificationsService } from 'angular2-notifications' | ||
3 | import { I18n } from '@ngx-translate/i18n-polyfill' | 2 | import { I18n } from '@ngx-translate/i18n-polyfill' |
4 | import { DropdownAction } from '@app/shared/buttons/action-dropdown.component' | 3 | import { DropdownAction } from '@app/shared/buttons/action-dropdown.component' |
5 | import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' | ||
6 | import { UserBanModalComponent } from '@app/shared/moderation/user-ban-modal.component' | 4 | import { UserBanModalComponent } from '@app/shared/moderation/user-ban-modal.component' |
7 | import { UserService } from '@app/shared/users' | 5 | import { UserService } from '@app/shared/users' |
8 | import { AuthService, ConfirmService } from '@app/core' | 6 | import { AuthService, ConfirmService, Notifier, ServerService } from '@app/core' |
9 | import { User, UserRight } from '../../../../../shared/models/users' | 7 | import { User, UserRight } from '../../../../../shared/models/users' |
8 | import { Account } from '@app/shared/account/account.model' | ||
9 | import { BlocklistService } from '@app/shared/blocklist' | ||
10 | 10 | ||
11 | @Component({ | 11 | @Component({ |
12 | selector: 'my-user-moderation-dropdown', | 12 | selector: 'my-user-moderation-dropdown', |
13 | templateUrl: './user-moderation-dropdown.component.html', | 13 | templateUrl: './user-moderation-dropdown.component.html', |
14 | styleUrls: [ './user-moderation-dropdown.component.scss' ] | 14 | styleUrls: [ './user-moderation-dropdown.component.scss' ] |
15 | }) | 15 | }) |
16 | export class UserModerationDropdownComponent implements OnInit { | 16 | export class UserModerationDropdownComponent implements OnChanges { |
17 | @ViewChild('userBanModal') userBanModal: UserBanModalComponent | 17 | @ViewChild('userBanModal') userBanModal: UserBanModalComponent |
18 | 18 | ||
19 | @Input() user: User | 19 | @Input() user: User |
20 | @Input() account: Account | ||
21 | |||
20 | @Input() buttonSize: 'normal' | 'small' = 'normal' | 22 | @Input() buttonSize: 'normal' | 'small' = 'normal' |
23 | @Input() placement = 'left' | ||
21 | 24 | ||
22 | @Output() userChanged = new EventEmitter() | 25 | @Output() userChanged = new EventEmitter() |
23 | @Output() userDeleted = new EventEmitter() | 26 | @Output() userDeleted = new EventEmitter() |
24 | 27 | ||
25 | userActions: DropdownAction<User>[] = [] | 28 | userActions: DropdownAction<{ user: User, account: Account }>[][] = [] |
26 | |||
27 | private openedModal: NgbModalRef | ||
28 | 29 | ||
29 | constructor ( | 30 | constructor ( |
30 | private authService: AuthService, | 31 | private authService: AuthService, |
31 | private notificationsService: NotificationsService, | 32 | private notifier: Notifier, |
32 | private confirmService: ConfirmService, | 33 | private confirmService: ConfirmService, |
34 | private serverService: ServerService, | ||
33 | private userService: UserService, | 35 | private userService: UserService, |
36 | private blocklistService: BlocklistService, | ||
34 | private i18n: I18n | 37 | private i18n: I18n |
35 | ) { } | 38 | ) { } |
36 | 39 | ||
37 | ngOnInit () { | 40 | get requiresEmailVerification () { |
38 | this.buildActions() | 41 | return this.serverService.getConfig().signup.requiresEmailVerification |
39 | } | 42 | } |
40 | 43 | ||
41 | hideBanUserModal () { | 44 | ngOnChanges () { |
42 | this.openedModal.close() | 45 | this.buildActions() |
43 | } | 46 | } |
44 | 47 | ||
45 | openBanUserModal (user: User) { | 48 | openBanUserModal (user: User) { |
46 | if (user.username === 'root') { | 49 | if (user.username === 'root') { |
47 | this.notificationsService.error(this.i18n('Error'), this.i18n('You cannot ban root.')) | 50 | this.notifier.error(this.i18n('You cannot ban root.')) |
48 | return | 51 | return |
49 | } | 52 | } |
50 | 53 | ||
@@ -60,24 +63,21 @@ export class UserModerationDropdownComponent implements OnInit { | |||
60 | const res = await this.confirmService.confirm(message, this.i18n('Unban')) | 63 | const res = await this.confirmService.confirm(message, this.i18n('Unban')) |
61 | if (res === false) return | 64 | if (res === false) return |
62 | 65 | ||
63 | this.userService.unbanUser(user) | 66 | this.userService.unbanUsers(user) |
64 | .subscribe( | 67 | .subscribe( |
65 | () => { | 68 | () => { |
66 | this.notificationsService.success( | 69 | this.notifier.success(this.i18n('User {{username}} unbanned.', { username: user.username })) |
67 | this.i18n('Success'), | ||
68 | this.i18n('User {{username}} unbanned.', { username: user.username }) | ||
69 | ) | ||
70 | 70 | ||
71 | this.userChanged.emit() | 71 | this.userChanged.emit() |
72 | }, | 72 | }, |
73 | 73 | ||
74 | err => this.notificationsService.error(this.i18n('Error'), err.message) | 74 | err => this.notifier.error(err.message) |
75 | ) | 75 | ) |
76 | } | 76 | } |
77 | 77 | ||
78 | async removeUser (user: User) { | 78 | async removeUser (user: User) { |
79 | if (user.username === 'root') { | 79 | if (user.username === 'root') { |
80 | this.notificationsService.error(this.i18n('Error'), this.i18n('You cannot delete root.')) | 80 | this.notifier.error(this.i18n('You cannot delete root.')) |
81 | return | 81 | return |
82 | } | 82 | } |
83 | 83 | ||
@@ -87,17 +87,138 @@ export class UserModerationDropdownComponent implements OnInit { | |||
87 | 87 | ||
88 | this.userService.removeUser(user).subscribe( | 88 | this.userService.removeUser(user).subscribe( |
89 | () => { | 89 | () => { |
90 | this.notificationsService.success( | 90 | this.notifier.success(this.i18n('User {{username}} deleted.', { username: user.username })) |
91 | this.i18n('Success'), | ||
92 | this.i18n('User {{username}} deleted.', { username: user.username }) | ||
93 | ) | ||
94 | this.userDeleted.emit() | 91 | this.userDeleted.emit() |
95 | }, | 92 | }, |
96 | 93 | ||
97 | err => this.notificationsService.error(this.i18n('Error'), err.message) | 94 | err => this.notifier.error(err.message) |
98 | ) | 95 | ) |
99 | } | 96 | } |
100 | 97 | ||
98 | setEmailAsVerified (user: User) { | ||
99 | this.userService.updateUser(user.id, { emailVerified: true }).subscribe( | ||
100 | () => { | ||
101 | this.notifier.success(this.i18n('User {{username}} email set as verified', { username: user.username })) | ||
102 | |||
103 | this.userChanged.emit() | ||
104 | }, | ||
105 | |||
106 | err => this.notifier.error(err.message) | ||
107 | ) | ||
108 | } | ||
109 | |||
110 | blockAccountByUser (account: Account) { | ||
111 | this.blocklistService.blockAccountByUser(account) | ||
112 | .subscribe( | ||
113 | () => { | ||
114 | this.notifier.success(this.i18n('Account {{nameWithHost}} muted.', { nameWithHost: account.nameWithHost })) | ||
115 | |||
116 | this.account.mutedByUser = true | ||
117 | this.userChanged.emit() | ||
118 | }, | ||
119 | |||
120 | err => this.notifier.error(err.message) | ||
121 | ) | ||
122 | } | ||
123 | |||
124 | unblockAccountByUser (account: Account) { | ||
125 | this.blocklistService.unblockAccountByUser(account) | ||
126 | .subscribe( | ||
127 | () => { | ||
128 | this.notifier.success(this.i18n('Account {{nameWithHost}} unmuted.', { nameWithHost: account.nameWithHost })) | ||
129 | |||
130 | this.account.mutedByUser = false | ||
131 | this.userChanged.emit() | ||
132 | }, | ||
133 | |||
134 | err => this.notifier.error(err.message) | ||
135 | ) | ||
136 | } | ||
137 | |||
138 | blockServerByUser (host: string) { | ||
139 | this.blocklistService.blockServerByUser(host) | ||
140 | .subscribe( | ||
141 | () => { | ||
142 | this.notifier.success(this.i18n('Instance {{host}} muted.', { host })) | ||
143 | |||
144 | this.account.mutedServerByUser = true | ||
145 | this.userChanged.emit() | ||
146 | }, | ||
147 | |||
148 | err => this.notifier.error(err.message) | ||
149 | ) | ||
150 | } | ||
151 | |||
152 | unblockServerByUser (host: string) { | ||
153 | this.blocklistService.unblockServerByUser(host) | ||
154 | .subscribe( | ||
155 | () => { | ||
156 | this.notifier.success(this.i18n('Instance {{host}} unmuted.', { host })) | ||
157 | |||
158 | this.account.mutedServerByUser = false | ||
159 | this.userChanged.emit() | ||
160 | }, | ||
161 | |||
162 | err => this.notifier.error(err.message) | ||
163 | ) | ||
164 | } | ||
165 | |||
166 | blockAccountByInstance (account: Account) { | ||
167 | this.blocklistService.blockAccountByInstance(account) | ||
168 | .subscribe( | ||
169 | () => { | ||
170 | this.notifier.success(this.i18n('Account {{nameWithHost}} muted by the instance.', { nameWithHost: account.nameWithHost })) | ||
171 | |||
172 | this.account.mutedByInstance = true | ||
173 | this.userChanged.emit() | ||
174 | }, | ||
175 | |||
176 | err => this.notifier.error(err.message) | ||
177 | ) | ||
178 | } | ||
179 | |||
180 | unblockAccountByInstance (account: Account) { | ||
181 | this.blocklistService.unblockAccountByInstance(account) | ||
182 | .subscribe( | ||
183 | () => { | ||
184 | this.notifier.success(this.i18n('Account {{nameWithHost}} unmuted by the instance.', { nameWithHost: account.nameWithHost })) | ||
185 | |||
186 | this.account.mutedByInstance = false | ||
187 | this.userChanged.emit() | ||
188 | }, | ||
189 | |||
190 | err => this.notifier.error(err.message) | ||
191 | ) | ||
192 | } | ||
193 | |||
194 | blockServerByInstance (host: string) { | ||
195 | this.blocklistService.blockServerByInstance(host) | ||
196 | .subscribe( | ||
197 | () => { | ||
198 | this.notifier.success(this.i18n('Instance {{host}} muted by the instance.', { host })) | ||
199 | |||
200 | this.account.mutedServerByInstance = true | ||
201 | this.userChanged.emit() | ||
202 | }, | ||
203 | |||
204 | err => this.notifier.error(err.message) | ||
205 | ) | ||
206 | } | ||
207 | |||
208 | unblockServerByInstance (host: string) { | ||
209 | this.blocklistService.unblockServerByInstance(host) | ||
210 | .subscribe( | ||
211 | () => { | ||
212 | this.notifier.success(this.i18n('Instance {{host}} unmuted by the instance.', { host })) | ||
213 | |||
214 | this.account.mutedServerByInstance = false | ||
215 | this.userChanged.emit() | ||
216 | }, | ||
217 | |||
218 | err => this.notifier.error(err.message) | ||
219 | ) | ||
220 | } | ||
221 | |||
101 | getRouterUserEditLink (user: User) { | 222 | getRouterUserEditLink (user: User) { |
102 | return [ '/admin', 'users', 'update', user.id ] | 223 | return [ '/admin', 'users', 'update', user.id ] |
103 | } | 224 | } |
@@ -108,28 +229,100 @@ export class UserModerationDropdownComponent implements OnInit { | |||
108 | if (this.authService.isLoggedIn()) { | 229 | if (this.authService.isLoggedIn()) { |
109 | const authUser = this.authService.getUser() | 230 | const authUser = this.authService.getUser() |
110 | 231 | ||
111 | if (authUser.hasRight(UserRight.MANAGE_USERS)) { | 232 | if (this.user && authUser.id === this.user.id) return |
112 | this.userActions = this.userActions.concat([ | 233 | |
234 | if (this.user && authUser.hasRight(UserRight.MANAGE_USERS)) { | ||
235 | this.userActions.push([ | ||
113 | { | 236 | { |
114 | label: this.i18n('Edit'), | 237 | label: this.i18n('Edit'), |
115 | linkBuilder: this.getRouterUserEditLink | 238 | linkBuilder: ({ user }) => this.getRouterUserEditLink(user) |
116 | }, | 239 | }, |
117 | { | 240 | { |
118 | label: this.i18n('Delete'), | 241 | label: this.i18n('Delete'), |
119 | handler: user => this.removeUser(user) | 242 | handler: ({ user }) => this.removeUser(user) |
120 | }, | 243 | }, |
121 | { | 244 | { |
122 | label: this.i18n('Ban'), | 245 | label: this.i18n('Ban'), |
123 | handler: user => this.openBanUserModal(user), | 246 | handler: ({ user }) => this.openBanUserModal(user), |
124 | isDisplayed: user => !user.blocked | 247 | isDisplayed: ({ user }) => !user.blocked |
125 | }, | 248 | }, |
126 | { | 249 | { |
127 | label: this.i18n('Unban'), | 250 | label: this.i18n('Unban'), |
128 | handler: user => this.unbanUser(user), | 251 | handler: ({ user }) => this.unbanUser(user), |
129 | isDisplayed: user => user.blocked | 252 | isDisplayed: ({ user }) => user.blocked |
253 | }, | ||
254 | { | ||
255 | label: this.i18n('Set Email as Verified'), | ||
256 | handler: ({ user }) => this.setEmailAsVerified(user), | ||
257 | isDisplayed: ({ user }) => this.requiresEmailVerification && !user.blocked && user.emailVerified === false | ||
130 | } | 258 | } |
131 | ]) | 259 | ]) |
132 | } | 260 | } |
261 | |||
262 | // Actions on accounts/servers | ||
263 | if (this.account) { | ||
264 | // User actions | ||
265 | this.userActions.push([ | ||
266 | { | ||
267 | label: this.i18n('Mute this account'), | ||
268 | isDisplayed: ({ account }) => account.mutedByUser === false, | ||
269 | handler: ({ account }) => this.blockAccountByUser(account) | ||
270 | }, | ||
271 | { | ||
272 | label: this.i18n('Unmute this account'), | ||
273 | isDisplayed: ({ account }) => account.mutedByUser === true, | ||
274 | handler: ({ account }) => this.unblockAccountByUser(account) | ||
275 | }, | ||
276 | { | ||
277 | label: this.i18n('Mute the instance'), | ||
278 | isDisplayed: ({ account }) => !account.userId && account.mutedServerByInstance === false, | ||
279 | handler: ({ account }) => this.blockServerByUser(account.host) | ||
280 | }, | ||
281 | { | ||
282 | label: this.i18n('Unmute the instance'), | ||
283 | isDisplayed: ({ account }) => !account.userId && account.mutedServerByInstance === true, | ||
284 | handler: ({ account }) => this.unblockServerByUser(account.host) | ||
285 | } | ||
286 | ]) | ||
287 | |||
288 | let instanceActions: DropdownAction<{ user: User, account: Account }>[] = [] | ||
289 | |||
290 | // Instance actions | ||
291 | if (authUser.hasRight(UserRight.MANAGE_ACCOUNTS_BLOCKLIST)) { | ||
292 | instanceActions = instanceActions.concat([ | ||
293 | { | ||
294 | label: this.i18n('Mute this account by your instance'), | ||
295 | isDisplayed: ({ account }) => account.mutedByInstance === false, | ||
296 | handler: ({ account }) => this.blockAccountByInstance(account) | ||
297 | }, | ||
298 | { | ||
299 | label: this.i18n('Unmute this account by your instance'), | ||
300 | isDisplayed: ({ account }) => account.mutedByInstance === true, | ||
301 | handler: ({ account }) => this.unblockAccountByInstance(account) | ||
302 | } | ||
303 | ]) | ||
304 | } | ||
305 | |||
306 | // Instance actions | ||
307 | if (authUser.hasRight(UserRight.MANAGE_SERVERS_BLOCKLIST)) { | ||
308 | instanceActions = instanceActions.concat([ | ||
309 | { | ||
310 | label: this.i18n('Mute the instance by your instance'), | ||
311 | isDisplayed: ({ account }) => !account.userId && account.mutedServerByInstance === false, | ||
312 | handler: ({ account }) => this.blockServerByInstance(account.host) | ||
313 | }, | ||
314 | { | ||
315 | label: this.i18n('Unmute the instance by your instance'), | ||
316 | isDisplayed: ({ account }) => !account.userId && account.mutedServerByInstance === true, | ||
317 | handler: ({ account }) => this.unblockServerByInstance(account.host) | ||
318 | } | ||
319 | ]) | ||
320 | } | ||
321 | |||
322 | if (instanceActions.length !== 0) { | ||
323 | this.userActions.push(instanceActions) | ||
324 | } | ||
325 | } | ||
133 | } | 326 | } |
134 | } | 327 | } |
135 | } | 328 | } |