2020-06-23 14:10:17 +02:00
|
|
|
import { Subscription } from 'rxjs'
|
2019-02-11 09:30:29 +01:00
|
|
|
import { Component, OnDestroy, OnInit } from '@angular/core'
|
2024-03-04 10:01:52 +01:00
|
|
|
import { ActivatedRoute, Router, RouterLink } from '@angular/router'
|
2018-09-26 14:46:54 +02:00
|
|
|
import { ConfigService } from '@app/+admin/config/shared/config.service'
|
2020-06-23 14:10:17 +02:00
|
|
|
import { AuthService, Notifier, ScreenService, ServerService, User, UserService } from '@app/core'
|
2020-08-17 11:47:04 +02:00
|
|
|
import {
|
|
|
|
USER_EMAIL_VALIDATOR,
|
|
|
|
USER_ROLE_VALIDATOR,
|
|
|
|
USER_VIDEO_QUOTA_DAILY_VALIDATOR,
|
|
|
|
USER_VIDEO_QUOTA_VALIDATOR
|
|
|
|
} from '@app/shared/form-validators/user-validators'
|
2024-03-05 09:30:12 +01:00
|
|
|
import { FormReactiveService } from '@app/shared/shared-forms/form-reactive.service'
|
2023-07-31 14:34:36 +02:00
|
|
|
import { User as UserType, UserAdminFlag, UserRole, UserUpdate } from '@peertube/peertube-models'
|
2020-06-23 14:10:17 +02:00
|
|
|
import { UserEdit } from './user-edit'
|
2024-03-04 10:01:52 +01:00
|
|
|
import { BytesPipe } from '../../../../shared/shared-main/angular/bytes.pipe'
|
|
|
|
import { UserPasswordComponent } from './user-password.component'
|
|
|
|
import { PeertubeCheckboxComponent } from '../../../../shared/shared-forms/peertube-checkbox.component'
|
|
|
|
import { UserRealQuotaInfoComponent } from '../../../shared/user-real-quota-info.component'
|
|
|
|
import { SelectCustomValueComponent } from '../../../../shared/shared-forms/select/select-custom-value.component'
|
|
|
|
import { InputTextComponent } from '../../../../shared/shared-forms/input-text.component'
|
|
|
|
import { PeerTubeTemplateDirective } from '../../../../shared/shared-main/angular/peertube-template.directive'
|
|
|
|
import { HelpComponent } from '../../../../shared/shared-main/misc/help.component'
|
|
|
|
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
|
|
|
|
import { ActorAvatarEditComponent } from '../../../../shared/shared-actor-image-edit/actor-avatar-edit.component'
|
|
|
|
import { NgIf, NgTemplateOutlet, NgClass, NgFor } from '@angular/common'
|
2024-03-05 09:30:12 +01:00
|
|
|
import { UserAdminService } from '@app/shared/shared-users/user-admin.service'
|
|
|
|
import { TwoFactorService } from '@app/shared/shared-users/two-factor.service'
|
2017-09-05 21:29:39 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'my-user-update',
|
2017-10-19 17:33:32 +02:00
|
|
|
templateUrl: './user-edit.component.html',
|
2024-03-04 10:01:52 +01:00
|
|
|
styleUrls: [ './user-edit.component.scss' ],
|
|
|
|
standalone: true,
|
|
|
|
imports: [
|
|
|
|
RouterLink,
|
|
|
|
NgIf,
|
|
|
|
NgTemplateOutlet,
|
|
|
|
ActorAvatarEditComponent,
|
|
|
|
FormsModule,
|
|
|
|
ReactiveFormsModule,
|
|
|
|
NgClass,
|
|
|
|
HelpComponent,
|
|
|
|
PeerTubeTemplateDirective,
|
|
|
|
InputTextComponent,
|
|
|
|
NgFor,
|
|
|
|
SelectCustomValueComponent,
|
|
|
|
UserRealQuotaInfoComponent,
|
|
|
|
PeertubeCheckboxComponent,
|
|
|
|
UserPasswordComponent,
|
|
|
|
BytesPipe
|
|
|
|
]
|
2017-09-05 21:29:39 +02:00
|
|
|
})
|
|
|
|
export class UserUpdateComponent extends UserEdit implements OnInit, OnDestroy {
|
|
|
|
error: string
|
|
|
|
|
|
|
|
private paramsSub: Subscription
|
|
|
|
|
|
|
|
constructor (
|
2022-10-07 15:26:53 +02:00
|
|
|
protected formReactiveService: FormReactiveService,
|
2017-10-19 17:33:32 +02:00
|
|
|
protected serverService: ServerService,
|
2018-09-26 14:46:54 +02:00
|
|
|
protected configService: ConfigService,
|
2020-03-27 15:19:03 +01:00
|
|
|
protected screenService: ScreenService,
|
2019-07-30 09:59:19 +02:00
|
|
|
protected auth: AuthService,
|
2017-09-05 21:29:39 +02:00
|
|
|
private route: ActivatedRoute,
|
|
|
|
private router: Router,
|
2018-12-19 16:04:34 +01:00
|
|
|
private notifier: Notifier,
|
2022-01-21 11:03:25 +01:00
|
|
|
private userService: UserService,
|
2022-10-07 14:23:42 +02:00
|
|
|
private twoFactorService: TwoFactorService,
|
2022-01-21 11:03:25 +01:00
|
|
|
private userAdminService: UserAdminService
|
2021-08-17 14:42:53 +02:00
|
|
|
) {
|
2017-09-05 21:29:39 +02:00
|
|
|
super()
|
2018-09-26 14:46:54 +02:00
|
|
|
|
|
|
|
this.buildQuotaOptions()
|
2017-09-05 21:29:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit () {
|
2019-12-18 15:31:54 +01:00
|
|
|
super.ngOnInit()
|
|
|
|
|
2020-03-27 15:19:03 +01:00
|
|
|
const defaultValues = {
|
|
|
|
role: UserRole.USER.toString(),
|
|
|
|
videoQuota: '-1',
|
|
|
|
videoQuotaDaily: '-1'
|
|
|
|
}
|
|
|
|
|
2018-06-05 10:58:45 +02:00
|
|
|
this.buildForm({
|
2020-08-17 11:47:04 +02:00
|
|
|
email: USER_EMAIL_VALIDATOR,
|
|
|
|
role: USER_ROLE_VALIDATOR,
|
|
|
|
videoQuota: USER_VIDEO_QUOTA_VALIDATOR,
|
|
|
|
videoQuotaDaily: USER_VIDEO_QUOTA_DAILY_VALIDATOR,
|
2021-02-01 15:39:13 +01:00
|
|
|
byPassAutoBlock: null,
|
|
|
|
pluginAuth: null
|
2018-06-05 10:58:45 +02:00
|
|
|
}, defaultValues)
|
2017-09-05 21:29:39 +02:00
|
|
|
|
|
|
|
this.paramsSub = this.route.params.subscribe(routeParams => {
|
|
|
|
const userId = routeParams['id']
|
2021-08-17 11:27:47 +02:00
|
|
|
this.userService.getUser(userId, true)
|
|
|
|
.subscribe({
|
|
|
|
next: user => this.onUserFetched(user),
|
2017-09-05 21:29:39 +02:00
|
|
|
|
2021-08-17 14:42:53 +02:00
|
|
|
error: err => {
|
|
|
|
this.error = err.message
|
|
|
|
}
|
2021-08-17 11:27:47 +02:00
|
|
|
})
|
2017-09-05 21:29:39 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy () {
|
|
|
|
this.paramsSub.unsubscribe()
|
|
|
|
}
|
|
|
|
|
|
|
|
formValidated () {
|
|
|
|
this.error = undefined
|
|
|
|
|
|
|
|
const userUpdate: UserUpdate = this.form.value
|
2019-04-15 10:49:46 +02:00
|
|
|
userUpdate.adminFlags = this.buildAdminFlags(this.form.value)
|
2017-09-05 21:29:39 +02:00
|
|
|
|
|
|
|
// A select in HTML is always mapped as a string, we convert it to number
|
|
|
|
userUpdate.videoQuota = parseInt(this.form.value['videoQuota'], 10)
|
2018-08-28 09:01:35 +02:00
|
|
|
userUpdate.videoQuotaDaily = parseInt(this.form.value['videoQuotaDaily'], 10)
|
2017-09-05 21:29:39 +02:00
|
|
|
|
2021-05-25 13:49:52 +02:00
|
|
|
if (userUpdate.pluginAuth === 'null') userUpdate.pluginAuth = null
|
|
|
|
|
2022-01-21 11:03:25 +01:00
|
|
|
this.userAdminService.updateUser(this.user.id, userUpdate)
|
2021-08-17 11:27:47 +02:00
|
|
|
.subscribe({
|
|
|
|
next: () => {
|
|
|
|
this.notifier.success($localize`User ${this.user.username} updated.`)
|
|
|
|
this.router.navigate([ '/admin/users/list' ])
|
|
|
|
},
|
2017-09-05 21:29:39 +02:00
|
|
|
|
2021-08-17 14:42:53 +02:00
|
|
|
error: err => {
|
|
|
|
this.error = err.message
|
|
|
|
}
|
2021-08-17 11:27:47 +02:00
|
|
|
})
|
2017-09-05 21:29:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
isCreation () {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-02-17 10:16:52 +01:00
|
|
|
isPasswordOptional () {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-09-05 21:29:39 +02:00
|
|
|
getFormButtonTitle () {
|
2020-08-12 10:40:04 +02:00
|
|
|
return $localize`Update user`
|
2017-09-05 21:29:39 +02:00
|
|
|
}
|
|
|
|
|
2018-10-06 13:54:00 +02:00
|
|
|
resetPassword () {
|
2021-08-17 11:27:47 +02:00
|
|
|
this.userService.askResetPassword(this.user.email)
|
|
|
|
.subscribe({
|
|
|
|
next: () => {
|
|
|
|
this.notifier.success($localize`An email asking for password reset has been sent to ${this.user.username}.`)
|
|
|
|
},
|
|
|
|
|
2022-10-07 14:23:42 +02:00
|
|
|
error: err => this.notifier.error(err.message)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
disableTwoFactorAuth () {
|
|
|
|
this.twoFactorService.disableTwoFactor({ userId: this.user.id })
|
|
|
|
.subscribe({
|
|
|
|
next: () => {
|
|
|
|
this.user.twoFactorEnabled = false
|
|
|
|
|
|
|
|
this.notifier.success($localize`Two factor authentication of ${this.user.username} disabled.`)
|
|
|
|
},
|
|
|
|
|
|
|
|
error: err => this.notifier.error(err.message)
|
2021-08-17 11:27:47 +02:00
|
|
|
})
|
2022-10-07 14:23:42 +02:00
|
|
|
|
2018-10-06 13:54:00 +02:00
|
|
|
}
|
|
|
|
|
2020-03-27 15:19:03 +01:00
|
|
|
private onUserFetched (userJson: UserType) {
|
|
|
|
this.user = new User(userJson)
|
2017-09-05 21:29:39 +02:00
|
|
|
|
|
|
|
this.form.patchValue({
|
|
|
|
email: userJson.email,
|
2022-10-28 16:15:04 +02:00
|
|
|
role: userJson.role.id.toString(),
|
2018-08-28 09:01:35 +02:00
|
|
|
videoQuota: userJson.videoQuota,
|
2019-04-15 10:49:46 +02:00
|
|
|
videoQuotaDaily: userJson.videoQuotaDaily,
|
2021-02-01 15:39:13 +01:00
|
|
|
pluginAuth: userJson.pluginAuth,
|
2020-06-09 16:07:10 +02:00
|
|
|
byPassAutoBlock: userJson.adminFlags & UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
|
2017-09-05 21:29:39 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|