diff options
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 | 121 |
1 files changed, 111 insertions, 10 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 105c99d8b..2f4a55f37 100644 --- a/client/src/app/shared/moderation/user-moderation-dropdown.component.ts +++ b/client/src/app/shared/moderation/user-moderation-dropdown.component.ts | |||
@@ -1,4 +1,4 @@ | |||
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' | 2 | import { NotificationsService } from 'angular2-notifications' |
3 | import { I18n } from '@ngx-translate/i18n-polyfill' | 3 | import { I18n } from '@ngx-translate/i18n-polyfill' |
4 | import { DropdownAction } from '@app/shared/buttons/action-dropdown.component' | 4 | import { DropdownAction } from '@app/shared/buttons/action-dropdown.component' |
@@ -6,16 +6,20 @@ import { UserBanModalComponent } from '@app/shared/moderation/user-ban-modal.com | |||
6 | import { UserService } from '@app/shared/users' | 6 | import { UserService } from '@app/shared/users' |
7 | import { AuthService, ConfirmService } from '@app/core' | 7 | import { AuthService, ConfirmService } from '@app/core' |
8 | import { User, UserRight } from '../../../../../shared/models/users' | 8 | import { User, UserRight } from '../../../../../shared/models/users' |
9 | import { Account } from '@app/shared/account/account.model' | ||
10 | import { BlocklistService } from '@app/shared/blocklist' | ||
9 | 11 | ||
10 | @Component({ | 12 | @Component({ |
11 | selector: 'my-user-moderation-dropdown', | 13 | selector: 'my-user-moderation-dropdown', |
12 | templateUrl: './user-moderation-dropdown.component.html', | 14 | templateUrl: './user-moderation-dropdown.component.html', |
13 | styleUrls: [ './user-moderation-dropdown.component.scss' ] | 15 | styleUrls: [ './user-moderation-dropdown.component.scss' ] |
14 | }) | 16 | }) |
15 | export class UserModerationDropdownComponent implements OnInit { | 17 | export class UserModerationDropdownComponent implements OnChanges { |
16 | @ViewChild('userBanModal') userBanModal: UserBanModalComponent | 18 | @ViewChild('userBanModal') userBanModal: UserBanModalComponent |
17 | 19 | ||
18 | @Input() user: User | 20 | @Input() user: User |
21 | @Input() account: Account | ||
22 | |||
19 | @Input() buttonSize: 'normal' | 'small' = 'normal' | 23 | @Input() buttonSize: 'normal' | 'small' = 'normal' |
20 | @Input() placement = 'left' | 24 | @Input() placement = 'left' |
21 | 25 | ||
@@ -29,10 +33,11 @@ export class UserModerationDropdownComponent implements OnInit { | |||
29 | private notificationsService: NotificationsService, | 33 | private notificationsService: NotificationsService, |
30 | private confirmService: ConfirmService, | 34 | private confirmService: ConfirmService, |
31 | private userService: UserService, | 35 | private userService: UserService, |
36 | private blocklistService: BlocklistService, | ||
32 | private i18n: I18n | 37 | private i18n: I18n |
33 | ) { } | 38 | ) { } |
34 | 39 | ||
35 | ngOnInit () { | 40 | ngOnChanges () { |
36 | this.buildActions() | 41 | this.buildActions() |
37 | } | 42 | } |
38 | 43 | ||
@@ -92,6 +97,74 @@ export class UserModerationDropdownComponent implements OnInit { | |||
92 | ) | 97 | ) |
93 | } | 98 | } |
94 | 99 | ||
100 | blockAccountByUser (account: Account) { | ||
101 | this.blocklistService.blockAccountByUser(account) | ||
102 | .subscribe( | ||
103 | () => { | ||
104 | this.notificationsService.success( | ||
105 | this.i18n('Success'), | ||
106 | this.i18n('Account {{nameWithHost}} muted.', { nameWithHost: account.nameWithHost }) | ||
107 | ) | ||
108 | |||
109 | this.account.muted = true | ||
110 | this.userChanged.emit() | ||
111 | }, | ||
112 | |||
113 | err => this.notificationsService.error(this.i18n('Error'), err.message) | ||
114 | ) | ||
115 | } | ||
116 | |||
117 | unblockAccountByUser (account: Account) { | ||
118 | this.blocklistService.unblockAccountByUser(account) | ||
119 | .subscribe( | ||
120 | () => { | ||
121 | this.notificationsService.success( | ||
122 | this.i18n('Success'), | ||
123 | this.i18n('Account {{nameWithHost}} unmuted.', { nameWithHost: account.nameWithHost }) | ||
124 | ) | ||
125 | |||
126 | this.account.muted = false | ||
127 | this.userChanged.emit() | ||
128 | }, | ||
129 | |||
130 | err => this.notificationsService.error(this.i18n('Error'), err.message) | ||
131 | ) | ||
132 | } | ||
133 | |||
134 | blockServerByUser (host: string) { | ||
135 | this.blocklistService.blockServerByUser(host) | ||
136 | .subscribe( | ||
137 | () => { | ||
138 | this.notificationsService.success( | ||
139 | this.i18n('Success'), | ||
140 | this.i18n('Instance {{host}} muted.', { host }) | ||
141 | ) | ||
142 | |||
143 | this.account.mutedServer = true | ||
144 | this.userChanged.emit() | ||
145 | }, | ||
146 | |||
147 | err => this.notificationsService.error(this.i18n('Error'), err.message) | ||
148 | ) | ||
149 | } | ||
150 | |||
151 | unblockServerByUser (host: string) { | ||
152 | this.blocklistService.unblockServerByUser(host) | ||
153 | .subscribe( | ||
154 | () => { | ||
155 | this.notificationsService.success( | ||
156 | this.i18n('Success'), | ||
157 | this.i18n('Instance {{host}} unmuted.', { host }) | ||
158 | ) | ||
159 | |||
160 | this.account.mutedServer = false | ||
161 | this.userChanged.emit() | ||
162 | }, | ||
163 | |||
164 | err => this.notificationsService.error(this.i18n('Error'), err.message) | ||
165 | ) | ||
166 | } | ||
167 | |||
95 | getRouterUserEditLink (user: User) { | 168 | getRouterUserEditLink (user: User) { |
96 | return [ '/admin', 'users', 'update', user.id ] | 169 | return [ '/admin', 'users', 'update', user.id ] |
97 | } | 170 | } |
@@ -102,25 +175,53 @@ export class UserModerationDropdownComponent implements OnInit { | |||
102 | if (this.authService.isLoggedIn()) { | 175 | if (this.authService.isLoggedIn()) { |
103 | const authUser = this.authService.getUser() | 176 | const authUser = this.authService.getUser() |
104 | 177 | ||
105 | if (authUser.hasRight(UserRight.MANAGE_USERS)) { | 178 | if (this.user && authUser.id === this.user.id) return |
179 | |||
180 | if (this.user && authUser.hasRight(UserRight.MANAGE_USERS)) { | ||
106 | this.userActions = this.userActions.concat([ | 181 | this.userActions = this.userActions.concat([ |
107 | { | 182 | { |
108 | label: this.i18n('Edit'), | 183 | label: this.i18n('Edit'), |
109 | linkBuilder: this.getRouterUserEditLink | 184 | linkBuilder: ({ user }) => this.getRouterUserEditLink(user) |
110 | }, | 185 | }, |
111 | { | 186 | { |
112 | label: this.i18n('Delete'), | 187 | label: this.i18n('Delete'), |
113 | handler: user => this.removeUser(user) | 188 | handler: ({ user }) => this.removeUser(user) |
114 | }, | 189 | }, |
115 | { | 190 | { |
116 | label: this.i18n('Ban'), | 191 | label: this.i18n('Ban'), |
117 | handler: user => this.openBanUserModal(user), | 192 | handler: ({ user }) => this.openBanUserModal(user), |
118 | isDisplayed: user => !user.blocked | 193 | isDisplayed: ({ user }) => !user.muted |
119 | }, | 194 | }, |
120 | { | 195 | { |
121 | label: this.i18n('Unban'), | 196 | label: this.i18n('Unban'), |
122 | handler: user => this.unbanUser(user), | 197 | handler: ({ user }) => this.unbanUser(user), |
123 | isDisplayed: user => user.blocked | 198 | isDisplayed: ({ user }) => user.muted |
199 | } | ||
200 | ]) | ||
201 | } | ||
202 | |||
203 | // User actions on accounts/servers | ||
204 | if (this.account) { | ||
205 | this.userActions = this.userActions.concat([ | ||
206 | { | ||
207 | label: this.i18n('Mute this account'), | ||
208 | isDisplayed: ({ account }) => account.muted === false, | ||
209 | handler: ({ account }) => this.blockAccountByUser(account) | ||
210 | }, | ||
211 | { | ||
212 | label: this.i18n('Unmute this account'), | ||
213 | isDisplayed: ({ account }) => account.muted === true, | ||
214 | handler: ({ account }) => this.unblockAccountByUser(account) | ||
215 | }, | ||
216 | { | ||
217 | label: this.i18n('Mute the instance'), | ||
218 | isDisplayed: ({ account }) => !account.userId && account.mutedServer === false, | ||
219 | handler: ({ account }) => this.blockServerByUser(account.host) | ||
220 | }, | ||
221 | { | ||
222 | label: this.i18n('Unmute the instance'), | ||
223 | isDisplayed: ({ account }) => !account.userId && account.mutedServer === true, | ||
224 | handler: ({ account }) => this.unblockServerByUser(account.host) | ||
124 | } | 225 | } |
125 | ]) | 226 | ]) |
126 | } | 227 | } |