]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/users/user-edit/user-edit.ts
Add ability to set a custom quota
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / users / user-edit / user-edit.ts
CommitLineData
bd45d503 1import { Directive, 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'
bd45d503
C
5import { USER_ROLE_LABELS } from '@shared/core-utils/users'
6import { ServerConfig, UserAdminFlag, UserRole, VideoResolution } from '@shared/models'
21e493d4 7import { SelectOptionsItem } from '../../../../types/select-options-item.model'
8094a898 8
583eb04b 9@Directive()
a02b93ce 10// tslint:disable-next-line: directive-class-suffix
ba430d75 11export abstract class UserEdit extends FormReactive implements OnInit {
21e493d4
C
12 videoQuotaOptions: SelectOptionsItem[] = []
13 videoQuotaDailyOptions: SelectOptionsItem[] = []
2fbe7f19 14 username: string
76314386 15 user: User
954605a8 16
a31bec51
C
17 roles: { value: string, label: string }[] = []
18
ba430d75
C
19 protected serverConfig: ServerConfig
20
6a84aafd 21 protected abstract serverService: ServerService
3827c3b3 22 protected abstract configService: ConfigService
76314386 23 protected abstract screenService: ScreenService
a95a4cc8 24 protected abstract auth: AuthService
8094a898
C
25 abstract isCreation (): boolean
26 abstract getFormButtonTitle (): string
6a84aafd 27
ba430d75
C
28 ngOnInit (): void {
29 this.serverConfig = this.serverService.getTmpConfig()
30 this.serverService.getConfig()
31 .subscribe(config => this.serverConfig = config)
a31bec51
C
32
33 this.buildRoles()
ba430d75
C
34 }
35
76314386
RK
36 get subscribersCount () {
37 const forAccount = this.user
38 ? this.user.account.followersCount
39 : 0
40 const forChannels = this.user
41 ? this.user.videoChannels.map(c => c.followersCount).reduce((a, b) => a + b, 0)
42 : 0
43 return forAccount + forChannels
44 }
45
6d989edc
C
46 getAuthPlugins () {
47 return this.serverConfig.plugin.registeredIdAndPassAuths.map(p => p.npmName)
48 .concat(this.serverConfig.plugin.registeredExternalAuths.map(p => p.npmName))
49 }
50
76314386
RK
51 isInBigView () {
52 return this.screenService.getWindowInnerWidth() > 1600
53 }
54
a31bec51 55 buildRoles () {
a95a4cc8
C
56 const authUser = this.auth.getUser()
57
58 if (authUser.role === UserRole.ADMINISTRATOR) {
a31bec51 59 this.roles = Object.keys(USER_ROLE_LABELS)
a95a4cc8 60 .map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
a31bec51 61 return
a95a4cc8
C
62 }
63
a31bec51 64 this.roles = [
a95a4cc8
C
65 { value: UserRole.USER.toString(), label: USER_ROLE_LABELS[UserRole.USER] }
66 ]
67 }
68
6a84aafd
C
69 isTranscodingInformationDisplayed () {
70 const formVideoQuota = parseInt(this.form.value['videoQuota'], 10)
71
ba430d75 72 return this.serverConfig.transcoding.enabledResolutions.length !== 0 &&
6a84aafd
C
73 formVideoQuota > 0
74 }
75
76 computeQuotaWithTranscoding () {
ba430d75 77 const transcodingConfig = this.serverConfig.transcoding
09209296
C
78
79 const resolutions = transcodingConfig.enabledResolutions
ad3405d0 80 const higherResolution = VideoResolution.H_4K
6a84aafd
C
81 let multiplier = 0
82
83 for (const resolution of resolutions) {
84 multiplier += resolution / higherResolution
85 }
86
09209296
C
87 if (transcodingConfig.hls.enabled) multiplier *= 2
88
6a84aafd
C
89 return multiplier * parseInt(this.form.value['videoQuota'], 10)
90 }
3827c3b3 91
b426edd4
C
92 resetPassword () {
93 return
94 }
95
1eddc9a7 96 protected buildAdminFlags (formValue: any) {
3487330d 97 return formValue.byPassAutoBlock ? UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE
1eddc9a7
C
98 }
99
3827c3b3 100 protected buildQuotaOptions () {
21e493d4
C
101 this.videoQuotaOptions = this.configService.videoQuotaOptions
102 this.videoQuotaDailyOptions = this.configService.videoQuotaDailyOptions
3827c3b3 103 }
8094a898 104}