aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin/overview/users/user-edit/user-update.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-10-27 09:36:37 +0200
committerChocobozzz <chocobozzz@cpy.re>2021-10-29 11:48:21 +0200
commit00004f7f6b966a975498612117212b5373f4103c (patch)
tree4899b77da3c55bf1fbb77f927d9da5cd873e2c2a /client/src/app/+admin/overview/users/user-edit/user-update.component.ts
parentbd898dd76babf6ab33a0040297bfb40a69a69dda (diff)
downloadPeerTube-00004f7f6b966a975498612117212b5373f4103c.tar.gz
PeerTube-00004f7f6b966a975498612117212b5373f4103c.tar.zst
PeerTube-00004f7f6b966a975498612117212b5373f4103c.zip
Put admin users in overview tab
Diffstat (limited to 'client/src/app/+admin/overview/users/user-edit/user-update.component.ts')
-rw-r--r--client/src/app/+admin/overview/users/user-edit/user-update.component.ts139
1 files changed, 139 insertions, 0 deletions
diff --git a/client/src/app/+admin/overview/users/user-edit/user-update.component.ts b/client/src/app/+admin/overview/users/user-edit/user-update.component.ts
new file mode 100644
index 000000000..42599a17e
--- /dev/null
+++ b/client/src/app/+admin/overview/users/user-edit/user-update.component.ts
@@ -0,0 +1,139 @@
1import { Subscription } from 'rxjs'
2import { Component, OnDestroy, OnInit } from '@angular/core'
3import { ActivatedRoute, Router } from '@angular/router'
4import { ConfigService } from '@app/+admin/config/shared/config.service'
5import { AuthService, Notifier, ScreenService, ServerService, User, UserService } from '@app/core'
6import {
7 USER_EMAIL_VALIDATOR,
8 USER_ROLE_VALIDATOR,
9 USER_VIDEO_QUOTA_DAILY_VALIDATOR,
10 USER_VIDEO_QUOTA_VALIDATOR
11} from '@app/shared/form-validators/user-validators'
12import { FormValidatorService } from '@app/shared/shared-forms'
13import { User as UserType, UserAdminFlag, UserRole, UserUpdate } from '@shared/models'
14import { UserEdit } from './user-edit'
15
16@Component({
17 selector: 'my-user-update',
18 templateUrl: './user-edit.component.html',
19 styleUrls: [ './user-edit.component.scss' ]
20})
21export class UserUpdateComponent extends UserEdit implements OnInit, OnDestroy {
22 error: string
23
24 private paramsSub: Subscription
25
26 constructor (
27 protected formValidatorService: FormValidatorService,
28 protected serverService: ServerService,
29 protected configService: ConfigService,
30 protected screenService: ScreenService,
31 protected auth: AuthService,
32 private route: ActivatedRoute,
33 private router: Router,
34 private notifier: Notifier,
35 private userService: UserService
36 ) {
37 super()
38
39 this.buildQuotaOptions()
40 }
41
42 ngOnInit () {
43 super.ngOnInit()
44
45 const defaultValues = {
46 role: UserRole.USER.toString(),
47 videoQuota: '-1',
48 videoQuotaDaily: '-1'
49 }
50
51 this.buildForm({
52 email: USER_EMAIL_VALIDATOR,
53 role: USER_ROLE_VALIDATOR,
54 videoQuota: USER_VIDEO_QUOTA_VALIDATOR,
55 videoQuotaDaily: USER_VIDEO_QUOTA_DAILY_VALIDATOR,
56 byPassAutoBlock: null,
57 pluginAuth: null
58 }, defaultValues)
59
60 this.paramsSub = this.route.params.subscribe(routeParams => {
61 const userId = routeParams['id']
62 this.userService.getUser(userId, true)
63 .subscribe({
64 next: user => this.onUserFetched(user),
65
66 error: err => {
67 this.error = err.message
68 }
69 })
70 })
71 }
72
73 ngOnDestroy () {
74 this.paramsSub.unsubscribe()
75 }
76
77 formValidated () {
78 this.error = undefined
79
80 const userUpdate: UserUpdate = this.form.value
81 userUpdate.adminFlags = this.buildAdminFlags(this.form.value)
82
83 // A select in HTML is always mapped as a string, we convert it to number
84 userUpdate.videoQuota = parseInt(this.form.value['videoQuota'], 10)
85 userUpdate.videoQuotaDaily = parseInt(this.form.value['videoQuotaDaily'], 10)
86
87 if (userUpdate.pluginAuth === 'null') userUpdate.pluginAuth = null
88
89 this.userService.updateUser(this.user.id, userUpdate)
90 .subscribe({
91 next: () => {
92 this.notifier.success($localize`User ${this.user.username} updated.`)
93 this.router.navigate([ '/admin/users/list' ])
94 },
95
96 error: err => {
97 this.error = err.message
98 }
99 })
100 }
101
102 isCreation () {
103 return false
104 }
105
106 isPasswordOptional () {
107 return false
108 }
109
110 getFormButtonTitle () {
111 return $localize`Update user`
112 }
113
114 resetPassword () {
115 this.userService.askResetPassword(this.user.email)
116 .subscribe({
117 next: () => {
118 this.notifier.success($localize`An email asking for password reset has been sent to ${this.user.username}.`)
119 },
120
121 error: err => {
122 this.error = err.message
123 }
124 })
125 }
126
127 private onUserFetched (userJson: UserType) {
128 this.user = new User(userJson)
129
130 this.form.patchValue({
131 email: userJson.email,
132 role: userJson.role.toString(),
133 videoQuota: userJson.videoQuota,
134 videoQuotaDaily: userJson.videoQuotaDaily,
135 pluginAuth: userJson.pluginAuth,
136 byPassAutoBlock: userJson.adminFlags & UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
137 })
138 }
139}