aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/moderation
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-10-05 16:56:14 +0200
committerChocobozzz <me@florianbigard.com>2018-10-05 17:02:10 +0200
commit79bd2632d62f2f600d663815fcc00a01ca981aa1 (patch)
tree2a6b5df65fdd6025dda16cf7cd743c4530c63bf6 /client/src/app/shared/moderation
parente724fa93c71d76d709e819a05e5e2904a3c4205b (diff)
downloadPeerTube-79bd2632d62f2f600d663815fcc00a01ca981aa1.tar.gz
PeerTube-79bd2632d62f2f600d663815fcc00a01ca981aa1.tar.zst
PeerTube-79bd2632d62f2f600d663815fcc00a01ca981aa1.zip
Add user moderation in the account page
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.ts3
-rw-r--r--client/src/app/shared/moderation/user-moderation-dropdown.component.html6
-rw-r--r--client/src/app/shared/moderation/user-moderation-dropdown.component.ts69
4 files changed, 45 insertions, 35 deletions
diff --git a/client/src/app/shared/moderation/index.ts b/client/src/app/shared/moderation/index.ts
index 2245294c5..9a77c64c0 100644
--- a/client/src/app/shared/moderation/index.ts
+++ b/client/src/app/shared/moderation/index.ts
@@ -1,2 +1,2 @@
1export * from './user-ban-modal.component' 1export * from './user-ban-modal.component'
2export * from './user-moderation-dropdown.component' \ No newline at end of file 2export * from './user-moderation-dropdown.component'
diff --git a/client/src/app/shared/moderation/user-ban-modal.component.ts b/client/src/app/shared/moderation/user-ban-modal.component.ts
index d49783cd2..67ae38e48 100644
--- a/client/src/app/shared/moderation/user-ban-modal.component.ts
+++ b/client/src/app/shared/moderation/user-ban-modal.component.ts
@@ -5,7 +5,8 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
5import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' 5import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
6import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' 6import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
7import { FormReactive, UserValidatorsService } from '@app/shared/forms' 7import { FormReactive, UserValidatorsService } from '@app/shared/forms'
8import { User, UserService } from '@app/shared/users' 8import { UserService } from '@app/shared/users'
9import { User } from '../../../../../shared'
9 10
10@Component({ 11@Component({
11 selector: 'my-user-ban-modal', 12 selector: 'my-user-ban-modal',
diff --git a/client/src/app/shared/moderation/user-moderation-dropdown.component.html b/client/src/app/shared/moderation/user-moderation-dropdown.component.html
index ed8a4dc66..ed1a4c863 100644
--- a/client/src/app/shared/moderation/user-moderation-dropdown.component.html
+++ b/client/src/app/shared/moderation/user-moderation-dropdown.component.html
@@ -1,3 +1,5 @@
1<my-user-ban-modal #userBanModal (userBanned)="onUserBanned()"></my-user-ban-modal> 1<ng-container *ngIf="user && userActions.length !== 0">
2 <my-user-ban-modal #userBanModal (userBanned)="onUserBanned()"></my-user-ban-modal>
2 3
3<my-action-dropdown i18n-label label="Actions" [actions]="userActions" [entry]="user"></my-action-dropdown> \ No newline at end of file 4 <my-action-dropdown i18n-label label="Actions" [actions]="userActions" [entry]="user" [buttonSize]="buttonSize"></my-action-dropdown>
5</ng-container> \ No newline at end of file
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}