1 import { AuthService, ServerService } from '../../../core'
2 import { FormReactive } from '../../../shared'
3 import { USER_ROLE_LABELS, UserRole, VideoResolution } from '../../../../../../shared'
4 import { ConfigService } from '@app/+admin/config/shared/config.service'
5 import { UserAdminFlag } from '@shared/models/users/user-flag.model'
7 export abstract class UserEdit extends FormReactive {
8 videoQuotaOptions: { value: string, label: string }[] = []
9 videoQuotaDailyOptions: { value: string, label: string }[] = []
13 protected abstract serverService: ServerService
14 protected abstract configService: ConfigService
15 protected abstract auth: AuthService
16 abstract isCreation (): boolean
17 abstract getFormButtonTitle (): string
20 const authUser = this.auth.getUser()
22 if (authUser.role === UserRole.ADMINISTRATOR) {
23 return Object.keys(USER_ROLE_LABELS)
24 .map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
28 { value: UserRole.USER.toString(), label: USER_ROLE_LABELS[UserRole.USER] }
32 isTranscodingInformationDisplayed () {
33 const formVideoQuota = parseInt(this.form.value['videoQuota'], 10)
35 return this.serverService.getConfig().transcoding.enabledResolutions.length !== 0 &&
39 computeQuotaWithTranscoding () {
40 const transcodingConfig = this.serverService.getConfig().transcoding
42 const resolutions = transcodingConfig.enabledResolutions
43 const higherResolution = VideoResolution.H_4K
46 for (const resolution of resolutions) {
47 multiplier += resolution / higherResolution
50 if (transcodingConfig.hls.enabled) multiplier *= 2
52 return multiplier * parseInt(this.form.value['videoQuota'], 10)
59 protected buildAdminFlags (formValue: any) {
60 return formValue.byPassAutoBlacklist ? UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE
63 protected buildQuotaOptions () {
64 // These are used by a HTML select, so convert key into strings
65 this.videoQuotaOptions = this.configService
66 .videoQuotaOptions.map(q => ({ value: q.value.toString(), label: q.label }))
68 this.videoQuotaDailyOptions = this.configService
69 .videoQuotaDailyOptions.map(q => ({ value: q.value.toString(), label: q.label }))