From 791645e620fb98c6e7c32271d91d91ff7e41b892 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 8 Oct 2018 15:15:11 +0200 Subject: Add bulk actions in users table --- .../app/shared/moderation/user-moderation-dropdown.component.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'client/src/app/shared/moderation/user-moderation-dropdown.component.ts') 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..174e9f024 100644 --- a/client/src/app/shared/moderation/user-moderation-dropdown.component.ts +++ b/client/src/app/shared/moderation/user-moderation-dropdown.component.ts @@ -2,7 +2,6 @@ import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angu import { NotificationsService } from 'angular2-notifications' 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 { UserService } from '@app/shared/users' import { AuthService, ConfirmService } from '@app/core' @@ -24,8 +23,6 @@ export class UserModerationDropdownComponent implements OnInit { userActions: DropdownAction[] = [] - private openedModal: NgbModalRef - constructor ( private authService: AuthService, private notificationsService: NotificationsService, @@ -38,10 +35,6 @@ export class UserModerationDropdownComponent implements OnInit { this.buildActions() } - hideBanUserModal () { - this.openedModal.close() - } - openBanUserModal (user: User) { if (user.username === 'root') { this.notificationsService.error(this.i18n('Error'), this.i18n('You cannot ban root.')) @@ -60,7 +53,7 @@ export class UserModerationDropdownComponent implements OnInit { const res = await this.confirmService.confirm(message, this.i18n('Unban')) if (res === false) return - this.userService.unbanUser(user) + this.userService.unbanUsers(user) .subscribe( () => { this.notificationsService.success( -- cgit v1.2.3 From 24b9417cec5cc785a57b2fe169a1ae88b88801a4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 8 Oct 2018 15:51:38 +0200 Subject: Add users search filter --- client/src/app/shared/moderation/user-moderation-dropdown.component.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'client/src/app/shared/moderation/user-moderation-dropdown.component.ts') 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 174e9f024..105c99d8b 100644 --- a/client/src/app/shared/moderation/user-moderation-dropdown.component.ts +++ b/client/src/app/shared/moderation/user-moderation-dropdown.component.ts @@ -17,6 +17,7 @@ export class UserModerationDropdownComponent implements OnInit { @Input() user: User @Input() buttonSize: 'normal' | 'small' = 'normal' + @Input() placement = 'left' @Output() userChanged = new EventEmitter() @Output() userDeleted = new EventEmitter() -- cgit v1.2.3 From af5767ffae41b2d5604e41ba9a7225c623dd6735 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 12 Oct 2018 17:26:40 +0200 Subject: Add user/instance block by users in the client --- .../user-moderation-dropdown.component.ts | 121 +++++++++++++++++++-- 1 file changed, 111 insertions(+), 10 deletions(-) (limited to 'client/src/app/shared/moderation/user-moderation-dropdown.component.ts') 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 @@ -import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' +import { Component, EventEmitter, Input, OnChanges, Output, ViewChild } from '@angular/core' import { NotificationsService } from 'angular2-notifications' import { I18n } from '@ngx-translate/i18n-polyfill' import { DropdownAction } from '@app/shared/buttons/action-dropdown.component' @@ -6,16 +6,20 @@ import { UserBanModalComponent } from '@app/shared/moderation/user-ban-modal.com import { UserService } from '@app/shared/users' import { AuthService, ConfirmService } from '@app/core' import { User, UserRight } from '../../../../../shared/models/users' +import { Account } from '@app/shared/account/account.model' +import { BlocklistService } from '@app/shared/blocklist' @Component({ selector: 'my-user-moderation-dropdown', templateUrl: './user-moderation-dropdown.component.html', styleUrls: [ './user-moderation-dropdown.component.scss' ] }) -export class UserModerationDropdownComponent implements OnInit { +export class UserModerationDropdownComponent implements OnChanges { @ViewChild('userBanModal') userBanModal: UserBanModalComponent @Input() user: User + @Input() account: Account + @Input() buttonSize: 'normal' | 'small' = 'normal' @Input() placement = 'left' @@ -29,10 +33,11 @@ export class UserModerationDropdownComponent implements OnInit { private notificationsService: NotificationsService, private confirmService: ConfirmService, private userService: UserService, + private blocklistService: BlocklistService, private i18n: I18n ) { } - ngOnInit () { + ngOnChanges () { this.buildActions() } @@ -92,6 +97,74 @@ export class UserModerationDropdownComponent implements OnInit { ) } + blockAccountByUser (account: Account) { + this.blocklistService.blockAccountByUser(account) + .subscribe( + () => { + this.notificationsService.success( + this.i18n('Success'), + this.i18n('Account {{nameWithHost}} muted.', { nameWithHost: account.nameWithHost }) + ) + + this.account.muted = true + this.userChanged.emit() + }, + + err => this.notificationsService.error(this.i18n('Error'), err.message) + ) + } + + unblockAccountByUser (account: Account) { + this.blocklistService.unblockAccountByUser(account) + .subscribe( + () => { + this.notificationsService.success( + this.i18n('Success'), + this.i18n('Account {{nameWithHost}} unmuted.', { nameWithHost: account.nameWithHost }) + ) + + this.account.muted = false + this.userChanged.emit() + }, + + err => this.notificationsService.error(this.i18n('Error'), err.message) + ) + } + + blockServerByUser (host: string) { + this.blocklistService.blockServerByUser(host) + .subscribe( + () => { + this.notificationsService.success( + this.i18n('Success'), + this.i18n('Instance {{host}} muted.', { host }) + ) + + this.account.mutedServer = true + this.userChanged.emit() + }, + + err => this.notificationsService.error(this.i18n('Error'), err.message) + ) + } + + unblockServerByUser (host: string) { + this.blocklistService.unblockServerByUser(host) + .subscribe( + () => { + this.notificationsService.success( + this.i18n('Success'), + this.i18n('Instance {{host}} unmuted.', { host }) + ) + + this.account.mutedServer = false + this.userChanged.emit() + }, + + err => this.notificationsService.error(this.i18n('Error'), err.message) + ) + } + getRouterUserEditLink (user: User) { return [ '/admin', 'users', 'update', user.id ] } @@ -102,25 +175,53 @@ export class UserModerationDropdownComponent implements OnInit { if (this.authService.isLoggedIn()) { const authUser = this.authService.getUser() - if (authUser.hasRight(UserRight.MANAGE_USERS)) { + if (this.user && authUser.id === this.user.id) return + + if (this.user && authUser.hasRight(UserRight.MANAGE_USERS)) { this.userActions = this.userActions.concat([ { label: this.i18n('Edit'), - linkBuilder: this.getRouterUserEditLink + linkBuilder: ({ user }) => this.getRouterUserEditLink(user) }, { label: this.i18n('Delete'), - handler: user => this.removeUser(user) + handler: ({ user }) => this.removeUser(user) }, { label: this.i18n('Ban'), - handler: user => this.openBanUserModal(user), - isDisplayed: user => !user.blocked + handler: ({ user }) => this.openBanUserModal(user), + isDisplayed: ({ user }) => !user.muted }, { label: this.i18n('Unban'), - handler: user => this.unbanUser(user), - isDisplayed: user => user.blocked + handler: ({ user }) => this.unbanUser(user), + isDisplayed: ({ user }) => user.muted + } + ]) + } + + // User actions on accounts/servers + if (this.account) { + this.userActions = this.userActions.concat([ + { + label: this.i18n('Mute this account'), + isDisplayed: ({ account }) => account.muted === false, + handler: ({ account }) => this.blockAccountByUser(account) + }, + { + label: this.i18n('Unmute this account'), + isDisplayed: ({ account }) => account.muted === true, + handler: ({ account }) => this.unblockAccountByUser(account) + }, + { + label: this.i18n('Mute the instance'), + isDisplayed: ({ account }) => !account.userId && account.mutedServer === false, + handler: ({ account }) => this.blockServerByUser(account.host) + }, + { + label: this.i18n('Unmute the instance'), + isDisplayed: ({ account }) => !account.userId && account.mutedServer === true, + handler: ({ account }) => this.unblockServerByUser(account.host) } ]) } -- cgit v1.2.3 From 65b21c961c69c4a63c7c0c34be3d6d034a1176c7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 15 Oct 2018 16:43:14 +0200 Subject: Add ability to mute a user/instance by server in client --- .../user-moderation-dropdown.component.ts | 137 ++++++++++++++++++--- 1 file changed, 119 insertions(+), 18 deletions(-) (limited to 'client/src/app/shared/moderation/user-moderation-dropdown.component.ts') 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 2f4a55f37..908f0b8e0 100644 --- a/client/src/app/shared/moderation/user-moderation-dropdown.component.ts +++ b/client/src/app/shared/moderation/user-moderation-dropdown.component.ts @@ -26,7 +26,7 @@ export class UserModerationDropdownComponent implements OnChanges { @Output() userChanged = new EventEmitter() @Output() userDeleted = new EventEmitter() - userActions: DropdownAction[] = [] + userActions: DropdownAction<{ user: User, account: Account }>[] = [] constructor ( private authService: AuthService, @@ -106,7 +106,7 @@ export class UserModerationDropdownComponent implements OnChanges { this.i18n('Account {{nameWithHost}} muted.', { nameWithHost: account.nameWithHost }) ) - this.account.muted = true + this.account.mutedByUser = true this.userChanged.emit() }, @@ -123,7 +123,7 @@ export class UserModerationDropdownComponent implements OnChanges { this.i18n('Account {{nameWithHost}} unmuted.', { nameWithHost: account.nameWithHost }) ) - this.account.muted = false + this.account.mutedByUser = false this.userChanged.emit() }, @@ -140,7 +140,7 @@ export class UserModerationDropdownComponent implements OnChanges { this.i18n('Instance {{host}} muted.', { host }) ) - this.account.mutedServer = true + this.account.mutedServerByUser = true this.userChanged.emit() }, @@ -157,7 +157,75 @@ export class UserModerationDropdownComponent implements OnChanges { this.i18n('Instance {{host}} unmuted.', { host }) ) - this.account.mutedServer = false + this.account.mutedServerByUser = false + this.userChanged.emit() + }, + + err => this.notificationsService.error(this.i18n('Error'), err.message) + ) + } + + blockAccountByInstance (account: Account) { + this.blocklistService.blockAccountByInstance(account) + .subscribe( + () => { + this.notificationsService.success( + this.i18n('Success'), + this.i18n('Account {{nameWithHost}} muted by the instance.', { nameWithHost: account.nameWithHost }) + ) + + this.account.mutedByInstance = true + this.userChanged.emit() + }, + + err => this.notificationsService.error(this.i18n('Error'), err.message) + ) + } + + unblockAccountByInstance (account: Account) { + this.blocklistService.unblockAccountByInstance(account) + .subscribe( + () => { + this.notificationsService.success( + this.i18n('Success'), + this.i18n('Account {{nameWithHost}} unmuted by the instance.', { nameWithHost: account.nameWithHost }) + ) + + this.account.mutedByInstance = false + this.userChanged.emit() + }, + + err => this.notificationsService.error(this.i18n('Error'), err.message) + ) + } + + blockServerByInstance (host: string) { + this.blocklistService.blockServerByInstance(host) + .subscribe( + () => { + this.notificationsService.success( + this.i18n('Success'), + this.i18n('Instance {{host}} muted by the instance.', { host }) + ) + + this.account.mutedServerByInstance = true + this.userChanged.emit() + }, + + err => this.notificationsService.error(this.i18n('Error'), err.message) + ) + } + + unblockServerByInstance (host: string) { + this.blocklistService.unblockServerByInstance(host) + .subscribe( + () => { + this.notificationsService.success( + this.i18n('Success'), + this.i18n('Instance {{host}} unmuted by the instance.', { host }) + ) + + this.account.mutedServerByInstance = false this.userChanged.emit() }, @@ -189,41 +257,74 @@ export class UserModerationDropdownComponent implements OnChanges { }, { label: this.i18n('Ban'), - handler: ({ user }) => this.openBanUserModal(user), - isDisplayed: ({ user }) => !user.muted + handler: ({ user }: { user: User }) => this.openBanUserModal(user), + isDisplayed: ({ user }: { user: User }) => !user.blocked }, { label: this.i18n('Unban'), - handler: ({ user }) => this.unbanUser(user), - isDisplayed: ({ user }) => user.muted + handler: ({ user }: { user: User }) => this.unbanUser(user), + isDisplayed: ({ user }: { user: User }) => user.blocked } ]) } - // User actions on accounts/servers + // Actions on accounts/servers if (this.account) { + // User actions this.userActions = this.userActions.concat([ { label: this.i18n('Mute this account'), - isDisplayed: ({ account }) => account.muted === false, - handler: ({ account }) => this.blockAccountByUser(account) + isDisplayed: ({ account }: { account: Account }) => account.mutedByUser === false, + handler: ({ account }: { account: Account }) => this.blockAccountByUser(account) }, { label: this.i18n('Unmute this account'), - isDisplayed: ({ account }) => account.muted === true, - handler: ({ account }) => this.unblockAccountByUser(account) + isDisplayed: ({ account }: { account: Account }) => account.mutedByUser === true, + handler: ({ account }: { account: Account }) => this.unblockAccountByUser(account) }, { label: this.i18n('Mute the instance'), - isDisplayed: ({ account }) => !account.userId && account.mutedServer === false, - handler: ({ account }) => this.blockServerByUser(account.host) + isDisplayed: ({ account }: { account: Account }) => !account.userId && account.mutedServerByInstance === false, + handler: ({ account }: { account: Account }) => this.blockServerByUser(account.host) }, { label: this.i18n('Unmute the instance'), - isDisplayed: ({ account }) => !account.userId && account.mutedServer === true, - handler: ({ account }) => this.unblockServerByUser(account.host) + isDisplayed: ({ account }: { account: Account }) => !account.userId && account.mutedServerByInstance === true, + handler: ({ account }: { account: Account }) => this.unblockServerByUser(account.host) } ]) + + // Instance actions + if (authUser.hasRight(UserRight.MANAGE_ACCOUNTS_BLOCKLIST)) { + this.userActions = this.userActions.concat([ + { + label: this.i18n('Mute this account by your instance'), + isDisplayed: ({ account }: { account: Account }) => account.mutedByInstance === false, + handler: ({ account }: { account: Account }) => this.blockAccountByInstance(account) + }, + { + label: this.i18n('Unmute this account by your instance'), + isDisplayed: ({ account }: { account: Account }) => account.mutedByInstance === true, + handler: ({ account }: { account: Account }) => this.unblockAccountByInstance(account) + } + ]) + } + + // Instance actions + if (authUser.hasRight(UserRight.MANAGE_SERVERS_BLOCKLIST)) { + this.userActions = this.userActions.concat([ + { + label: this.i18n('Mute the instance by your instance'), + isDisplayed: ({ account }: { account: Account }) => !account.userId && account.mutedServerByInstance === false, + handler: ({ account }: { account: Account }) => this.blockServerByInstance(account.host) + }, + { + label: this.i18n('Unmute the instance by your instance'), + isDisplayed: ({ account }: { account: Account }) => !account.userId && account.mutedServerByInstance === true, + handler: ({ account }: { account: Account }) => this.unblockServerByInstance(account.host) + } + ]) + } } } } -- cgit v1.2.3 From fc2ec87a8c4dcfbb91a1a62cf4c07a2a8e6a50fe Mon Sep 17 00:00:00 2001 From: Josh Morel Date: Wed, 21 Nov 2018 02:48:29 -0500 Subject: enable email verification by admin (#1348) * enable email verification by admin * rename/label to set email as verified to be more explicit that admin is not sending another email to confirm * add update user emailVerified check-params test * make user.model emailVerified property required --- .../user-moderation-dropdown.component.ts | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'client/src/app/shared/moderation/user-moderation-dropdown.component.ts') 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 908f0b8e0..460750740 100644 --- a/client/src/app/shared/moderation/user-moderation-dropdown.component.ts +++ b/client/src/app/shared/moderation/user-moderation-dropdown.component.ts @@ -4,7 +4,7 @@ import { I18n } from '@ngx-translate/i18n-polyfill' import { DropdownAction } from '@app/shared/buttons/action-dropdown.component' import { UserBanModalComponent } from '@app/shared/moderation/user-ban-modal.component' import { UserService } from '@app/shared/users' -import { AuthService, ConfirmService } from '@app/core' +import { AuthService, ConfirmService, ServerService } from '@app/core' import { User, UserRight } from '../../../../../shared/models/users' import { Account } from '@app/shared/account/account.model' import { BlocklistService } from '@app/shared/blocklist' @@ -32,11 +32,16 @@ export class UserModerationDropdownComponent implements OnChanges { private authService: AuthService, private notificationsService: NotificationsService, private confirmService: ConfirmService, + private serverService: ServerService, private userService: UserService, private blocklistService: BlocklistService, private i18n: I18n ) { } + get requiresEmailVerification () { + return this.serverService.getConfig().signup.requiresEmailVerification + } + ngOnChanges () { this.buildActions() } @@ -97,6 +102,19 @@ export class UserModerationDropdownComponent implements OnChanges { ) } + setEmailAsVerified (user: User) { + this.userService.updateUser(user.id, { emailVerified: true }).subscribe( + () => { + this.notificationsService.success( + this.i18n('Success'), + this.i18n('User {{username}} email set as verified', { username: user.username }) + ) + }, + + err => this.notificationsService.error(this.i18n('Error'), err.message) + ) + } + blockAccountByUser (account: Account) { this.blocklistService.blockAccountByUser(account) .subscribe( @@ -264,6 +282,11 @@ export class UserModerationDropdownComponent implements OnChanges { label: this.i18n('Unban'), handler: ({ user }: { user: User }) => this.unbanUser(user), isDisplayed: ({ user }: { user: User }) => user.blocked + }, + { + label: this.i18n('Set Email as Verified'), + handler: ({ user }: { user: User }) => this.setEmailAsVerified(user), + isDisplayed: ({ user }: { user: User }) => this.requiresEmailVerification && !user.blocked && user.emailVerified === false } ]) } -- cgit v1.2.3 From f97c91f7ec4afc26ab790fbefa63d11b3060f40f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 21 Nov 2018 17:05:31 +0100 Subject: Add separators in user moderation dropdown --- .../moderation/user-moderation-dropdown.component.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'client/src/app/shared/moderation/user-moderation-dropdown.component.ts') 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 460750740..47967f8e5 100644 --- a/client/src/app/shared/moderation/user-moderation-dropdown.component.ts +++ b/client/src/app/shared/moderation/user-moderation-dropdown.component.ts @@ -26,7 +26,7 @@ export class UserModerationDropdownComponent implements OnChanges { @Output() userChanged = new EventEmitter() @Output() userDeleted = new EventEmitter() - userActions: DropdownAction<{ user: User, account: Account }>[] = [] + userActions: DropdownAction<{ user: User, account: Account }>[][] = [] constructor ( private authService: AuthService, @@ -264,7 +264,7 @@ export class UserModerationDropdownComponent implements OnChanges { if (this.user && authUser.id === this.user.id) return if (this.user && authUser.hasRight(UserRight.MANAGE_USERS)) { - this.userActions = this.userActions.concat([ + this.userActions.push([ { label: this.i18n('Edit'), linkBuilder: ({ user }) => this.getRouterUserEditLink(user) @@ -294,7 +294,7 @@ export class UserModerationDropdownComponent implements OnChanges { // Actions on accounts/servers if (this.account) { // User actions - this.userActions = this.userActions.concat([ + this.userActions.push([ { label: this.i18n('Mute this account'), isDisplayed: ({ account }: { account: Account }) => account.mutedByUser === false, @@ -317,9 +317,11 @@ export class UserModerationDropdownComponent implements OnChanges { } ]) + let instanceActions: DropdownAction<{ user: User, account: Account }>[] = [] + // Instance actions if (authUser.hasRight(UserRight.MANAGE_ACCOUNTS_BLOCKLIST)) { - this.userActions = this.userActions.concat([ + instanceActions = instanceActions.concat([ { label: this.i18n('Mute this account by your instance'), isDisplayed: ({ account }: { account: Account }) => account.mutedByInstance === false, @@ -335,7 +337,7 @@ export class UserModerationDropdownComponent implements OnChanges { // Instance actions if (authUser.hasRight(UserRight.MANAGE_SERVERS_BLOCKLIST)) { - this.userActions = this.userActions.concat([ + instanceActions = instanceActions.concat([ { label: this.i18n('Mute the instance by your instance'), isDisplayed: ({ account }: { account: Account }) => !account.userId && account.mutedServerByInstance === false, @@ -348,6 +350,10 @@ export class UserModerationDropdownComponent implements OnChanges { } ]) } + + if (instanceActions.length !== 0) { + this.userActions.push(instanceActions) + } } } } -- cgit v1.2.3 From a99e2d9448f12ebfb7e824fd34470b52206fd7a8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 21 Nov 2018 17:11:56 +0100 Subject: Reload user table when setting an email to verified --- client/src/app/shared/moderation/user-moderation-dropdown.component.ts | 2 ++ 1 file changed, 2 insertions(+) (limited to 'client/src/app/shared/moderation/user-moderation-dropdown.component.ts') 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 47967f8e5..d391246e0 100644 --- a/client/src/app/shared/moderation/user-moderation-dropdown.component.ts +++ b/client/src/app/shared/moderation/user-moderation-dropdown.component.ts @@ -109,6 +109,8 @@ export class UserModerationDropdownComponent implements OnChanges { this.i18n('Success'), this.i18n('User {{username}} email set as verified', { username: user.username }) ) + + this.userChanged.emit() }, err => this.notificationsService.error(this.i18n('Error'), err.message) -- cgit v1.2.3 From 4e74e8032be8293ffe3cb3c30528d4ef7c11a798 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 5 Dec 2018 14:36:05 +0100 Subject: Remove inferred type --- .../user-moderation-dropdown.component.ts | 44 +++++++++++----------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'client/src/app/shared/moderation/user-moderation-dropdown.component.ts') 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 d391246e0..e3c9db923 100644 --- a/client/src/app/shared/moderation/user-moderation-dropdown.component.ts +++ b/client/src/app/shared/moderation/user-moderation-dropdown.component.ts @@ -277,18 +277,18 @@ export class UserModerationDropdownComponent implements OnChanges { }, { label: this.i18n('Ban'), - handler: ({ user }: { user: User }) => this.openBanUserModal(user), - isDisplayed: ({ user }: { user: User }) => !user.blocked + handler: ({ user }) => this.openBanUserModal(user), + isDisplayed: ({ user }) => !user.blocked }, { label: this.i18n('Unban'), - handler: ({ user }: { user: User }) => this.unbanUser(user), - isDisplayed: ({ user }: { user: User }) => user.blocked + handler: ({ user }) => this.unbanUser(user), + isDisplayed: ({ user }) => user.blocked }, { label: this.i18n('Set Email as Verified'), - handler: ({ user }: { user: User }) => this.setEmailAsVerified(user), - isDisplayed: ({ user }: { user: User }) => this.requiresEmailVerification && !user.blocked && user.emailVerified === false + handler: ({ user }) => this.setEmailAsVerified(user), + isDisplayed: ({ user }) => this.requiresEmailVerification && !user.blocked && user.emailVerified === false } ]) } @@ -299,23 +299,23 @@ export class UserModerationDropdownComponent implements OnChanges { this.userActions.push([ { label: this.i18n('Mute this account'), - isDisplayed: ({ account }: { account: Account }) => account.mutedByUser === false, - handler: ({ account }: { account: Account }) => this.blockAccountByUser(account) + isDisplayed: ({ account }) => account.mutedByUser === false, + handler: ({ account }) => this.blockAccountByUser(account) }, { label: this.i18n('Unmute this account'), - isDisplayed: ({ account }: { account: Account }) => account.mutedByUser === true, - handler: ({ account }: { account: Account }) => this.unblockAccountByUser(account) + isDisplayed: ({ account }) => account.mutedByUser === true, + handler: ({ account }) => this.unblockAccountByUser(account) }, { label: this.i18n('Mute the instance'), - isDisplayed: ({ account }: { account: Account }) => !account.userId && account.mutedServerByInstance === false, - handler: ({ account }: { account: Account }) => this.blockServerByUser(account.host) + isDisplayed: ({ account }) => !account.userId && account.mutedServerByInstance === false, + handler: ({ account }) => this.blockServerByUser(account.host) }, { label: this.i18n('Unmute the instance'), - isDisplayed: ({ account }: { account: Account }) => !account.userId && account.mutedServerByInstance === true, - handler: ({ account }: { account: Account }) => this.unblockServerByUser(account.host) + isDisplayed: ({ account }) => !account.userId && account.mutedServerByInstance === true, + handler: ({ account }) => this.unblockServerByUser(account.host) } ]) @@ -326,13 +326,13 @@ export class UserModerationDropdownComponent implements OnChanges { instanceActions = instanceActions.concat([ { label: this.i18n('Mute this account by your instance'), - isDisplayed: ({ account }: { account: Account }) => account.mutedByInstance === false, - handler: ({ account }: { account: Account }) => this.blockAccountByInstance(account) + isDisplayed: ({ account }) => account.mutedByInstance === false, + handler: ({ account }) => this.blockAccountByInstance(account) }, { label: this.i18n('Unmute this account by your instance'), - isDisplayed: ({ account }: { account: Account }) => account.mutedByInstance === true, - handler: ({ account }: { account: Account }) => this.unblockAccountByInstance(account) + isDisplayed: ({ account }) => account.mutedByInstance === true, + handler: ({ account }) => this.unblockAccountByInstance(account) } ]) } @@ -342,13 +342,13 @@ export class UserModerationDropdownComponent implements OnChanges { instanceActions = instanceActions.concat([ { label: this.i18n('Mute the instance by your instance'), - isDisplayed: ({ account }: { account: Account }) => !account.userId && account.mutedServerByInstance === false, - handler: ({ account }: { account: Account }) => this.blockServerByInstance(account.host) + isDisplayed: ({ account }) => !account.userId && account.mutedServerByInstance === false, + handler: ({ account }) => this.blockServerByInstance(account.host) }, { label: this.i18n('Unmute the instance by your instance'), - isDisplayed: ({ account }: { account: Account }) => !account.userId && account.mutedServerByInstance === true, - handler: ({ account }: { account: Account }) => this.unblockServerByInstance(account.host) + isDisplayed: ({ account }) => !account.userId && account.mutedServerByInstance === true, + handler: ({ account }) => this.unblockServerByInstance(account.host) } ]) } -- cgit v1.2.3 From f8b2c1b4f509c037b9650cca2c5befd21f056df3 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 19 Dec 2018 16:04:34 +0100 Subject: Refractor notification service Shorter name and use primeng component --- .../user-moderation-dropdown.component.ts | 86 +++++++--------------- 1 file changed, 26 insertions(+), 60 deletions(-) (limited to 'client/src/app/shared/moderation/user-moderation-dropdown.component.ts') 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 e3c9db923..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,10 +1,9 @@ import { Component, EventEmitter, Input, OnChanges, Output, ViewChild } from '@angular/core' -import { NotificationsService } from 'angular2-notifications' import { I18n } from '@ngx-translate/i18n-polyfill' import { DropdownAction } from '@app/shared/buttons/action-dropdown.component' import { UserBanModalComponent } from '@app/shared/moderation/user-ban-modal.component' import { UserService } from '@app/shared/users' -import { AuthService, ConfirmService, ServerService } from '@app/core' +import { AuthService, ConfirmService, Notifier, ServerService } from '@app/core' import { User, UserRight } from '../../../../../shared/models/users' import { Account } from '@app/shared/account/account.model' import { BlocklistService } from '@app/shared/blocklist' @@ -30,7 +29,7 @@ export class UserModerationDropdownComponent implements OnChanges { constructor ( private authService: AuthService, - private notificationsService: NotificationsService, + private notifier: Notifier, private confirmService: ConfirmService, private serverService: ServerService, private userService: UserService, @@ -48,7 +47,7 @@ export class UserModerationDropdownComponent implements OnChanges { openBanUserModal (user: User) { if (user.username === 'root') { - this.notificationsService.error(this.i18n('Error'), this.i18n('You cannot ban root.')) + this.notifier.error(this.i18n('You cannot ban root.')) return } @@ -67,21 +66,18 @@ export class UserModerationDropdownComponent implements OnChanges { this.userService.unbanUsers(user) .subscribe( () => { - this.notificationsService.success( - this.i18n('Success'), - this.i18n('User {{username}} unbanned.', { username: user.username }) - ) + this.notifier.success(this.i18n('User {{username}} unbanned.', { username: user.username })) this.userChanged.emit() }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } async removeUser (user: User) { if (user.username === 'root') { - this.notificationsService.error(this.i18n('Error'), this.i18n('You cannot delete root.')) + this.notifier.error(this.i18n('You cannot delete root.')) return } @@ -91,29 +87,23 @@ export class UserModerationDropdownComponent implements OnChanges { this.userService.removeUser(user).subscribe( () => { - this.notificationsService.success( - this.i18n('Success'), - this.i18n('User {{username}} deleted.', { username: user.username }) - ) + this.notifier.success(this.i18n('User {{username}} deleted.', { username: user.username })) this.userDeleted.emit() }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } setEmailAsVerified (user: User) { this.userService.updateUser(user.id, { emailVerified: true }).subscribe( () => { - this.notificationsService.success( - this.i18n('Success'), - this.i18n('User {{username}} email set as verified', { username: user.username }) - ) + this.notifier.success(this.i18n('User {{username}} email set as verified', { username: user.username })) this.userChanged.emit() }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } @@ -121,16 +111,13 @@ export class UserModerationDropdownComponent implements OnChanges { this.blocklistService.blockAccountByUser(account) .subscribe( () => { - this.notificationsService.success( - this.i18n('Success'), - this.i18n('Account {{nameWithHost}} muted.', { nameWithHost: account.nameWithHost }) - ) + this.notifier.success(this.i18n('Account {{nameWithHost}} muted.', { nameWithHost: account.nameWithHost })) this.account.mutedByUser = true this.userChanged.emit() }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } @@ -138,16 +125,13 @@ export class UserModerationDropdownComponent implements OnChanges { this.blocklistService.unblockAccountByUser(account) .subscribe( () => { - this.notificationsService.success( - this.i18n('Success'), - this.i18n('Account {{nameWithHost}} unmuted.', { nameWithHost: account.nameWithHost }) - ) + this.notifier.success(this.i18n('Account {{nameWithHost}} unmuted.', { nameWithHost: account.nameWithHost })) this.account.mutedByUser = false this.userChanged.emit() }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } @@ -155,16 +139,13 @@ export class UserModerationDropdownComponent implements OnChanges { this.blocklistService.blockServerByUser(host) .subscribe( () => { - this.notificationsService.success( - this.i18n('Success'), - this.i18n('Instance {{host}} muted.', { host }) - ) + this.notifier.success(this.i18n('Instance {{host}} muted.', { host })) this.account.mutedServerByUser = true this.userChanged.emit() }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } @@ -172,16 +153,13 @@ export class UserModerationDropdownComponent implements OnChanges { this.blocklistService.unblockServerByUser(host) .subscribe( () => { - this.notificationsService.success( - this.i18n('Success'), - this.i18n('Instance {{host}} unmuted.', { host }) - ) + this.notifier.success(this.i18n('Instance {{host}} unmuted.', { host })) this.account.mutedServerByUser = false this.userChanged.emit() }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } @@ -189,16 +167,13 @@ export class UserModerationDropdownComponent implements OnChanges { this.blocklistService.blockAccountByInstance(account) .subscribe( () => { - this.notificationsService.success( - this.i18n('Success'), - this.i18n('Account {{nameWithHost}} muted by the instance.', { nameWithHost: account.nameWithHost }) - ) + this.notifier.success(this.i18n('Account {{nameWithHost}} muted by the instance.', { nameWithHost: account.nameWithHost })) this.account.mutedByInstance = true this.userChanged.emit() }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } @@ -206,16 +181,13 @@ export class UserModerationDropdownComponent implements OnChanges { this.blocklistService.unblockAccountByInstance(account) .subscribe( () => { - this.notificationsService.success( - this.i18n('Success'), - this.i18n('Account {{nameWithHost}} unmuted by the instance.', { nameWithHost: account.nameWithHost }) - ) + this.notifier.success(this.i18n('Account {{nameWithHost}} unmuted by the instance.', { nameWithHost: account.nameWithHost })) this.account.mutedByInstance = false this.userChanged.emit() }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } @@ -223,16 +195,13 @@ export class UserModerationDropdownComponent implements OnChanges { this.blocklistService.blockServerByInstance(host) .subscribe( () => { - this.notificationsService.success( - this.i18n('Success'), - this.i18n('Instance {{host}} muted by the instance.', { host }) - ) + this.notifier.success(this.i18n('Instance {{host}} muted by the instance.', { host })) this.account.mutedServerByInstance = true this.userChanged.emit() }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } @@ -240,16 +209,13 @@ export class UserModerationDropdownComponent implements OnChanges { this.blocklistService.unblockServerByInstance(host) .subscribe( () => { - this.notificationsService.success( - this.i18n('Success'), - this.i18n('Instance {{host}} unmuted by the instance.', { host }) - ) + this.notifier.success(this.i18n('Instance {{host}} unmuted by the instance.', { host })) this.account.mutedServerByInstance = false this.userChanged.emit() }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } -- cgit v1.2.3