Merge branch 'release/v1.3.0' into develop
[oweals/peertube.git] / client / src / app / +admin / users / user-edit / user-edit.ts
1 import { ServerService } from '../../../core'
2 import { FormReactive } from '../../../shared'
3 import { USER_ROLE_LABELS, VideoResolution } from '../../../../../../shared'
4 import { ConfigService } from '@app/+admin/config/shared/config.service'
5 import { UserAdminFlag } from '@shared/models/users/user-flag.model'
6
7 export abstract class UserEdit extends FormReactive {
8   videoQuotaOptions: { value: string, label: string }[] = []
9   videoQuotaDailyOptions: { value: string, label: string }[] = []
10   roles = Object.keys(USER_ROLE_LABELS)
11                 .map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
12   username: string
13   userId: number
14
15   protected abstract serverService: ServerService
16   protected abstract configService: ConfigService
17   abstract isCreation (): boolean
18   abstract getFormButtonTitle (): string
19
20   isTranscodingInformationDisplayed () {
21     const formVideoQuota = parseInt(this.form.value['videoQuota'], 10)
22
23     return this.serverService.getConfig().transcoding.enabledResolutions.length !== 0 &&
24            formVideoQuota > 0
25   }
26
27   computeQuotaWithTranscoding () {
28     const transcodingConfig = this.serverService.getConfig().transcoding
29
30     const resolutions = transcodingConfig.enabledResolutions
31     const higherResolution = VideoResolution.H_4K
32     let multiplier = 0
33
34     for (const resolution of resolutions) {
35       multiplier += resolution / higherResolution
36     }
37
38     if (transcodingConfig.hls.enabled) multiplier *= 2
39
40     return multiplier * parseInt(this.form.value['videoQuota'], 10)
41   }
42
43   resetPassword () {
44     return
45   }
46
47   protected buildAdminFlags (formValue: any) {
48     return formValue.byPassAutoBlacklist ? UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE
49   }
50
51   protected buildQuotaOptions () {
52     // These are used by a HTML select, so convert key into strings
53     this.videoQuotaOptions = this.configService
54                                  .videoQuotaOptions.map(q => ({ value: q.value.toString(), label: q.label }))
55
56     this.videoQuotaDailyOptions = this.configService
57                                       .videoQuotaDailyOptions.map(q => ({ value: q.value.toString(), label: q.label }))
58   }
59 }