]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/overview/users/user-edit/user-edit.ts
Merge branch 'release/4.3.0' into develop
[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'
9c0cdc50 6import { HTMLServerConfig, UserAdminFlag, UserRole } 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
9e5cf66b 52 if (authUser.role.id === 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
2166c058
C
63 displayDangerZone () {
64 if (this.isCreation()) return false
8347f8a4
C
65 if (!this.user) return false
66 if (this.user.pluginAuth) return false
2166c058
C
67 if (this.auth.getUser().id === this.user.id) return false
68
69 return true
70 }
71
b426edd4
C
72 resetPassword () {
73 return
74 }
75
2166c058
C
76 disableTwoFactorAuth () {
77 return
78 }
79
f67ac646
C
80 getUserVideoQuota () {
81 return this.form.value['videoQuota']
82 }
83
1eddc9a7 84 protected buildAdminFlags (formValue: any) {
3487330d 85 return formValue.byPassAutoBlock ? UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE
1eddc9a7
C
86 }
87
3827c3b3 88 protected buildQuotaOptions () {
21e493d4
C
89 this.videoQuotaOptions = this.configService.videoQuotaOptions
90 this.videoQuotaDailyOptions = this.configService.videoQuotaDailyOptions
3827c3b3 91 }
8094a898 92}