]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/users/user-edit/user-edit.ts
Fix typo for minimum age
[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 5import { USER_ROLE_LABELS } from '@shared/core-utils/users'
2989628b 6import { HTMLServerConfig, 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
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
76314386
RK
49 isInBigView () {
50 return this.screenService.getWindowInnerWidth() > 1600
51 }
52
a31bec51 53 buildRoles () {
a95a4cc8
C
54 const authUser = this.auth.getUser()
55
56 if (authUser.role === UserRole.ADMINISTRATOR) {
a31bec51 57 this.roles = Object.keys(USER_ROLE_LABELS)
a95a4cc8 58 .map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
a31bec51 59 return
a95a4cc8
C
60 }
61
a31bec51 62 this.roles = [
a95a4cc8
C
63 { value: UserRole.USER.toString(), label: USER_ROLE_LABELS[UserRole.USER] }
64 ]
65 }
66
6a84aafd
C
67 isTranscodingInformationDisplayed () {
68 const formVideoQuota = parseInt(this.form.value['videoQuota'], 10)
69
ba430d75 70 return this.serverConfig.transcoding.enabledResolutions.length !== 0 &&
6a84aafd
C
71 formVideoQuota > 0
72 }
73
74 computeQuotaWithTranscoding () {
ba430d75 75 const transcodingConfig = this.serverConfig.transcoding
09209296
C
76
77 const resolutions = transcodingConfig.enabledResolutions
ad3405d0 78 const higherResolution = VideoResolution.H_4K
6a84aafd
C
79 let multiplier = 0
80
81 for (const resolution of resolutions) {
82 multiplier += resolution / higherResolution
83 }
84
09209296
C
85 if (transcodingConfig.hls.enabled) multiplier *= 2
86
6a84aafd
C
87 return multiplier * parseInt(this.form.value['videoQuota'], 10)
88 }
3827c3b3 89
b426edd4
C
90 resetPassword () {
91 return
92 }
93
1eddc9a7 94 protected buildAdminFlags (formValue: any) {
3487330d 95 return formValue.byPassAutoBlock ? UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE
1eddc9a7
C
96 }
97
3827c3b3 98 protected buildQuotaOptions () {
21e493d4
C
99 this.videoQuotaOptions = this.configService.videoQuotaOptions
100 this.videoQuotaDailyOptions = this.configService.videoQuotaDailyOptions
3827c3b3 101 }
8094a898 102}