2020-08-06 14:58:01 +02:00
|
|
|
import { Directive, OnInit } from '@angular/core'
|
2020-06-23 14:10:17 +02:00
|
|
|
import { ConfigService } from '@app/+admin/config/shared/config.service'
|
|
|
|
import { AuthService, ScreenService, ServerService, User } from '@app/core'
|
|
|
|
import { FormReactive } from '@app/shared/shared-forms'
|
2023-07-31 14:34:36 +02:00
|
|
|
import { peertubeTranslate, USER_ROLE_LABELS } from '@peertube/peertube-core-utils'
|
|
|
|
import { HTMLServerConfig, UserAdminFlag, UserRole } from '@peertube/peertube-models'
|
2021-10-27 09:36:37 +02:00
|
|
|
import { SelectOptionsItem } from '../../../../../types/select-options-item.model'
|
2017-09-05 21:29:39 +02:00
|
|
|
|
2020-06-26 08:37:26 +02:00
|
|
|
@Directive()
|
2021-08-17 14:42:53 +02:00
|
|
|
// eslint-disable-next-line @angular-eslint/directive-class-suffix
|
2019-12-18 15:31:54 +01:00
|
|
|
export abstract class UserEdit extends FormReactive implements OnInit {
|
2021-02-10 09:05:29 +01:00
|
|
|
videoQuotaOptions: SelectOptionsItem[] = []
|
|
|
|
videoQuotaDailyOptions: SelectOptionsItem[] = []
|
2018-11-15 09:24:56 +01:00
|
|
|
username: string
|
2020-03-27 15:19:03 +01:00
|
|
|
user: User
|
2017-10-27 16:55:03 +02:00
|
|
|
|
2020-03-18 10:22:36 +01:00
|
|
|
roles: { value: string, label: string }[] = []
|
|
|
|
|
2021-06-04 13:31:41 +02:00
|
|
|
protected serverConfig: HTMLServerConfig
|
2019-12-18 15:31:54 +01:00
|
|
|
|
2017-10-19 17:33:32 +02:00
|
|
|
protected abstract serverService: ServerService
|
2018-09-26 14:46:54 +02:00
|
|
|
protected abstract configService: ConfigService
|
2020-03-27 15:19:03 +01:00
|
|
|
protected abstract screenService: ScreenService
|
2019-07-30 09:59:19 +02:00
|
|
|
protected abstract auth: AuthService
|
2017-09-05 21:29:39 +02:00
|
|
|
abstract isCreation (): boolean
|
|
|
|
abstract getFormButtonTitle (): string
|
2017-10-19 17:33:32 +02:00
|
|
|
|
2023-04-17 09:21:02 +02:00
|
|
|
ngOnInit () {
|
2021-06-04 13:31:41 +02:00
|
|
|
this.serverConfig = this.serverService.getHTMLConfig()
|
2020-03-18 10:22:36 +01:00
|
|
|
|
|
|
|
this.buildRoles()
|
2019-12-18 15:31:54 +01:00
|
|
|
}
|
|
|
|
|
2020-03-27 15:19:03 +01:00
|
|
|
get subscribersCount () {
|
|
|
|
const forAccount = this.user
|
|
|
|
? this.user.account.followersCount
|
|
|
|
: 0
|
|
|
|
const forChannels = this.user
|
|
|
|
? this.user.videoChannels.map(c => c.followersCount).reduce((a, b) => a + b, 0)
|
|
|
|
: 0
|
|
|
|
return forAccount + forChannels
|
|
|
|
}
|
|
|
|
|
2021-02-01 15:39:13 +01:00
|
|
|
getAuthPlugins () {
|
|
|
|
return this.serverConfig.plugin.registeredIdAndPassAuths.map(p => p.npmName)
|
|
|
|
.concat(this.serverConfig.plugin.registeredExternalAuths.map(p => p.npmName))
|
|
|
|
}
|
|
|
|
|
2020-03-18 10:22:36 +01:00
|
|
|
buildRoles () {
|
2019-07-30 09:59:19 +02:00
|
|
|
const authUser = this.auth.getUser()
|
|
|
|
|
2023-04-17 09:21:02 +02:00
|
|
|
this.serverService.getServerLocale()
|
|
|
|
.subscribe(translations => {
|
|
|
|
if (authUser.role.id === UserRole.ADMINISTRATOR) {
|
2023-05-24 16:48:54 +02:00
|
|
|
this.roles = Object.entries(USER_ROLE_LABELS)
|
|
|
|
.map(([ key, value ]) => ({ value: key.toString(), label: peertubeTranslate(value, translations) }))
|
2023-04-17 09:21:02 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
this.roles = [
|
|
|
|
{ value: UserRole.USER.toString(), label: peertubeTranslate(USER_ROLE_LABELS[UserRole.USER], translations) }
|
|
|
|
]
|
|
|
|
})
|
2019-07-30 09:59:19 +02:00
|
|
|
}
|
|
|
|
|
2022-10-07 14:23:42 +02:00
|
|
|
displayDangerZone () {
|
|
|
|
if (this.isCreation()) return false
|
2022-10-10 15:39:27 +02:00
|
|
|
if (!this.user) return false
|
|
|
|
if (this.user.pluginAuth) return false
|
2022-10-07 14:23:42 +02:00
|
|
|
if (this.auth.getUser().id === this.user.id) return false
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2019-02-11 09:30:29 +01:00
|
|
|
resetPassword () {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-10-07 14:23:42 +02:00
|
|
|
disableTwoFactorAuth () {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-09-28 13:59:23 +02:00
|
|
|
getUserVideoQuota () {
|
|
|
|
return this.form.value['videoQuota']
|
|
|
|
}
|
|
|
|
|
2019-04-15 10:49:46 +02:00
|
|
|
protected buildAdminFlags (formValue: any) {
|
2020-06-09 16:07:10 +02:00
|
|
|
return formValue.byPassAutoBlock ? UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE
|
2019-04-15 10:49:46 +02:00
|
|
|
}
|
|
|
|
|
2018-09-26 14:46:54 +02:00
|
|
|
protected buildQuotaOptions () {
|
2021-02-10 09:05:29 +01:00
|
|
|
this.videoQuotaOptions = this.configService.videoQuotaOptions
|
|
|
|
this.videoQuotaDailyOptions = this.configService.videoQuotaDailyOptions
|
2018-09-26 14:46:54 +02:00
|
|
|
}
|
2017-09-05 21:29:39 +02:00
|
|
|
}
|