]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/users/user-edit/user-create.component.ts
Moderators can only manage users
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / users / user-edit / user-create.component.ts
CommitLineData
df98563e 1import { Component, OnInit } from '@angular/core'
df98563e 2import { Router } from '@angular/router'
a95a4cc8 3import { AuthService, Notifier, ServerService } from '@app/core'
954605a8 4import { UserCreate, UserRole } from '../../../../../../shared'
8094a898 5import { UserEdit } from './user-edit'
b1d40cff 6import { I18n } from '@ngx-translate/i18n-polyfill'
d18d6478 7import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
e309822b 8import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service'
3827c3b3 9import { ConfigService } from '@app/+admin/config/shared/config.service'
e724fa93 10import { UserService } from '@app/shared'
7da18e44
C
11
12@Component({
4c200caa 13 selector: 'my-user-create',
6a84aafd
C
14 templateUrl: './user-edit.component.html',
15 styleUrls: [ './user-edit.component.scss' ]
7da18e44 16})
4c200caa 17export class UserCreateComponent extends UserEdit implements OnInit {
8094a898 18 error: string
7da18e44 19
df98563e 20 constructor (
6a84aafd 21 protected serverService: ServerService,
d18d6478 22 protected formValidatorService: FormValidatorService,
3827c3b3 23 protected configService: ConfigService,
a95a4cc8 24 protected auth: AuthService,
e309822b 25 private userValidatorsService: UserValidatorsService,
4b2f33f3 26 private router: Router,
f8b2c1b4 27 private notifier: Notifier,
b1d40cff
C
28 private userService: UserService,
29 private i18n: I18n
4b2f33f3 30 ) {
df98563e 31 super()
3827c3b3
C
32
33 this.buildQuotaOptions()
4b2f33f3
C
34 }
35
df98563e 36 ngOnInit () {
d18d6478
C
37 const defaultValues = {
38 role: UserRole.USER.toString(),
d6ca951b
C
39 videoQuota: '-1',
40 videoQuotaDaily: '-1'
d18d6478
C
41 }
42
43 this.buildForm({
e309822b
C
44 username: this.userValidatorsService.USER_USERNAME,
45 email: this.userValidatorsService.USER_EMAIL,
46 password: this.userValidatorsService.USER_PASSWORD,
47 role: this.userValidatorsService.USER_ROLE,
d6ca951b 48 videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA,
1eddc9a7
C
49 videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY,
50 byPassAutoBlacklist: null
d18d6478 51 }, defaultValues)
7da18e44
C
52 }
53
8094a898
C
54 formValidated () {
55 this.error = undefined
7da18e44 56
4771e000 57 const userCreate: UserCreate = this.form.value
4b2f33f3 58
1eddc9a7
C
59 userCreate.adminFlags = this.buildAdminFlags(this.form.value)
60
b0f9f39e
C
61 // A select in HTML is always mapped as a string, we convert it to number
62 userCreate.videoQuota = parseInt(this.form.value['videoQuota'], 10)
1eddc9a7 63 userCreate.videoQuotaDaily = parseInt(this.form.value['videoQuotaDaily'], 10)
b0f9f39e 64
4771e000 65 this.userService.addUser(userCreate).subscribe(
7ddd02c9 66 () => {
f8b2c1b4 67 this.notifier.success(this.i18n('User {{username}} created.', { username: userCreate.username }))
df98563e 68 this.router.navigate([ '/admin/users/list' ])
7ddd02c9 69 },
7da18e44 70
f7354483 71 err => this.error = err.message
df98563e 72 )
7da18e44 73 }
8094a898
C
74
75 isCreation () {
76 return true
77 }
78
79 getFormButtonTitle () {
b1d40cff 80 return this.i18n('Create user')
8094a898 81 }
7da18e44 82}