]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/overview/users/user-edit/user-edit.ts
Increase global font size
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / overview / 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 5import { USER_ROLE_LABELS } from '@shared/core-utils/users'
2989628b 6import { HTMLServerConfig, UserAdminFlag, UserRole, VideoResolution } from '@shared/models'
00004f7f 7import { SelectOptionsItem } from '../../../../../types/select-options-item.model'
8094a898 8
583eb04b 9@Directive()
9df52d66 10// eslint-disable-next-line @angular-eslint/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
2989628b 19 protected serverConfig: HTMLServerConfig
ba430d75 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 28 ngOnInit (): void {
2989628b 29 this.serverConfig = this.serverService.getHTMLConfig()
a31bec51
C
30
31 this.buildRoles()
ba430d75
C
32 }
33
76314386
RK
34 get subscribersCount () {
35 const forAccount = this.user
36 ? this.user.account.followersCount
37 : 0
38 const forChannels = this.user
39 ? this.user.videoChannels.map(c => c.followersCount).reduce((a, b) => a + b, 0)
40 : 0
41 return forAccount + forChannels
42 }
43
6d989edc
C
44 getAuthPlugins () {
45 return this.serverConfig.plugin.registeredIdAndPassAuths.map(p => p.npmName)
46 .concat(this.serverConfig.plugin.registeredExternalAuths.map(p => p.npmName))
47 }
48
a31bec51 49 buildRoles () {
a95a4cc8
C
50 const authUser = this.auth.getUser()
51
52 if (authUser.role === UserRole.ADMINISTRATOR) {
a31bec51 53 this.roles = Object.keys(USER_ROLE_LABELS)
a95a4cc8 54 .map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
a31bec51 55 return
a95a4cc8
C
56 }
57
a31bec51 58 this.roles = [
a95a4cc8
C
59 { value: UserRole.USER.toString(), label: USER_ROLE_LABELS[UserRole.USER] }
60 ]
61 }
62
6a84aafd
C
63 isTranscodingInformationDisplayed () {
64 const formVideoQuota = parseInt(this.form.value['videoQuota'], 10)
65
ba430d75 66 return this.serverConfig.transcoding.enabledResolutions.length !== 0 &&
6a84aafd
C
67 formVideoQuota > 0
68 }
69
70 computeQuotaWithTranscoding () {
ba430d75 71 const transcodingConfig = this.serverConfig.transcoding
09209296
C
72
73 const resolutions = transcodingConfig.enabledResolutions
ad3405d0 74 const higherResolution = VideoResolution.H_4K
6a84aafd
C
75 let multiplier = 0
76
77 for (const resolution of resolutions) {
78 multiplier += resolution / higherResolution
79 }
80
09209296
C
81 if (transcodingConfig.hls.enabled) multiplier *= 2
82
6a84aafd
C
83 return multiplier * parseInt(this.form.value['videoQuota'], 10)
84 }
3827c3b3 85
b426edd4
C
86 resetPassword () {
87 return
88 }
89
1eddc9a7 90 protected buildAdminFlags (formValue: any) {
3487330d 91 return formValue.byPassAutoBlock ? UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE
1eddc9a7
C
92 }
93
3827c3b3 94 protected buildQuotaOptions () {
21e493d4
C
95 this.videoQuotaOptions = this.configService.videoQuotaOptions
96 this.videoQuotaDailyOptions = this.configService.videoQuotaDailyOptions
3827c3b3 97 }
8094a898 98}