]>
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' | |
bd45d503 | 5 | import { USER_ROLE_LABELS } from '@shared/core-utils/users' |
9c0cdc50 | 6 | import { HTMLServerConfig, UserAdminFlag, UserRole } from '@shared/models' |
00004f7f | 7 | import { SelectOptionsItem } from '../../../../../types/select-options-item.model' |
8094a898 | 8 | |
583eb04b | 9 | @Directive() |
9df52d66 | 10 | // eslint-disable-next-line @angular-eslint/directive-class-suffix |
ba430d75 | 11 | export 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 | ||
2166c058 C |
63 | displayDangerZone () { |
64 | if (this.isCreation()) return false | |
65 | if (this.user?.pluginAuth) return false | |
66 | if (this.auth.getUser().id === this.user.id) return false | |
67 | ||
68 | return true | |
69 | } | |
70 | ||
b426edd4 C |
71 | resetPassword () { |
72 | return | |
73 | } | |
74 | ||
2166c058 C |
75 | disableTwoFactorAuth () { |
76 | return | |
77 | } | |
78 | ||
f67ac646 C |
79 | getUserVideoQuota () { |
80 | return this.form.value['videoQuota'] | |
81 | } | |
82 | ||
1eddc9a7 | 83 | protected buildAdminFlags (formValue: any) { |
3487330d | 84 | return formValue.byPassAutoBlock ? UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE |
1eddc9a7 C |
85 | } |
86 | ||
3827c3b3 | 87 | protected buildQuotaOptions () { |
21e493d4 C |
88 | this.videoQuotaOptions = this.configService.videoQuotaOptions |
89 | this.videoQuotaDailyOptions = this.configService.videoQuotaDailyOptions | |
3827c3b3 | 90 | } |
8094a898 | 91 | } |