]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/users/user-edit/user-edit.ts
Fix user role edition
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / users / user-edit / user-edit.ts
CommitLineData
a95a4cc8 1import { AuthService, ServerService } from '../../../core'
8094a898 2import { FormReactive } from '../../../shared'
ba430d75 3import { ServerConfig, USER_ROLE_LABELS, UserRole, VideoResolution } from '../../../../../../shared'
3827c3b3 4import { ConfigService } from '@app/+admin/config/shared/config.service'
1eddc9a7 5import { UserAdminFlag } from '@shared/models/users/user-flag.model'
ba430d75 6import { OnInit } from '@angular/core'
8094a898 7
ba430d75 8export abstract class UserEdit extends FormReactive implements OnInit {
3827c3b3
C
9 videoQuotaOptions: { value: string, label: string }[] = []
10 videoQuotaDailyOptions: { value: string, label: string }[] = []
2fbe7f19 11 username: string
b426edd4 12 userId: number
954605a8 13
a31bec51
C
14 roles: { value: string, label: string }[] = []
15
ba430d75
C
16 protected serverConfig: ServerConfig
17
6a84aafd 18 protected abstract serverService: ServerService
3827c3b3 19 protected abstract configService: ConfigService
a95a4cc8 20 protected abstract auth: AuthService
8094a898
C
21 abstract isCreation (): boolean
22 abstract getFormButtonTitle (): string
6a84aafd 23
ba430d75
C
24 ngOnInit (): void {
25 this.serverConfig = this.serverService.getTmpConfig()
26 this.serverService.getConfig()
27 .subscribe(config => this.serverConfig = config)
a31bec51
C
28
29 this.buildRoles()
ba430d75
C
30 }
31
a31bec51 32 buildRoles () {
a95a4cc8
C
33 const authUser = this.auth.getUser()
34
35 if (authUser.role === UserRole.ADMINISTRATOR) {
a31bec51 36 this.roles = Object.keys(USER_ROLE_LABELS)
a95a4cc8 37 .map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
a31bec51 38 return
a95a4cc8
C
39 }
40
a31bec51 41 this.roles = [
a95a4cc8
C
42 { value: UserRole.USER.toString(), label: USER_ROLE_LABELS[UserRole.USER] }
43 ]
44 }
45
6a84aafd
C
46 isTranscodingInformationDisplayed () {
47 const formVideoQuota = parseInt(this.form.value['videoQuota'], 10)
48
ba430d75 49 return this.serverConfig.transcoding.enabledResolutions.length !== 0 &&
6a84aafd
C
50 formVideoQuota > 0
51 }
52
53 computeQuotaWithTranscoding () {
ba430d75 54 const transcodingConfig = this.serverConfig.transcoding
09209296
C
55
56 const resolutions = transcodingConfig.enabledResolutions
ad3405d0 57 const higherResolution = VideoResolution.H_4K
6a84aafd
C
58 let multiplier = 0
59
60 for (const resolution of resolutions) {
61 multiplier += resolution / higherResolution
62 }
63
09209296
C
64 if (transcodingConfig.hls.enabled) multiplier *= 2
65
6a84aafd
C
66 return multiplier * parseInt(this.form.value['videoQuota'], 10)
67 }
3827c3b3 68
b426edd4
C
69 resetPassword () {
70 return
71 }
72
1eddc9a7
C
73 protected buildAdminFlags (formValue: any) {
74 return formValue.byPassAutoBlacklist ? UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE
75 }
76
3827c3b3
C
77 protected buildQuotaOptions () {
78 // These are used by a HTML select, so convert key into strings
79 this.videoQuotaOptions = this.configService
80 .videoQuotaOptions.map(q => ({ value: q.value.toString(), label: q.label }))
81
82 this.videoQuotaDailyOptions = this.configService
83 .videoQuotaDailyOptions.map(q => ({ value: q.value.toString(), label: q.label }))
84 }
8094a898 85}