From 79bd2632d62f2f600d663815fcc00a01ca981aa1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 5 Oct 2018 16:56:14 +0200 Subject: [PATCH] Add user moderation in the account page --- .../src/app/+accounts/accounts.component.html | 5 ++ .../src/app/+accounts/accounts.component.scss | 12 ++++ .../src/app/+accounts/accounts.component.ts | 48 +++++++++++-- .../users/user-list/user-list.component.html | 3 +- .../src/app/shared/account/account.model.ts | 3 + .../buttons/action-dropdown.component.html | 2 +- .../buttons/action-dropdown.component.scss | 6 ++ .../buttons/action-dropdown.component.ts | 1 + client/src/app/shared/moderation/index.ts | 2 +- .../moderation/user-ban-modal.component.ts | 3 +- .../user-moderation-dropdown.component.html | 6 +- .../user-moderation-dropdown.component.ts | 69 ++++++++++--------- client/src/app/shared/users/user.service.ts | 6 +- server/models/account/account.ts | 3 +- server/models/video/video-format-utils.ts | 2 +- server/models/video/video.ts | 1 - .../tests/api/users/users-multiple-servers.ts | 6 ++ shared/models/actors/account.model.ts | 2 + 18 files changed, 132 insertions(+), 48 deletions(-) diff --git a/client/src/app/+accounts/accounts.component.html b/client/src/app/+accounts/accounts.component.html index 69f648269..036e794d2 100644 --- a/client/src/app/+accounts/accounts.component.html +++ b/client/src/app/+accounts/accounts.component.html @@ -8,6 +8,11 @@
{{ account.displayName }}
{{ account.nameWithHost }}
+ + Banned + + +
{{ account.followersCount }} subscribers
diff --git a/client/src/app/+accounts/accounts.component.scss b/client/src/app/+accounts/accounts.component.scss index 909b65bc7..3cedda889 100644 --- a/client/src/app/+accounts/accounts.component.scss +++ b/client/src/app/+accounts/accounts.component.scss @@ -3,4 +3,16 @@ .sub-menu { @include sub-menu-with-actor; +} + +my-user-moderation-dropdown, +.badge { + margin-left: 10px; + + position: relative; + top: 3px; +} + +.badge { + font-size: 13px; } \ No newline at end of file diff --git a/client/src/app/+accounts/accounts.component.ts b/client/src/app/+accounts/accounts.component.ts index af0451e91..e19927d6b 100644 --- a/client/src/app/+accounts/accounts.component.ts +++ b/client/src/app/+accounts/accounts.component.ts @@ -1,10 +1,14 @@ -import { Component, OnInit, OnDestroy } from '@angular/core' +import { Component, OnDestroy, OnInit } from '@angular/core' import { ActivatedRoute } from '@angular/router' import { AccountService } from '@app/shared/account/account.service' import { Account } from '@app/shared/account/account.model' -import { RestExtractor } from '@app/shared' -import { catchError, switchMap, distinctUntilChanged, map } from 'rxjs/operators' +import { RestExtractor, UserService } from '@app/shared' +import { catchError, distinctUntilChanged, map, switchMap, tap } from 'rxjs/operators' import { Subscription } from 'rxjs' +import { NotificationsService } from 'angular2-notifications' +import { User, UserRight } from '../../../../shared' +import { I18n } from '@ngx-translate/i18n-polyfill' +import { AuthService, RedirectService } from '@app/core' @Component({ templateUrl: './accounts.component.html', @@ -12,13 +16,19 @@ import { Subscription } from 'rxjs' }) export class AccountsComponent implements OnInit, OnDestroy { account: Account + user: User private routeSub: Subscription constructor ( private route: ActivatedRoute, + private userService: UserService, private accountService: AccountService, - private restExtractor: RestExtractor + private notificationsService: NotificationsService, + private restExtractor: RestExtractor, + private redirectService: RedirectService, + private authService: AuthService, + private i18n: I18n ) {} ngOnInit () { @@ -27,12 +37,40 @@ export class AccountsComponent implements OnInit, OnDestroy { map(params => params[ 'accountId' ]), distinctUntilChanged(), switchMap(accountId => this.accountService.getAccount(accountId)), + tap(account => this.getUserIfNeeded(account)), catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ])) ) - .subscribe(account => this.account = account) + .subscribe( + account => this.account = account, + + err => this.notificationsService.error(this.i18n('Error'), err.message) + ) } ngOnDestroy () { if (this.routeSub) this.routeSub.unsubscribe() } + + onUserChanged () { + this.getUserIfNeeded(this.account) + } + + onUserDeleted () { + this.redirectService.redirectToHomepage() + } + + private getUserIfNeeded (account: Account) { + if (!account.userId) return + if (!this.authService.isLoggedIn()) return + + const user = this.authService.getUser() + if (user.hasRight(UserRight.MANAGE_USERS)) { + this.userService.getUser(account.userId) + .subscribe( + user => this.user = user, + + err => this.notificationsService.error(this.i18n('Error'), err.message) + ) + } + } } diff --git a/client/src/app/+admin/users/user-list/user-list.component.html b/client/src/app/+admin/users/user-list/user-list.component.html index 2479ce9e4..cca057ba1 100644 --- a/client/src/app/+admin/users/user-list/user-list.component.html +++ b/client/src/app/+admin/users/user-list/user-list.component.html @@ -40,7 +40,8 @@ {{ user.roleLabel }} {{ user.createdAt }} - + + diff --git a/client/src/app/shared/account/account.model.ts b/client/src/app/shared/account/account.model.ts index 5058e372f..42f2cfeaf 100644 --- a/client/src/app/shared/account/account.model.ts +++ b/client/src/app/shared/account/account.model.ts @@ -6,11 +6,14 @@ export class Account extends Actor implements ServerAccount { description: string nameWithHost: string + userId?: number + constructor (hash: ServerAccount) { super(hash) this.displayName = hash.displayName this.description = hash.description + this.userId = hash.userId this.nameWithHost = Actor.CREATE_BY_STRING(this.name, this.host) } } diff --git a/client/src/app/shared/buttons/action-dropdown.component.html b/client/src/app/shared/buttons/action-dropdown.component.html index 8b7241379..8110e2515 100644 --- a/client/src/app/shared/buttons/action-dropdown.component.html +++ b/client/src/app/shared/buttons/action-dropdown.component.html @@ -1,5 +1,5 @@