aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin/overview/users/user-edit
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
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')
-rw-r--r--client/src/app/+admin/overview/users/user-edit/index.ts3
-rw-r--r--client/src/app/+admin/overview/users/user-edit/user-create.component.ts98
-rw-r--r--client/src/app/+admin/overview/users/user-edit/user-edit.component.html237
-rw-r--r--client/src/app/+admin/overview/users/user-edit/user-edit.component.scss76
-rw-r--r--client/src/app/+admin/overview/users/user-edit/user-edit.ts102
-rw-r--r--client/src/app/+admin/overview/users/user-edit/user-password.component.html21
-rw-r--r--client/src/app/+admin/overview/users/user-edit/user-password.component.scss23
-rw-r--r--client/src/app/+admin/overview/users/user-edit/user-password.component.ts55
-rw-r--r--client/src/app/+admin/overview/users/user-edit/user-update.component.ts139
9 files changed, 754 insertions, 0 deletions
diff --git a/client/src/app/+admin/overview/users/user-edit/index.ts b/client/src/app/+admin/overview/users/user-edit/index.ts
new file mode 100644
index 000000000..ec734ef92
--- /dev/null
+++ b/client/src/app/+admin/overview/users/user-edit/index.ts
@@ -0,0 +1,3 @@
1export * from './user-create.component'
2export * from './user-update.component'
3export * from './user-password.component'
diff --git a/client/src/app/+admin/overview/users/user-edit/user-create.component.ts b/client/src/app/+admin/overview/users/user-edit/user-create.component.ts
new file mode 100644
index 000000000..b61b22fd0
--- /dev/null
+++ b/client/src/app/+admin/overview/users/user-edit/user-create.component.ts
@@ -0,0 +1,98 @@
1import { Component, OnInit } from '@angular/core'
2import { Router } from '@angular/router'
3import { ConfigService } from '@app/+admin/config/shared/config.service'
4import { AuthService, Notifier, ScreenService, ServerService, UserService } from '@app/core'
5import {
6 USER_CHANNEL_NAME_VALIDATOR,
7 USER_EMAIL_VALIDATOR,
8 USER_PASSWORD_OPTIONAL_VALIDATOR,
9 USER_PASSWORD_VALIDATOR,
10 USER_ROLE_VALIDATOR,
11 USER_USERNAME_VALIDATOR,
12 USER_VIDEO_QUOTA_DAILY_VALIDATOR,
13 USER_VIDEO_QUOTA_VALIDATOR
14} from '@app/shared/form-validators/user-validators'
15import { FormValidatorService } from '@app/shared/shared-forms'
16import { UserCreate, UserRole } from '@shared/models'
17import { UserEdit } from './user-edit'
18
19@Component({
20 selector: 'my-user-create',
21 templateUrl: './user-edit.component.html',
22 styleUrls: [ './user-edit.component.scss' ]
23})
24export class UserCreateComponent extends UserEdit implements OnInit {
25 error: string
26
27 constructor (
28 protected serverService: ServerService,
29 protected formValidatorService: FormValidatorService,
30 protected configService: ConfigService,
31 protected screenService: ScreenService,
32 protected auth: AuthService,
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 username: USER_USERNAME_VALIDATOR,
53 channelName: USER_CHANNEL_NAME_VALIDATOR,
54 email: USER_EMAIL_VALIDATOR,
55 password: this.isPasswordOptional() ? USER_PASSWORD_OPTIONAL_VALIDATOR : USER_PASSWORD_VALIDATOR,
56 role: USER_ROLE_VALIDATOR,
57 videoQuota: USER_VIDEO_QUOTA_VALIDATOR,
58 videoQuotaDaily: USER_VIDEO_QUOTA_DAILY_VALIDATOR,
59 byPassAutoBlock: null
60 }, defaultValues)
61 }
62
63 formValidated () {
64 this.error = undefined
65
66 const userCreate: UserCreate = this.form.value
67
68 userCreate.adminFlags = this.buildAdminFlags(this.form.value)
69
70 // A select in HTML is always mapped as a string, we convert it to number
71 userCreate.videoQuota = parseInt(this.form.value['videoQuota'], 10)
72 userCreate.videoQuotaDaily = parseInt(this.form.value['videoQuotaDaily'], 10)
73
74 this.userService.addUser(userCreate)
75 .subscribe({
76 next: () => {
77 this.notifier.success($localize`User ${userCreate.username} created.`)
78 this.router.navigate([ '/admin/users/list' ])
79 },
80
81 error: err => {
82 this.error = err.message
83 }
84 })
85 }
86
87 isCreation () {
88 return true
89 }
90
91 isPasswordOptional () {
92 return this.serverConfig.email.enabled
93 }
94
95 getFormButtonTitle () {
96 return $localize`Create user`
97 }
98}
diff --git a/client/src/app/+admin/overview/users/user-edit/user-edit.component.html b/client/src/app/+admin/overview/users/user-edit/user-edit.component.html
new file mode 100644
index 000000000..772ebf272
--- /dev/null
+++ b/client/src/app/+admin/overview/users/user-edit/user-edit.component.html
@@ -0,0 +1,237 @@
1<nav aria-label="breadcrumb">
2 <ol class="breadcrumb">
3 <li class="breadcrumb-item">
4 <a routerLink="/admin/users" i18n>Users</a>
5 </li>
6
7 <ng-container *ngIf="isCreation()">
8 <li class="breadcrumb-item active" i18n>Create</li>
9 </ng-container>
10 <ng-container *ngIf="!isCreation()">
11 <li class="breadcrumb-item active" i18n>Edit</li>
12 <li class="breadcrumb-item active" aria-current="page">
13 <a *ngIf="user" [routerLink]="[ '/a', user?.username ]">{{ user?.username }}</a>
14 </li>
15 </ng-container>
16 </ol>
17</nav>
18
19<ng-template #dashboard>
20 <div *ngIf="!isCreation() && user" class="dashboard">
21 <div>
22 <a>
23 <div class="dashboard-num">{{ user.videosCount }} ({{ user.videoQuotaUsed | bytes: 0 }})</div>
24 <div class="dashboard-label" i18n>{user.videosCount, plural, =1 {Video} other {Videos}}</div>
25 </a>
26 </div>
27 <div>
28 <a>
29 <div class="dashboard-num">{{ user.videoChannels.length || 0 }}</div>
30 <div class="dashboard-label" i18n>{user.videoChannels.length, plural, =1 {Channel} other {Channels}}</div>
31 </a>
32 </div>
33 <div>
34 <a>
35 <div class="dashboard-num">{{ subscribersCount }}</div>
36 <div class="dashboard-label" i18n>{subscribersCount, plural, =1 {Subscriber} other {Subscribers}}</div>
37 </a>
38 </div>
39 <div>
40 <a [routerLink]="[ '/admin/moderation/abuses/list' ]" [queryParams]="{ 'search': 'reportee:&quot;' + user?.account.displayName + '&quot;' }">
41 <div class="dashboard-num">{{ user.abusesCount }}</div>
42 <div class="dashboard-label" i18n>Incriminated in reports</div>
43 </a>
44 </div>
45 <div>
46 <a [routerLink]="[ '/admin/moderation/abuses/list' ]" [queryParams]="{ 'search': 'reporter:&quot;' + user?.account.displayName + '&quot; state:accepted' }">
47 <div class="dashboard-num">{{ user.abusesAcceptedCount }} / {{ user.abusesCreatedCount }}</div>
48 <div class="dashboard-label" i18n>Authored reports accepted</div>
49 </a>
50 </div>
51 <div>
52 <a>
53 <div class="dashboard-num">{{ user.videoCommentsCount }}</div>
54 <div class="dashboard-label" i18n>{user.videoCommentsCount, plural, =1 {Comment} other {Comments}}</div>
55 </a>
56 </div>
57 </div>
58</ng-template>
59
60<div class="form-row" *ngIf="!isInBigView()"> <!-- hidden on large screens, as it is then displayed on the right side of the form -->
61 <div class="col-12 col-xl-3"></div>
62
63 <div class="col-12 col-xl-9">
64 <ng-template *ngTemplateOutlet="dashboard"></ng-template>
65 </div>
66</div>
67
68<div *ngIf="error" class="alert alert-danger">{{ error }}</div>
69
70<div class="form-row mt-4"> <!-- user grid -->
71 <div class="form-group col-12 col-lg-4 col-xl-3">
72 <div class="anchor" id="user"></div> <!-- user anchor -->
73 <div *ngIf="isCreation()" class="account-title" i18n>NEW USER</div>
74 <div *ngIf="!isCreation() && user" class="account-title">
75 <my-actor-avatar-edit [actor]="user.account" [editable]="false" [displaySubscribers]="false" [displayUsername]="false"></my-actor-avatar-edit>
76 </div>
77 </div>
78
79 <div class="form-group col-12 col-lg-8 col-xl-9" [ngClass]="{ 'form-row': isInBigView() }">
80
81 <form role="form" (ngSubmit)="formValidated()" [formGroup]="form" [ngClass]="{ 'col-5': isInBigView() }">
82 <div class="form-group" *ngIf="isCreation()">
83 <label i18n for="username">Username</label>
84 <input
85 type="text" id="username" i18n-placeholder placeholder="john" class="form-control"
86 formControlName="username" [ngClass]="{ 'input-error': formErrors['username'] }"
87 >
88 <div *ngIf="formErrors.username" class="form-error">
89 {{ formErrors.username }}
90 </div>
91 </div>
92
93 <div class="form-group" *ngIf="isCreation()">
94 <label i18n for="channelName">Channel name</label>
95 <input
96 type="text" id="channelName" i18n-placeholder placeholder="john_channel" class="form-control"
97 formControlName="channelName" [ngClass]="{ 'input-error': formErrors['channelName'] }"
98 >
99 <div *ngIf="formErrors.channelName" class="form-error">
100 {{ formErrors.channelName }}
101 </div>
102 </div>
103
104 <div class="form-group">
105 <label i18n for="email">Email</label>
106 <input
107 type="text" id="email" i18n-placeholder placeholder="mail@example.com" class="form-control"
108 formControlName="email" [ngClass]="{ 'input-error': formErrors['email'] }"
109 autocomplete="off" [readonly]="user && user.pluginAuth !== null"
110 >
111 <div *ngIf="formErrors.email" class="form-error">
112 {{ formErrors.email }}
113 </div>
114 </div>
115
116 <div class="form-group" *ngIf="isCreation()">
117 <label i18n for="password">Password</label>
118 <my-help *ngIf="isPasswordOptional()">
119 <ng-template ptTemplate="customHtml">
120 <ng-container i18n>
121 If you leave the password empty, an email will be sent to the user.
122 </ng-container>
123 </ng-template>
124 </my-help>
125
126 <my-input-toggle-hidden
127 formControlName="password" inputId="password" [ngClass]="{ 'input-error': formErrors['password'] }" autocomplete="new-password"
128 ></my-input-toggle-hidden>
129
130 <div *ngIf="formErrors.password" class="form-error">
131 {{ formErrors.password }}
132 </div>
133 </div>
134
135 <div class="form-group">
136 <label i18n for="role">Role</label>
137 <div class="peertube-select-container">
138 <select id="role" formControlName="role" class="form-control">
139 <option *ngFor="let role of roles" [value]="role.value">
140 {{ role.label }}
141 </option>
142 </select>
143 </div>
144
145 <div *ngIf="formErrors.role" class="form-error">
146 {{ formErrors.role }}
147 </div>
148 </div>
149
150 <div class="form-group">
151 <label i18n for="videoQuota">Video quota</label>
152
153 <my-select-custom-value
154 id="videoQuota"
155 [items]="videoQuotaOptions"
156 formControlName="videoQuota"
157 i18n-inputSuffix inputSuffix="bytes" inputType="number"
158 [clearable]="false"
159 ></my-select-custom-value>
160
161 <div i18n class="transcoding-information" *ngIf="isTranscodingInformationDisplayed()">
162 Transcoding is enabled. The video quota only takes into account <strong>original</strong> video size. <br />
163 At most, this user could upload ~ {{ computeQuotaWithTranscoding() | bytes: 0 }}.
164 </div>
165
166 <div *ngIf="formErrors.videoQuota" class="form-error">
167 {{ formErrors.videoQuota }}
168 </div>
169 </div>
170
171 <div class="form-group">
172 <label i18n for="videoQuotaDaily">Daily video quota</label>
173
174 <my-select-custom-value
175 id="videoQuotaDaily"
176 [items]="videoQuotaDailyOptions"
177 formControlName="videoQuotaDaily"
178 i18n-inputSuffix inputSuffix="bytes" inputType="number"
179 [clearable]="false"
180 ></my-select-custom-value>
181
182 <div *ngIf="formErrors.videoQuotaDaily" class="form-error">
183 {{ formErrors.videoQuotaDaily }}
184 </div>
185 </div>
186
187 <div class="form-group" *ngIf="!isCreation() && getAuthPlugins().length !== 0">
188 <label i18n for="pluginAuth">Auth plugin</label>
189
190 <div class="peertube-select-container">
191 <select id="pluginAuth" formControlName="pluginAuth" class="form-control">
192 <option [value]="null" i18n>None (local authentication)</option>
193 <option *ngFor="let authPlugin of getAuthPlugins()" [value]="authPlugin">{{ authPlugin }}</option>
194 </select>
195 </div>
196 </div>
197
198 <div class="form-group">
199 <my-peertube-checkbox
200 inputName="byPassAutoBlock" formControlName="byPassAutoBlock"
201 i18n-labelText labelText="Doesn't need review before a video goes public"
202 ></my-peertube-checkbox>
203 </div>
204
205 <input type="submit" value="{{ getFormButtonTitle() }}" [disabled]="!form.valid">
206 </form>
207
208 <div *ngIf="isInBigView()" class="col-7">
209 <ng-template *ngTemplateOutlet="dashboard"></ng-template>
210 </div>
211
212 </div>
213</div>
214
215
216<div *ngIf="!isCreation() && user && user.pluginAuth === null" class="form-row mt-4"> <!-- danger zone grid -->
217 <div class="form-group col-12 col-lg-4 col-xl-3">
218 <div class="anchor" id="danger"></div> <!-- danger zone anchor -->
219 <div i18n class="account-title account-title-danger">DANGER ZONE</div>
220 </div>
221
222 <div class="form-group col-12 col-lg-8 col-xl-9" [ngClass]="{ 'form-row': isInBigView() }">
223
224 <div class="danger-zone">
225 <div class="form-group reset-password-email">
226 <label i18n>Send a link to reset the password by email to the user</label>
227 <button (click)="resetPassword()" i18n>Ask for new password</button>
228 </div>
229
230 <div class="form-group">
231 <label i18n>Manually set the user password</label>
232 <my-user-password [userId]="user.id"></my-user-password>
233 </div>
234 </div>
235
236 </div>
237</div>
diff --git a/client/src/app/+admin/overview/users/user-edit/user-edit.component.scss b/client/src/app/+admin/overview/users/user-edit/user-edit.component.scss
new file mode 100644
index 000000000..d7932154b
--- /dev/null
+++ b/client/src/app/+admin/overview/users/user-edit/user-edit.component.scss
@@ -0,0 +1,76 @@
1@use 'sass:math';
2@use '_variables' as *;
3@use '_mixins' as *;
4
5$form-base-input-width: 340px;
6
7label {
8 font-weight: $font-regular;
9 font-size: 100%;
10}
11
12.account-title {
13 @include settings-big-title;
14
15 &.account-title-danger {
16 color: lighten($color: #c54130, $amount: 10);
17 }
18}
19
20input:not([type=submit]) {
21 @include peertube-input-text($form-base-input-width);
22 display: block;
23}
24
25my-input-toggle-hidden {
26 @include responsive-width($form-base-input-width);
27
28 display: block;
29}
30
31.peertube-select-container {
32 @include peertube-select-container($form-base-input-width);
33}
34
35my-select-custom-value {
36 @include responsive-width($form-base-input-width);
37
38 display: block;
39}
40
41input[type=submit],
42button {
43 @include peertube-button;
44 @include orange-button;
45
46 margin-top: 10px;
47}
48
49.transcoding-information {
50 margin-top: 5px;
51 font-size: 11px;
52}
53
54.danger-zone {
55 .reset-password-email {
56 margin-bottom: 30px;
57
58 button {
59 @include peertube-button;
60 @include danger-button;
61 @include disable-outline;
62
63 display: block;
64 margin-top: 0;
65 }
66 }
67}
68
69.breadcrumb {
70 @include breadcrumb;
71}
72
73.dashboard {
74 @include dashboard;
75 max-width: 900px;
76}
diff --git a/client/src/app/+admin/overview/users/user-edit/user-edit.ts b/client/src/app/+admin/overview/users/user-edit/user-edit.ts
new file mode 100644
index 000000000..069b62a53
--- /dev/null
+++ b/client/src/app/+admin/overview/users/user-edit/user-edit.ts
@@ -0,0 +1,102 @@
1import { Directive, OnInit } from '@angular/core'
2import { ConfigService } from '@app/+admin/config/shared/config.service'
3import { AuthService, ScreenService, ServerService, User } from '@app/core'
4import { FormReactive } from '@app/shared/shared-forms'
5import { USER_ROLE_LABELS } from '@shared/core-utils/users'
6import { HTMLServerConfig, UserAdminFlag, UserRole, VideoResolution } from '@shared/models'
7import { SelectOptionsItem } from '../../../../../types/select-options-item.model'
8
9@Directive()
10// eslint-disable-next-line @angular-eslint/directive-class-suffix
11export abstract class UserEdit extends FormReactive implements OnInit {
12 videoQuotaOptions: SelectOptionsItem[] = []
13 videoQuotaDailyOptions: SelectOptionsItem[] = []
14 username: string
15 user: User
16
17 roles: { value: string, label: string }[] = []
18
19 protected serverConfig: HTMLServerConfig
20
21 protected abstract serverService: ServerService
22 protected abstract configService: ConfigService
23 protected abstract screenService: ScreenService
24 protected abstract auth: AuthService
25 abstract isCreation (): boolean
26 abstract getFormButtonTitle (): string
27
28 ngOnInit (): void {
29 this.serverConfig = this.serverService.getHTMLConfig()
30
31 this.buildRoles()
32 }
33
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
44 getAuthPlugins () {
45 return this.serverConfig.plugin.registeredIdAndPassAuths.map(p => p.npmName)
46 .concat(this.serverConfig.plugin.registeredExternalAuths.map(p => p.npmName))
47 }
48
49 isInBigView () {
50 return this.screenService.getWindowInnerWidth() > 1600
51 }
52
53 buildRoles () {
54 const authUser = this.auth.getUser()
55
56 if (authUser.role === UserRole.ADMINISTRATOR) {
57 this.roles = Object.keys(USER_ROLE_LABELS)
58 .map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
59 return
60 }
61
62 this.roles = [
63 { value: UserRole.USER.toString(), label: USER_ROLE_LABELS[UserRole.USER] }
64 ]
65 }
66
67 isTranscodingInformationDisplayed () {
68 const formVideoQuota = parseInt(this.form.value['videoQuota'], 10)
69
70 return this.serverConfig.transcoding.enabledResolutions.length !== 0 &&
71 formVideoQuota > 0
72 }
73
74 computeQuotaWithTranscoding () {
75 const transcodingConfig = this.serverConfig.transcoding
76
77 const resolutions = transcodingConfig.enabledResolutions
78 const higherResolution = VideoResolution.H_4K
79 let multiplier = 0
80
81 for (const resolution of resolutions) {
82 multiplier += resolution / higherResolution
83 }
84
85 if (transcodingConfig.hls.enabled) multiplier *= 2
86
87 return multiplier * parseInt(this.form.value['videoQuota'], 10)
88 }
89
90 resetPassword () {
91 return
92 }
93
94 protected buildAdminFlags (formValue: any) {
95 return formValue.byPassAutoBlock ? UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE
96 }
97
98 protected buildQuotaOptions () {
99 this.videoQuotaOptions = this.configService.videoQuotaOptions
100 this.videoQuotaDailyOptions = this.configService.videoQuotaDailyOptions
101 }
102}
diff --git a/client/src/app/+admin/overview/users/user-edit/user-password.component.html b/client/src/app/+admin/overview/users/user-edit/user-password.component.html
new file mode 100644
index 000000000..1238d1839
--- /dev/null
+++ b/client/src/app/+admin/overview/users/user-edit/user-password.component.html
@@ -0,0 +1,21 @@
1<form role="form" (ngSubmit)="formValidated()" [formGroup]="form">
2 <div class="form-group">
3
4 <div class="input-group">
5 <input id="password" [attr.type]="showPassword ? 'text' : 'password'" class="form-control"
6 formControlName="password" [ngClass]="{ 'input-error': formErrors['password'] }"
7 >
8 <div class="input-group-append">
9 <button class="btn btn-sm btn-outline-secondary" (click)="togglePasswordVisibility()" type="button">
10 <ng-container *ngIf="!showPassword" i18n>Show</ng-container>
11 <ng-container *ngIf="!!showPassword" i18n>Hide</ng-container>
12 </button>
13 </div>
14 </div>
15 <div *ngIf="formErrors.password" class="form-error">
16 {{ formErrors.password }}
17 </div>
18 </div>
19
20 <input type="submit" value="{{ getFormButtonTitle() }}" [disabled]="!form.valid">
21</form>
diff --git a/client/src/app/+admin/overview/users/user-edit/user-password.component.scss b/client/src/app/+admin/overview/users/user-edit/user-password.component.scss
new file mode 100644
index 000000000..acb680682
--- /dev/null
+++ b/client/src/app/+admin/overview/users/user-edit/user-password.component.scss
@@ -0,0 +1,23 @@
1@use '_variables' as *;
2@use '_mixins' as *;
3
4input:not([type=submit]):not([type=checkbox]) {
5 @include peertube-input-text(340px);
6
7 display: block;
8 border-top-right-radius: 0;
9 border-bottom-right-radius: 0;
10 border-right: 0;
11}
12
13input[type=submit] {
14 @include peertube-button;
15 @include danger-button;
16 @include disable-outline;
17
18 margin-top: 10px;
19}
20
21.input-group-append {
22 height: 30px;
23}
diff --git a/client/src/app/+admin/overview/users/user-edit/user-password.component.ts b/client/src/app/+admin/overview/users/user-edit/user-password.component.ts
new file mode 100644
index 000000000..42bf20de1
--- /dev/null
+++ b/client/src/app/+admin/overview/users/user-edit/user-password.component.ts
@@ -0,0 +1,55 @@
1import { Component, Input, OnInit } from '@angular/core'
2import { Notifier, UserService } from '@app/core'
3import { USER_PASSWORD_VALIDATOR } from '@app/shared/form-validators/user-validators'
4import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
5import { UserUpdate } from '@shared/models'
6
7@Component({
8 selector: 'my-user-password',
9 templateUrl: './user-password.component.html',
10 styleUrls: [ './user-password.component.scss' ]
11})
12export class UserPasswordComponent extends FormReactive implements OnInit {
13 error: string
14 username: string
15 showPassword = false
16
17 @Input() userId: number
18
19 constructor (
20 protected formValidatorService: FormValidatorService,
21 private notifier: Notifier,
22 private userService: UserService
23 ) {
24 super()
25 }
26
27 ngOnInit () {
28 this.buildForm({
29 password: USER_PASSWORD_VALIDATOR
30 })
31 }
32
33 formValidated () {
34 this.error = undefined
35
36 const userUpdate: UserUpdate = this.form.value
37
38 this.userService.updateUser(this.userId, userUpdate)
39 .subscribe({
40 next: () => this.notifier.success($localize`Password changed for user ${this.username}.`),
41
42 error: err => {
43 this.error = err.message
44 }
45 })
46 }
47
48 togglePasswordVisibility () {
49 this.showPassword = !this.showPassword
50 }
51
52 getFormButtonTitle () {
53 return $localize`Update user password`
54 }
55}
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}