2020-05-13 14:41:43 +02:00
|
|
|
import { Component, OnDestroy } from '@angular/core';
|
|
|
|
import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms';
|
|
|
|
import { Router } from '@angular/router';
|
|
|
|
import { Subscription } from 'rxjs';
|
|
|
|
import { CreateUserRequest, Gender, User } from 'src/app/proto/generated/management_pb';
|
2020-08-29 10:43:35 +02:00
|
|
|
import { ManagementService } from 'src/app/services/mgmt.service';
|
2020-05-13 14:41:43 +02:00
|
|
|
import { ToastService } from 'src/app/services/toast.service';
|
|
|
|
|
2020-06-24 11:33:27 +02:00
|
|
|
function noEmailValidator(c: AbstractControl): any {
|
|
|
|
const EMAIL_REGEXP: RegExp = /^((?!@).)*$/gm;
|
|
|
|
if (!c.parent || !c) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const username = c.parent.get('userName');
|
|
|
|
|
|
|
|
if (!username) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EMAIL_REGEXP.test(username.value) ? null : {
|
|
|
|
noEmailValidator: {
|
|
|
|
valid: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-05-13 14:41:43 +02:00
|
|
|
@Component({
|
|
|
|
selector: 'app-user-create',
|
|
|
|
templateUrl: './user-create.component.html',
|
|
|
|
styleUrls: ['./user-create.component.scss'],
|
|
|
|
})
|
|
|
|
export class UserCreateComponent implements OnDestroy {
|
|
|
|
public user: CreateUserRequest.AsObject = new CreateUserRequest().toObject();
|
|
|
|
public genders: Gender[] = [Gender.GENDER_FEMALE, Gender.GENDER_MALE, Gender.GENDER_UNSPECIFIED];
|
|
|
|
public languages: string[] = ['de', 'en'];
|
|
|
|
public userForm!: FormGroup;
|
|
|
|
|
|
|
|
private sub: Subscription = new Subscription();
|
|
|
|
|
2020-06-24 11:33:27 +02:00
|
|
|
public userLoginMustBeDomain: boolean = false;
|
2020-07-24 09:48:58 +02:00
|
|
|
public loading: boolean = false;
|
2020-06-24 11:33:27 +02:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private router: Router,
|
|
|
|
private toast: ToastService,
|
2020-08-29 10:43:35 +02:00
|
|
|
public userService: ManagementService,
|
2020-06-24 11:33:27 +02:00
|
|
|
private fb: FormBuilder,
|
2020-08-29 10:43:35 +02:00
|
|
|
private mgmtService: ManagementService,
|
2020-06-24 11:33:27 +02:00
|
|
|
) {
|
2020-07-24 09:48:58 +02:00
|
|
|
this.loading = true;
|
2020-08-29 10:43:35 +02:00
|
|
|
this.mgmtService.GetMyOrgIamPolicy().then((iampolicy) => {
|
2020-06-24 11:33:27 +02:00
|
|
|
this.userLoginMustBeDomain = iampolicy.toObject().userLoginMustBeDomain;
|
|
|
|
this.initForm();
|
2020-07-24 09:48:58 +02:00
|
|
|
this.loading = false;
|
2020-06-24 11:33:27 +02:00
|
|
|
}).catch(error => {
|
|
|
|
console.error(error);
|
|
|
|
this.initForm();
|
2020-07-24 09:48:58 +02:00
|
|
|
this.loading = false;
|
2020-06-24 11:33:27 +02:00
|
|
|
});
|
|
|
|
}
|
2020-05-13 14:41:43 +02:00
|
|
|
|
2020-06-24 11:33:27 +02:00
|
|
|
private initForm(): void {
|
2020-05-13 14:41:43 +02:00
|
|
|
this.userForm = this.fb.group({
|
|
|
|
email: ['', [Validators.required, Validators.email]],
|
2020-06-24 11:33:27 +02:00
|
|
|
userName: ['',
|
|
|
|
[
|
|
|
|
Validators.required,
|
|
|
|
Validators.minLength(2),
|
|
|
|
this.userLoginMustBeDomain ? noEmailValidator : Validators.email,
|
|
|
|
],
|
|
|
|
],
|
2020-05-13 14:41:43 +02:00
|
|
|
firstName: ['', Validators.required],
|
|
|
|
lastName: ['', Validators.required],
|
|
|
|
nickName: [''],
|
|
|
|
gender: [Gender.GENDER_UNSPECIFIED],
|
|
|
|
preferredLanguage: [''],
|
|
|
|
phone: [''],
|
|
|
|
streetAddress: [''],
|
|
|
|
postalCode: [''],
|
|
|
|
locality: [''],
|
|
|
|
region: [''],
|
|
|
|
country: [''],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public createUser(): void {
|
|
|
|
this.user = this.userForm.value;
|
|
|
|
|
2020-07-24 09:48:58 +02:00
|
|
|
this.loading = true;
|
2020-05-13 14:41:43 +02:00
|
|
|
this.userService
|
|
|
|
.CreateUser(this.user)
|
|
|
|
.then((data: User) => {
|
2020-07-24 09:48:58 +02:00
|
|
|
this.loading = false;
|
2020-07-09 10:54:55 +02:00
|
|
|
this.toast.showInfo('USER.TOAST.CREATED', true);
|
2020-05-13 14:41:43 +02:00
|
|
|
this.router.navigate(['users', data.getId()]);
|
|
|
|
})
|
fix(console): cleanup structure, role guard, paginated requests, cleanup policies, toast i18n, view timestamp, preloading strategy, maennchenfindings, fix passwordchange (#483)
* routes, move grid to list comopnent
* rename app list component, move to project sub
* add owned-project-detail child module
* seperate pipes
* set password validators only if needed
* create org initialize without pwd
* no caps
* self xss message
* fix user table
* fix project member paginator
* fix project members pagination, user grant pag
* move project grants, fix imports
* fix owned project detail imports
* use pipe and directives
* ng content bindings, rem custom schemas
* i18n, fix error toast parameter
* toast i18n
* side background
* fix: sequence, add timestamp
* audit
* fix metanav background
* org domain label
* cleanup policy component
* shorten user grant roles, mk cols visible as bind
* move user components, show otp only if available
* preload modules
* fix password change
* fix org create buttons
* class css
2020-07-16 15:13:36 +02:00
|
|
|
.catch(error => {
|
2020-07-24 09:48:58 +02:00
|
|
|
this.loading = false;
|
fix(console): cleanup structure, role guard, paginated requests, cleanup policies, toast i18n, view timestamp, preloading strategy, maennchenfindings, fix passwordchange (#483)
* routes, move grid to list comopnent
* rename app list component, move to project sub
* add owned-project-detail child module
* seperate pipes
* set password validators only if needed
* create org initialize without pwd
* no caps
* self xss message
* fix user table
* fix project member paginator
* fix project members pagination, user grant pag
* move project grants, fix imports
* fix owned project detail imports
* use pipe and directives
* ng content bindings, rem custom schemas
* i18n, fix error toast parameter
* toast i18n
* side background
* fix: sequence, add timestamp
* audit
* fix metanav background
* org domain label
* cleanup policy component
* shorten user grant roles, mk cols visible as bind
* move user components, show otp only if available
* preload modules
* fix password change
* fix org create buttons
* class css
2020-07-16 15:13:36 +02:00
|
|
|
this.toast.showError(error);
|
2020-05-13 14:41:43 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
|
|
|
|
this.sub.unsubscribe();
|
|
|
|
}
|
|
|
|
|
|
|
|
public get email(): AbstractControl | null {
|
|
|
|
return this.userForm.get('email');
|
|
|
|
}
|
|
|
|
public get userName(): AbstractControl | null {
|
|
|
|
return this.userForm.get('userName');
|
|
|
|
}
|
|
|
|
public get firstName(): AbstractControl | null {
|
|
|
|
return this.userForm.get('firstName');
|
|
|
|
}
|
|
|
|
public get lastName(): AbstractControl | null {
|
|
|
|
return this.userForm.get('lastName');
|
|
|
|
}
|
|
|
|
public get nickName(): AbstractControl | null {
|
|
|
|
return this.userForm.get('nickName');
|
|
|
|
}
|
|
|
|
public get gender(): AbstractControl | null {
|
|
|
|
return this.userForm.get('gender');
|
|
|
|
}
|
|
|
|
public get preferredLanguage(): AbstractControl | null {
|
|
|
|
return this.userForm.get('preferredLanguage');
|
|
|
|
}
|
|
|
|
public get phone(): AbstractControl | null {
|
|
|
|
return this.userForm.get('phone');
|
|
|
|
}
|
|
|
|
public get streetAddress(): AbstractControl | null {
|
|
|
|
return this.userForm.get('streetAddress');
|
|
|
|
}
|
|
|
|
public get postalCode(): AbstractControl | null {
|
|
|
|
return this.userForm.get('postalCode');
|
|
|
|
}
|
|
|
|
public get locality(): AbstractControl | null {
|
|
|
|
return this.userForm.get('locality');
|
|
|
|
}
|
|
|
|
public get region(): AbstractControl | null {
|
|
|
|
return this.userForm.get('region');
|
|
|
|
}
|
|
|
|
public get country(): AbstractControl | null {
|
|
|
|
return this.userForm.get('country');
|
|
|
|
}
|
|
|
|
}
|