From 00004f7f6b966a975498612117212b5373f4103c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 27 Oct 2021 09:36:37 +0200 Subject: Put admin users in overview tab --- client/src/app/+admin/users/user-edit/index.ts | 3 - .../users/user-edit/user-create.component.ts | 98 --------- .../users/user-edit/user-edit.component.html | 237 --------------------- .../users/user-edit/user-edit.component.scss | 76 ------- client/src/app/+admin/users/user-edit/user-edit.ts | 102 --------- .../users/user-edit/user-password.component.html | 21 -- .../users/user-edit/user-password.component.scss | 23 -- .../users/user-edit/user-password.component.ts | 55 ----- .../users/user-edit/user-update.component.ts | 139 ------------ 9 files changed, 754 deletions(-) delete mode 100644 client/src/app/+admin/users/user-edit/index.ts delete mode 100644 client/src/app/+admin/users/user-edit/user-create.component.ts delete mode 100644 client/src/app/+admin/users/user-edit/user-edit.component.html delete mode 100644 client/src/app/+admin/users/user-edit/user-edit.component.scss delete mode 100644 client/src/app/+admin/users/user-edit/user-edit.ts delete mode 100644 client/src/app/+admin/users/user-edit/user-password.component.html delete mode 100644 client/src/app/+admin/users/user-edit/user-password.component.scss delete mode 100644 client/src/app/+admin/users/user-edit/user-password.component.ts delete mode 100644 client/src/app/+admin/users/user-edit/user-update.component.ts (limited to 'client/src/app/+admin/users/user-edit') diff --git a/client/src/app/+admin/users/user-edit/index.ts b/client/src/app/+admin/users/user-edit/index.ts deleted file mode 100644 index ec734ef92..000000000 --- a/client/src/app/+admin/users/user-edit/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './user-create.component' -export * from './user-update.component' -export * from './user-password.component' diff --git a/client/src/app/+admin/users/user-edit/user-create.component.ts b/client/src/app/+admin/users/user-edit/user-create.component.ts deleted file mode 100644 index b61b22fd0..000000000 --- a/client/src/app/+admin/users/user-edit/user-create.component.ts +++ /dev/null @@ -1,98 +0,0 @@ -import { Component, OnInit } from '@angular/core' -import { Router } from '@angular/router' -import { ConfigService } from '@app/+admin/config/shared/config.service' -import { AuthService, Notifier, ScreenService, ServerService, UserService } from '@app/core' -import { - USER_CHANNEL_NAME_VALIDATOR, - USER_EMAIL_VALIDATOR, - USER_PASSWORD_OPTIONAL_VALIDATOR, - USER_PASSWORD_VALIDATOR, - USER_ROLE_VALIDATOR, - USER_USERNAME_VALIDATOR, - USER_VIDEO_QUOTA_DAILY_VALIDATOR, - USER_VIDEO_QUOTA_VALIDATOR -} from '@app/shared/form-validators/user-validators' -import { FormValidatorService } from '@app/shared/shared-forms' -import { UserCreate, UserRole } from '@shared/models' -import { UserEdit } from './user-edit' - -@Component({ - selector: 'my-user-create', - templateUrl: './user-edit.component.html', - styleUrls: [ './user-edit.component.scss' ] -}) -export class UserCreateComponent extends UserEdit implements OnInit { - error: string - - constructor ( - protected serverService: ServerService, - protected formValidatorService: FormValidatorService, - protected configService: ConfigService, - protected screenService: ScreenService, - protected auth: AuthService, - private router: Router, - private notifier: Notifier, - private userService: UserService - ) { - super() - - this.buildQuotaOptions() - } - - ngOnInit () { - super.ngOnInit() - - const defaultValues = { - role: UserRole.USER.toString(), - videoQuota: -1, - videoQuotaDaily: -1 - } - - this.buildForm({ - username: USER_USERNAME_VALIDATOR, - channelName: USER_CHANNEL_NAME_VALIDATOR, - email: USER_EMAIL_VALIDATOR, - password: this.isPasswordOptional() ? USER_PASSWORD_OPTIONAL_VALIDATOR : USER_PASSWORD_VALIDATOR, - role: USER_ROLE_VALIDATOR, - videoQuota: USER_VIDEO_QUOTA_VALIDATOR, - videoQuotaDaily: USER_VIDEO_QUOTA_DAILY_VALIDATOR, - byPassAutoBlock: null - }, defaultValues) - } - - formValidated () { - this.error = undefined - - const userCreate: UserCreate = this.form.value - - userCreate.adminFlags = this.buildAdminFlags(this.form.value) - - // A select in HTML is always mapped as a string, we convert it to number - userCreate.videoQuota = parseInt(this.form.value['videoQuota'], 10) - userCreate.videoQuotaDaily = parseInt(this.form.value['videoQuotaDaily'], 10) - - this.userService.addUser(userCreate) - .subscribe({ - next: () => { - this.notifier.success($localize`User ${userCreate.username} created.`) - this.router.navigate([ '/admin/users/list' ]) - }, - - error: err => { - this.error = err.message - } - }) - } - - isCreation () { - return true - } - - isPasswordOptional () { - return this.serverConfig.email.enabled - } - - getFormButtonTitle () { - return $localize`Create user` - } -} diff --git a/client/src/app/+admin/users/user-edit/user-edit.component.html b/client/src/app/+admin/users/user-edit/user-edit.component.html deleted file mode 100644 index 772ebf272..000000000 --- a/client/src/app/+admin/users/user-edit/user-edit.component.html +++ /dev/null @@ -1,237 +0,0 @@ - - - - - - -
-
- -
- -
-
- -
{{ error }}
- -
-
-
- - -
- -
- -
-
- - -
- {{ formErrors.username }} -
-
- -
- - -
- {{ formErrors.channelName }} -
-
- -
- - -
- {{ formErrors.email }} -
-
- -
- - - - - If you leave the password empty, an email will be sent to the user. - - - - - - -
- {{ formErrors.password }} -
-
- -
- -
- -
- -
- {{ formErrors.role }} -
-
- -
- - - - -
- Transcoding is enabled. The video quota only takes into account original video size.
- At most, this user could upload ~ {{ computeQuotaWithTranscoding() | bytes: 0 }}. -
- -
- {{ formErrors.videoQuota }} -
-
- -
- - - - -
- {{ formErrors.videoQuotaDaily }} -
-
- -
- - -
- -
-
- -
- -
- - -
- -
- -
- -
-
- - -
-
-
- -
- -
- -
-
- - -
- -
- - -
-
- -
-
diff --git a/client/src/app/+admin/users/user-edit/user-edit.component.scss b/client/src/app/+admin/users/user-edit/user-edit.component.scss deleted file mode 100644 index d7932154b..000000000 --- a/client/src/app/+admin/users/user-edit/user-edit.component.scss +++ /dev/null @@ -1,76 +0,0 @@ -@use 'sass:math'; -@use '_variables' as *; -@use '_mixins' as *; - -$form-base-input-width: 340px; - -label { - font-weight: $font-regular; - font-size: 100%; -} - -.account-title { - @include settings-big-title; - - &.account-title-danger { - color: lighten($color: #c54130, $amount: 10); - } -} - -input:not([type=submit]) { - @include peertube-input-text($form-base-input-width); - display: block; -} - -my-input-toggle-hidden { - @include responsive-width($form-base-input-width); - - display: block; -} - -.peertube-select-container { - @include peertube-select-container($form-base-input-width); -} - -my-select-custom-value { - @include responsive-width($form-base-input-width); - - display: block; -} - -input[type=submit], -button { - @include peertube-button; - @include orange-button; - - margin-top: 10px; -} - -.transcoding-information { - margin-top: 5px; - font-size: 11px; -} - -.danger-zone { - .reset-password-email { - margin-bottom: 30px; - - button { - @include peertube-button; - @include danger-button; - @include disable-outline; - - display: block; - margin-top: 0; - } - } -} - -.breadcrumb { - @include breadcrumb; -} - -.dashboard { - @include dashboard; - max-width: 900px; -} diff --git a/client/src/app/+admin/users/user-edit/user-edit.ts b/client/src/app/+admin/users/user-edit/user-edit.ts deleted file mode 100644 index af5e674a7..000000000 --- a/client/src/app/+admin/users/user-edit/user-edit.ts +++ /dev/null @@ -1,102 +0,0 @@ -import { Directive, OnInit } from '@angular/core' -import { ConfigService } from '@app/+admin/config/shared/config.service' -import { AuthService, ScreenService, ServerService, User } from '@app/core' -import { FormReactive } from '@app/shared/shared-forms' -import { USER_ROLE_LABELS } from '@shared/core-utils/users' -import { HTMLServerConfig, UserAdminFlag, UserRole, VideoResolution } from '@shared/models' -import { SelectOptionsItem } from '../../../../types/select-options-item.model' - -@Directive() -// eslint-disable-next-line @angular-eslint/directive-class-suffix -export abstract class UserEdit extends FormReactive implements OnInit { - videoQuotaOptions: SelectOptionsItem[] = [] - videoQuotaDailyOptions: SelectOptionsItem[] = [] - username: string - user: User - - roles: { value: string, label: string }[] = [] - - protected serverConfig: HTMLServerConfig - - protected abstract serverService: ServerService - protected abstract configService: ConfigService - protected abstract screenService: ScreenService - protected abstract auth: AuthService - abstract isCreation (): boolean - abstract getFormButtonTitle (): string - - ngOnInit (): void { - this.serverConfig = this.serverService.getHTMLConfig() - - this.buildRoles() - } - - get subscribersCount () { - const forAccount = this.user - ? this.user.account.followersCount - : 0 - const forChannels = this.user - ? this.user.videoChannels.map(c => c.followersCount).reduce((a, b) => a + b, 0) - : 0 - return forAccount + forChannels - } - - getAuthPlugins () { - return this.serverConfig.plugin.registeredIdAndPassAuths.map(p => p.npmName) - .concat(this.serverConfig.plugin.registeredExternalAuths.map(p => p.npmName)) - } - - isInBigView () { - return this.screenService.getWindowInnerWidth() > 1600 - } - - buildRoles () { - const authUser = this.auth.getUser() - - if (authUser.role === UserRole.ADMINISTRATOR) { - this.roles = Object.keys(USER_ROLE_LABELS) - .map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] })) - return - } - - this.roles = [ - { value: UserRole.USER.toString(), label: USER_ROLE_LABELS[UserRole.USER] } - ] - } - - isTranscodingInformationDisplayed () { - const formVideoQuota = parseInt(this.form.value['videoQuota'], 10) - - return this.serverConfig.transcoding.enabledResolutions.length !== 0 && - formVideoQuota > 0 - } - - computeQuotaWithTranscoding () { - const transcodingConfig = this.serverConfig.transcoding - - const resolutions = transcodingConfig.enabledResolutions - const higherResolution = VideoResolution.H_4K - let multiplier = 0 - - for (const resolution of resolutions) { - multiplier += resolution / higherResolution - } - - if (transcodingConfig.hls.enabled) multiplier *= 2 - - return multiplier * parseInt(this.form.value['videoQuota'], 10) - } - - resetPassword () { - return - } - - protected buildAdminFlags (formValue: any) { - return formValue.byPassAutoBlock ? UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE - } - - protected buildQuotaOptions () { - this.videoQuotaOptions = this.configService.videoQuotaOptions - this.videoQuotaDailyOptions = this.configService.videoQuotaDailyOptions - } -} diff --git a/client/src/app/+admin/users/user-edit/user-password.component.html b/client/src/app/+admin/users/user-edit/user-password.component.html deleted file mode 100644 index 1238d1839..000000000 --- a/client/src/app/+admin/users/user-edit/user-password.component.html +++ /dev/null @@ -1,21 +0,0 @@ -
-
- -
- -
- -
-
-
- {{ formErrors.password }} -
-
- - -
diff --git a/client/src/app/+admin/users/user-edit/user-password.component.scss b/client/src/app/+admin/users/user-edit/user-password.component.scss deleted file mode 100644 index acb680682..000000000 --- a/client/src/app/+admin/users/user-edit/user-password.component.scss +++ /dev/null @@ -1,23 +0,0 @@ -@use '_variables' as *; -@use '_mixins' as *; - -input:not([type=submit]):not([type=checkbox]) { - @include peertube-input-text(340px); - - display: block; - border-top-right-radius: 0; - border-bottom-right-radius: 0; - border-right: 0; -} - -input[type=submit] { - @include peertube-button; - @include danger-button; - @include disable-outline; - - margin-top: 10px; -} - -.input-group-append { - height: 30px; -} diff --git a/client/src/app/+admin/users/user-edit/user-password.component.ts b/client/src/app/+admin/users/user-edit/user-password.component.ts deleted file mode 100644 index 42bf20de1..000000000 --- a/client/src/app/+admin/users/user-edit/user-password.component.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { Component, Input, OnInit } from '@angular/core' -import { Notifier, UserService } from '@app/core' -import { USER_PASSWORD_VALIDATOR } from '@app/shared/form-validators/user-validators' -import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' -import { UserUpdate } from '@shared/models' - -@Component({ - selector: 'my-user-password', - templateUrl: './user-password.component.html', - styleUrls: [ './user-password.component.scss' ] -}) -export class UserPasswordComponent extends FormReactive implements OnInit { - error: string - username: string - showPassword = false - - @Input() userId: number - - constructor ( - protected formValidatorService: FormValidatorService, - private notifier: Notifier, - private userService: UserService - ) { - super() - } - - ngOnInit () { - this.buildForm({ - password: USER_PASSWORD_VALIDATOR - }) - } - - formValidated () { - this.error = undefined - - const userUpdate: UserUpdate = this.form.value - - this.userService.updateUser(this.userId, userUpdate) - .subscribe({ - next: () => this.notifier.success($localize`Password changed for user ${this.username}.`), - - error: err => { - this.error = err.message - } - }) - } - - togglePasswordVisibility () { - this.showPassword = !this.showPassword - } - - getFormButtonTitle () { - return $localize`Update user password` - } -} diff --git a/client/src/app/+admin/users/user-edit/user-update.component.ts b/client/src/app/+admin/users/user-edit/user-update.component.ts deleted file mode 100644 index 42599a17e..000000000 --- a/client/src/app/+admin/users/user-edit/user-update.component.ts +++ /dev/null @@ -1,139 +0,0 @@ -import { Subscription } from 'rxjs' -import { Component, OnDestroy, OnInit } from '@angular/core' -import { ActivatedRoute, Router } from '@angular/router' -import { ConfigService } from '@app/+admin/config/shared/config.service' -import { AuthService, Notifier, ScreenService, ServerService, User, UserService } from '@app/core' -import { - USER_EMAIL_VALIDATOR, - USER_ROLE_VALIDATOR, - USER_VIDEO_QUOTA_DAILY_VALIDATOR, - USER_VIDEO_QUOTA_VALIDATOR -} from '@app/shared/form-validators/user-validators' -import { FormValidatorService } from '@app/shared/shared-forms' -import { User as UserType, UserAdminFlag, UserRole, UserUpdate } from '@shared/models' -import { UserEdit } from './user-edit' - -@Component({ - selector: 'my-user-update', - templateUrl: './user-edit.component.html', - styleUrls: [ './user-edit.component.scss' ] -}) -export class UserUpdateComponent extends UserEdit implements OnInit, OnDestroy { - error: string - - private paramsSub: Subscription - - constructor ( - protected formValidatorService: FormValidatorService, - protected serverService: ServerService, - protected configService: ConfigService, - protected screenService: ScreenService, - protected auth: AuthService, - private route: ActivatedRoute, - private router: Router, - private notifier: Notifier, - private userService: UserService - ) { - super() - - this.buildQuotaOptions() - } - - ngOnInit () { - super.ngOnInit() - - const defaultValues = { - role: UserRole.USER.toString(), - videoQuota: '-1', - videoQuotaDaily: '-1' - } - - this.buildForm({ - email: USER_EMAIL_VALIDATOR, - role: USER_ROLE_VALIDATOR, - videoQuota: USER_VIDEO_QUOTA_VALIDATOR, - videoQuotaDaily: USER_VIDEO_QUOTA_DAILY_VALIDATOR, - byPassAutoBlock: null, - pluginAuth: null - }, defaultValues) - - this.paramsSub = this.route.params.subscribe(routeParams => { - const userId = routeParams['id'] - this.userService.getUser(userId, true) - .subscribe({ - next: user => this.onUserFetched(user), - - error: err => { - this.error = err.message - } - }) - }) - } - - ngOnDestroy () { - this.paramsSub.unsubscribe() - } - - formValidated () { - this.error = undefined - - const userUpdate: UserUpdate = this.form.value - userUpdate.adminFlags = this.buildAdminFlags(this.form.value) - - // A select in HTML is always mapped as a string, we convert it to number - userUpdate.videoQuota = parseInt(this.form.value['videoQuota'], 10) - userUpdate.videoQuotaDaily = parseInt(this.form.value['videoQuotaDaily'], 10) - - if (userUpdate.pluginAuth === 'null') userUpdate.pluginAuth = null - - this.userService.updateUser(this.user.id, userUpdate) - .subscribe({ - next: () => { - this.notifier.success($localize`User ${this.user.username} updated.`) - this.router.navigate([ '/admin/users/list' ]) - }, - - error: err => { - this.error = err.message - } - }) - } - - isCreation () { - return false - } - - isPasswordOptional () { - return false - } - - getFormButtonTitle () { - return $localize`Update user` - } - - resetPassword () { - this.userService.askResetPassword(this.user.email) - .subscribe({ - next: () => { - this.notifier.success($localize`An email asking for password reset has been sent to ${this.user.username}.`) - }, - - error: err => { - this.error = err.message - } - }) - } - - private onUserFetched (userJson: UserType) { - this.user = new User(userJson) - - this.form.patchValue({ - email: userJson.email, - role: userJson.role.toString(), - videoQuota: userJson.videoQuota, - videoQuotaDaily: userJson.videoQuotaDaily, - pluginAuth: userJson.pluginAuth, - byPassAutoBlock: userJson.adminFlags & UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST - }) - } -} -- cgit v1.2.3