X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fmoderation%2Fuser-moderation-dropdown.component.ts;h=4f88456defa03212407443483cfa890a47def945;hb=79bd2632d62f2f600d663815fcc00a01ca981aa1;hp=d92423476d001c27c78708d31e4579ca7b7e245e;hpb=e724fa93c71d76d709e819a05e5e2904a3c4205b;p=github%2FChocobozzz%2FPeerTube.git 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' import { DropdownAction } from '@app/shared/buttons/action-dropdown.component' import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' import { UserBanModalComponent } from '@app/shared/moderation/user-ban-modal.component' -import { User, UserService } from '@app/shared/users' +import { UserService } from '@app/shared/users' import { AuthService, ConfirmService } from '@app/core' -import { UserRight } from '../../../../../shared/models/users' +import { User, UserRight } from '../../../../../shared/models/users' @Component({ selector: 'my-user-moderation-dropdown', @@ -17,7 +17,10 @@ export class UserModerationDropdownComponent implements OnInit { @ViewChild('userBanModal') userBanModal: UserBanModalComponent @Input() user: User + @Input() buttonSize: 'normal' | 'small' = 'normal' + @Output() userChanged = new EventEmitter() + @Output() userDeleted = new EventEmitter() userActions: DropdownAction[] = [] @@ -32,34 +35,7 @@ export class UserModerationDropdownComponent implements OnInit { ) { } ngOnInit () { - this.userActions = [] - - if (this.authService.isLoggedIn()) { - const authUser = this.authService.getUser() - - if (authUser.hasRight(UserRight.MANAGE_USERS)) { - this.userActions = this.userActions.concat([ - { - label: this.i18n('Edit'), - linkBuilder: this.getRouterUserEditLink - }, - { - label: this.i18n('Delete'), - handler: user => this.removeUser(user) - }, - { - label: this.i18n('Ban'), - handler: user => this.openBanUserModal(user), - isDisplayed: user => !user.blocked - }, - { - label: this.i18n('Unban'), - handler: user => this.unbanUser(user), - isDisplayed: user => user.blocked - } - ]) - } - } + this.buildActions() } hideBanUserModal () { @@ -115,7 +91,7 @@ export class UserModerationDropdownComponent implements OnInit { this.i18n('Success'), this.i18n('User {{username}} deleted.', { username: user.username }) ) - this.userChanged.emit() + this.userDeleted.emit() }, err => this.notificationsService.error(this.i18n('Error'), err.message) @@ -125,4 +101,35 @@ export class UserModerationDropdownComponent implements OnInit { getRouterUserEditLink (user: User) { return [ '/admin', 'users', 'update', user.id ] } + + private buildActions () { + this.userActions = [] + + if (this.authService.isLoggedIn()) { + const authUser = this.authService.getUser() + + if (authUser.hasRight(UserRight.MANAGE_USERS)) { + this.userActions = this.userActions.concat([ + { + label: this.i18n('Edit'), + linkBuilder: this.getRouterUserEditLink + }, + { + label: this.i18n('Delete'), + handler: user => this.removeUser(user) + }, + { + label: this.i18n('Ban'), + handler: user => this.openBanUserModal(user), + isDisplayed: user => !user.blocked + }, + { + label: this.i18n('Unban'), + handler: user => this.unbanUser(user), + isDisplayed: user => user.blocked + } + ]) + } + } + } }