PeerTube/client/src/app/+admin/overview/users/user-edit/user-edit.ts

96 lines
2.9 KiB
TypeScript
Raw Normal View History

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'
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
user: User
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
protected abstract serverService: ServerService
2018-09-26 14:46:54 +02:00
protected abstract configService: ConfigService
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
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
}
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) {
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
}
displayDangerZone () {
if (this.isCreation()) return false
if (!this.user) return false
if (this.user.pluginAuth) return false
if (this.auth.getUser().id === this.user.id) return false
return true
}
resetPassword () {
return
}
disableTwoFactorAuth () {
return
}
getUserVideoQuota () {
return this.form.value['videoQuota']
}
2019-04-15 10:49:46 +02:00
protected buildAdminFlags (formValue: any) {
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
}