1 import { Directive, OnInit } from '@angular/core'
2 import { ConfigService } from '@app/+admin/config/shared/config.service'
3 import { AuthService, ScreenService, ServerService, User } from '@app/core'
4 import { FormReactive } from '@app/shared/shared-forms'
5 import { USER_ROLE_LABELS } from '@shared/core-utils/users'
6 import { HTMLServerConfig, UserAdminFlag, UserRole } from '@shared/models'
7 import { SelectOptionsItem } from '../../../../../types/select-options-item.model'
10 // eslint-disable-next-line @angular-eslint/directive-class-suffix
11 export abstract class UserEdit extends FormReactive implements OnInit {
12 videoQuotaOptions: SelectOptionsItem[] = []
13 videoQuotaDailyOptions: SelectOptionsItem[] = []
17 roles: { value: string, label: string }[] = []
19 protected serverConfig: HTMLServerConfig
21 protected abstract serverService: ServerService
22 protected abstract configService: ConfigService
23 protected abstract screenService: ScreenService
24 protected abstract auth: AuthService
25 abstract isCreation (): boolean
26 abstract getFormButtonTitle (): string
29 this.serverConfig = this.serverService.getHTMLConfig()
34 get subscribersCount () {
35 const forAccount = this.user
36 ? this.user.account.followersCount
38 const forChannels = this.user
39 ? this.user.videoChannels.map(c => c.followersCount).reduce((a, b) => a + b, 0)
41 return forAccount + forChannels
45 return this.serverConfig.plugin.registeredIdAndPassAuths.map(p => p.npmName)
46 .concat(this.serverConfig.plugin.registeredExternalAuths.map(p => p.npmName))
50 const authUser = this.auth.getUser()
52 if (authUser.role.id === UserRole.ADMINISTRATOR) {
53 this.roles = Object.keys(USER_ROLE_LABELS)
54 .map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
59 { value: UserRole.USER.toString(), label: USER_ROLE_LABELS[UserRole.USER] }
63 displayDangerZone () {
64 if (this.isCreation()) return false
65 if (!this.user) return false
66 if (this.user.pluginAuth) return false
67 if (this.auth.getUser().id === this.user.id) return false
76 disableTwoFactorAuth () {
80 getUserVideoQuota () {
81 return this.form.value['videoQuota']
84 protected buildAdminFlags (formValue: any) {
85 return formValue.byPassAutoBlock ? UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE
88 protected buildQuotaOptions () {
89 this.videoQuotaOptions = this.configService.videoQuotaOptions
90 this.videoQuotaDailyOptions = this.configService.videoQuotaDailyOptions