Support roles with rights and add moderator role
[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
5 export abstract class UserEdit extends FormReactive {
6   videoQuotaOptions = [
7     { value: -1, label: 'Unlimited' },
8     { value: 0, label: '0'},
9     { value: 100 * 1024 * 1024, label: '100MB' },
10     { value: 500 * 1024 * 1024, label: '500MB' },
11     { value: 1024 * 1024 * 1024, label: '1GB' },
12     { value: 5 * 1024 * 1024 * 1024, label: '5GB' },
13     { value: 20 * 1024 * 1024 * 1024, label: '20GB' },
14     { value: 50 * 1024 * 1024 * 1024, label: '50GB' }
15   ]
16
17   roles = Object.keys(USER_ROLE_LABELS).map(key => ({ value: key, label: USER_ROLE_LABELS[key] }))
18
19   protected abstract serverService: ServerService
20   abstract isCreation (): boolean
21   abstract getFormButtonTitle (): string
22
23   isTranscodingInformationDisplayed () {
24     const formVideoQuota = parseInt(this.form.value['videoQuota'], 10)
25
26     return this.serverService.getConfig().transcoding.enabledResolutions.length !== 0 &&
27            formVideoQuota > 0
28   }
29
30   computeQuotaWithTranscoding () {
31     const resolutions = this.serverService.getConfig().transcoding.enabledResolutions
32     const higherResolution = VideoResolution.H_1080P
33     let multiplier = 0
34
35     for (const resolution of resolutions) {
36       multiplier += resolution / higherResolution
37     }
38
39     return multiplier * parseInt(this.form.value['videoQuota'], 10)
40   }
41 }