aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/moderation/user-moderation-dropdown.component.ts
diff options
context:
space:
mode:
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.ts69
1 files changed, 38 insertions, 31 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 d92423476..4f88456de 100644
--- a/client/src/app/shared/moderation/user-moderation-dropdown.component.ts
+++ b/client/src/app/shared/moderation/user-moderation-dropdown.component.ts
@@ -4,9 +4,9 @@ import { I18n } from '@ngx-translate/i18n-polyfill'
4import { DropdownAction } from '@app/shared/buttons/action-dropdown.component' 4import { DropdownAction } from '@app/shared/buttons/action-dropdown.component'
5import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' 5import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
6import { UserBanModalComponent } from '@app/shared/moderation/user-ban-modal.component' 6import { UserBanModalComponent } from '@app/shared/moderation/user-ban-modal.component'
7import { User, UserService } from '@app/shared/users' 7import { UserService } from '@app/shared/users'
8import { AuthService, ConfirmService } from '@app/core' 8import { AuthService, ConfirmService } from '@app/core'
9import { UserRight } from '../../../../../shared/models/users' 9import { User, UserRight } from '../../../../../shared/models/users'
10 10
11@Component({ 11@Component({
12 selector: 'my-user-moderation-dropdown', 12 selector: 'my-user-moderation-dropdown',
@@ -17,7 +17,10 @@ export class UserModerationDropdownComponent implements OnInit {
17 @ViewChild('userBanModal') userBanModal: UserBanModalComponent 17 @ViewChild('userBanModal') userBanModal: UserBanModalComponent
18 18
19 @Input() user: User 19 @Input() user: User
20 @Input() buttonSize: 'normal' | 'small' = 'normal'
21
20 @Output() userChanged = new EventEmitter() 22 @Output() userChanged = new EventEmitter()
23 @Output() userDeleted = new EventEmitter()
21 24
22 userActions: DropdownAction<User>[] = [] 25 userActions: DropdownAction<User>[] = []
23 26
@@ -32,34 +35,7 @@ export class UserModerationDropdownComponent implements OnInit {
32 ) { } 35 ) { }
33 36
34 ngOnInit () { 37 ngOnInit () {
35 this.userActions = [] 38 this.buildActions()
36
37 if (this.authService.isLoggedIn()) {
38 const authUser = this.authService.getUser()
39
40 if (authUser.hasRight(UserRight.MANAGE_USERS)) {
41 this.userActions = this.userActions.concat([
42 {
43 label: this.i18n('Edit'),
44 linkBuilder: this.getRouterUserEditLink
45 },
46 {
47 label: this.i18n('Delete'),
48 handler: user => this.removeUser(user)
49 },
50 {
51 label: this.i18n('Ban'),
52 handler: user => this.openBanUserModal(user),
53 isDisplayed: user => !user.blocked
54 },
55 {
56 label: this.i18n('Unban'),
57 handler: user => this.unbanUser(user),
58 isDisplayed: user => user.blocked
59 }
60 ])
61 }
62 }
63 } 39 }
64 40
65 hideBanUserModal () { 41 hideBanUserModal () {
@@ -115,7 +91,7 @@ export class UserModerationDropdownComponent implements OnInit {
115 this.i18n('Success'), 91 this.i18n('Success'),
116 this.i18n('User {{username}} deleted.', { username: user.username }) 92 this.i18n('User {{username}} deleted.', { username: user.username })
117 ) 93 )
118 this.userChanged.emit() 94 this.userDeleted.emit()
119 }, 95 },
120 96
121 err => this.notificationsService.error(this.i18n('Error'), err.message) 97 err => this.notificationsService.error(this.i18n('Error'), err.message)
@@ -125,4 +101,35 @@ export class UserModerationDropdownComponent implements OnInit {
125 getRouterUserEditLink (user: User) { 101 getRouterUserEditLink (user: User) {
126 return [ '/admin', 'users', 'update', user.id ] 102 return [ '/admin', 'users', 'update', user.id ]
127 } 103 }
104
105 private buildActions () {
106 this.userActions = []
107
108 if (this.authService.isLoggedIn()) {
109 const authUser = this.authService.getUser()
110
111 if (authUser.hasRight(UserRight.MANAGE_USERS)) {
112 this.userActions = this.userActions.concat([
113 {
114 label: this.i18n('Edit'),
115 linkBuilder: this.getRouterUserEditLink
116 },
117 {
118 label: this.i18n('Delete'),
119 handler: user => this.removeUser(user)
120 },
121 {
122 label: this.i18n('Ban'),
123 handler: user => this.openBanUserModal(user),
124 isDisplayed: user => !user.blocked
125 },
126 {
127 label: this.i18n('Unban'),
128 handler: user => this.unbanUser(user),
129 isDisplayed: user => user.blocked
130 }
131 ])
132 }
133 }
134 }
128} 135}