]>
Commit | Line | Data |
---|---|---|
bd45d503 | 1 | import { Directive, OnInit } from '@angular/core' |
67ed6552 C |
2 | import { ConfigService } from '@app/+admin/config/shared/config.service' |
3 | import { AuthService, ScreenService, ServerService, User } from '@app/core' | |
4 | import { FormReactive } from '@app/shared/shared-forms' | |
208c97e1 | 5 | import { peertubeTranslate } from '@shared/core-utils' |
bd45d503 | 6 | import { USER_ROLE_LABELS } from '@shared/core-utils/users' |
9c0cdc50 | 7 | import { HTMLServerConfig, UserAdminFlag, UserRole } from '@shared/models' |
00004f7f | 8 | import { SelectOptionsItem } from '../../../../../types/select-options-item.model' |
8094a898 | 9 | |
583eb04b | 10 | @Directive() |
9df52d66 | 11 | // eslint-disable-next-line @angular-eslint/directive-class-suffix |
ba430d75 | 12 | export abstract class UserEdit extends FormReactive implements OnInit { |
21e493d4 C |
13 | videoQuotaOptions: SelectOptionsItem[] = [] |
14 | videoQuotaDailyOptions: SelectOptionsItem[] = [] | |
2fbe7f19 | 15 | username: string |
76314386 | 16 | user: User |
954605a8 | 17 | |
a31bec51 C |
18 | roles: { value: string, label: string }[] = [] |
19 | ||
2989628b | 20 | protected serverConfig: HTMLServerConfig |
ba430d75 | 21 | |
6a84aafd | 22 | protected abstract serverService: ServerService |
3827c3b3 | 23 | protected abstract configService: ConfigService |
76314386 | 24 | protected abstract screenService: ScreenService |
a95a4cc8 | 25 | protected abstract auth: AuthService |
8094a898 C |
26 | abstract isCreation (): boolean |
27 | abstract getFormButtonTitle (): string | |
6a84aafd | 28 | |
208c97e1 | 29 | ngOnInit () { |
2989628b | 30 | this.serverConfig = this.serverService.getHTMLConfig() |
a31bec51 C |
31 | |
32 | this.buildRoles() | |
ba430d75 C |
33 | } |
34 | ||
76314386 RK |
35 | get subscribersCount () { |
36 | const forAccount = this.user | |
37 | ? this.user.account.followersCount | |
38 | : 0 | |
39 | const forChannels = this.user | |
40 | ? this.user.videoChannels.map(c => c.followersCount).reduce((a, b) => a + b, 0) | |
41 | : 0 | |
42 | return forAccount + forChannels | |
43 | } | |
44 | ||
6d989edc C |
45 | getAuthPlugins () { |
46 | return this.serverConfig.plugin.registeredIdAndPassAuths.map(p => p.npmName) | |
47 | .concat(this.serverConfig.plugin.registeredExternalAuths.map(p => p.npmName)) | |
48 | } | |
49 | ||
a31bec51 | 50 | buildRoles () { |
a95a4cc8 C |
51 | const authUser = this.auth.getUser() |
52 | ||
208c97e1 C |
53 | this.serverService.getServerLocale() |
54 | .subscribe(translations => { | |
55 | if (authUser.role.id === UserRole.ADMINISTRATOR) { | |
54909304 C |
56 | this.roles = Object.entries(USER_ROLE_LABELS) |
57 | .map(([ key, value ]) => ({ value: key.toString(), label: peertubeTranslate(value, translations) })) | |
208c97e1 C |
58 | return |
59 | } | |
60 | ||
61 | this.roles = [ | |
62 | { value: UserRole.USER.toString(), label: peertubeTranslate(USER_ROLE_LABELS[UserRole.USER], translations) } | |
63 | ] | |
64 | }) | |
a95a4cc8 C |
65 | } |
66 | ||
2166c058 C |
67 | displayDangerZone () { |
68 | if (this.isCreation()) return false | |
8347f8a4 C |
69 | if (!this.user) return false |
70 | if (this.user.pluginAuth) return false | |
2166c058 C |
71 | if (this.auth.getUser().id === this.user.id) return false |
72 | ||
73 | return true | |
74 | } | |
75 | ||
b426edd4 C |
76 | resetPassword () { |
77 | return | |
78 | } | |
79 | ||
2166c058 C |
80 | disableTwoFactorAuth () { |
81 | return | |
82 | } | |
83 | ||
f67ac646 C |
84 | getUserVideoQuota () { |
85 | return this.form.value['videoQuota'] | |
86 | } | |
87 | ||
1eddc9a7 | 88 | protected buildAdminFlags (formValue: any) { |
3487330d | 89 | return formValue.byPassAutoBlock ? UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE |
1eddc9a7 C |
90 | } |
91 | ||
3827c3b3 | 92 | protected buildQuotaOptions () { |
21e493d4 C |
93 | this.videoQuotaOptions = this.configService.videoQuotaOptions |
94 | this.videoQuotaDailyOptions = this.configService.videoQuotaDailyOptions | |
3827c3b3 | 95 | } |
8094a898 | 96 | } |