]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/users/user-edit/user-edit.ts
deal with refresh token in embed
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / users / user-edit / user-edit.ts
CommitLineData
ba430d75 1import { OnInit } from '@angular/core'
67ed6552
C
2import { ConfigService } from '@app/+admin/config/shared/config.service'
3import { AuthService, ScreenService, ServerService, User } from '@app/core'
4import { FormReactive } from '@app/shared/shared-forms'
5import { ServerConfig, USER_ROLE_LABELS, UserAdminFlag, UserRole, VideoResolution } from '@shared/models'
8094a898 6
ba430d75 7export abstract class UserEdit extends FormReactive implements OnInit {
2bc9bd08
RK
8 videoQuotaOptions: { value: string, label: string, disabled?: boolean }[] = []
9 videoQuotaDailyOptions: { value: string, label: string, disabled?: boolean }[] = []
2fbe7f19 10 username: string
76314386 11 user: User
954605a8 12
a31bec51
C
13 roles: { value: string, label: string }[] = []
14
ba430d75
C
15 protected serverConfig: ServerConfig
16
6a84aafd 17 protected abstract serverService: ServerService
3827c3b3 18 protected abstract configService: ConfigService
76314386 19 protected abstract screenService: ScreenService
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
76314386
RK
32 get subscribersCount () {
33 const forAccount = this.user
34 ? this.user.account.followersCount
35 : 0
36 const forChannels = this.user
37 ? this.user.videoChannels.map(c => c.followersCount).reduce((a, b) => a + b, 0)
38 : 0
39 return forAccount + forChannels
40 }
41
42 isInBigView () {
43 return this.screenService.getWindowInnerWidth() > 1600
44 }
45
a31bec51 46 buildRoles () {
a95a4cc8
C
47 const authUser = this.auth.getUser()
48
49 if (authUser.role === UserRole.ADMINISTRATOR) {
a31bec51 50 this.roles = Object.keys(USER_ROLE_LABELS)
a95a4cc8 51 .map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
a31bec51 52 return
a95a4cc8
C
53 }
54
a31bec51 55 this.roles = [
a95a4cc8
C
56 { value: UserRole.USER.toString(), label: USER_ROLE_LABELS[UserRole.USER] }
57 ]
58 }
59
6a84aafd
C
60 isTranscodingInformationDisplayed () {
61 const formVideoQuota = parseInt(this.form.value['videoQuota'], 10)
62
ba430d75 63 return this.serverConfig.transcoding.enabledResolutions.length !== 0 &&
6a84aafd
C
64 formVideoQuota > 0
65 }
66
67 computeQuotaWithTranscoding () {
ba430d75 68 const transcodingConfig = this.serverConfig.transcoding
09209296
C
69
70 const resolutions = transcodingConfig.enabledResolutions
ad3405d0 71 const higherResolution = VideoResolution.H_4K
6a84aafd
C
72 let multiplier = 0
73
74 for (const resolution of resolutions) {
75 multiplier += resolution / higherResolution
76 }
77
09209296
C
78 if (transcodingConfig.hls.enabled) multiplier *= 2
79
6a84aafd
C
80 return multiplier * parseInt(this.form.value['videoQuota'], 10)
81 }
3827c3b3 82
b426edd4
C
83 resetPassword () {
84 return
85 }
86
1eddc9a7 87 protected buildAdminFlags (formValue: any) {
3487330d 88 return formValue.byPassAutoBlock ? UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE
1eddc9a7
C
89 }
90
3827c3b3
C
91 protected buildQuotaOptions () {
92 // These are used by a HTML select, so convert key into strings
93 this.videoQuotaOptions = this.configService
8e4aff44 94 .videoQuotaOptions.map(q => ({
471ee394
RK
95 value: q.value?.toString(),
96 label: q.label,
97 disabled: q.disabled
8e4aff44 98 }))
3827c3b3
C
99
100 this.videoQuotaDailyOptions = this.configService
471ee394
RK
101 .videoQuotaDailyOptions.map(q => ({
102 value: q.value?.toString(),
103 label: q.label,
104 disabled: q.disabled
105 }))
2bc9bd08
RK
106
107 console.log(
108 this.videoQuotaOptions,
109 this.videoQuotaDailyOptions
110 )
3827c3b3 111 }
8094a898 112}