Commit 449aa20e authored by Hamza HRAMCHI's avatar Hamza HRAMCHI
Browse files

FEAT #16956 TIME 4:15 be able to modify the information of an external user

parent ccd20313
<div class="mat-dialog-content-container">
<h1 mat-dialog-title>{{'lang.addOtpUser' | translate}}</h1>
<h1 mat-dialog-title>{{(data === null ? 'lang.addOtp' : 'lang.updateOtp') | translate}}</h1>
<div mat-dialog-content>
<div *ngIf="loading" class="loading" style="display:flex;height:100%;">
<mat-spinner style="margin:auto;"></mat-spinner>
......@@ -42,7 +42,7 @@
<mat-form-field>
<input matInput style="display: none;">
<mat-radio-group #role style="display: inline-flex;flex-direction: row;" [(ngModel)]="userOTP.role" required>
<mat-radio-button *ngFor="let role of roles" [value]="role.id" style="margin-left: 10px;">
<mat-radio-button *ngFor="let role of availableRoles" [value]="role.id" style="margin-left: 10px;" color="primary">
{{ role.label }}
</mat-radio-button>
</mat-radio-group >
......@@ -52,7 +52,7 @@
</div>
<span class="divider-modal"></span>
<div mat-dialog-actions class="actions">
<button mat-raised-button mat-button color="primary" [disabled]="loading || !isValidForm()" (click)="addOtpUser()">{{'lang.validate' | translate}}</button>
<button mat-raised-button mat-button color="primary" [disabled]="loading || !isValidForm()" (click)="addOtpUser()">{{ (this.data === null ? 'lang.validate' : 'lang.update') | translate}}</button>
<button mat-raised-button mat-button [mat-dialog-close]="">{{'lang.cancel' | translate}}</button>
</div>
</div>
import { Component, OnInit } from '@angular/core';
import { Component, Inject, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { TranslateService } from '@ngx-translate/core';
import { NotificationService } from '@service/notification/notification.service';
import { FunctionsService } from '@service/functions.service';
import { tap, catchError } from 'rxjs/operators';
import { MatDialogRef } from '@angular/material/dialog';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { of } from 'rxjs';
@Component({
......@@ -18,13 +18,13 @@ export class CreateUserOtpComponent implements OnInit {
currentSource: any[] = [];
roles: any[] = [
availableRoles: any[] = [
{
id: 'otp_visa_yousign',
id: 'visa',
label: this.translate.instant('lang.otp_visa_yousign')
},
{
id: 'otp_sign_yousign',
id: 'sign',
label: this.translate.instant('lang.otp_sign_yousign')
}
];
......@@ -45,10 +45,11 @@ export class CreateUserOtpComponent implements OnInit {
lastname: '',
email: '',
phone: '',
role: '',
security: '',
sourceId: '',
type: ''
type: '',
role: 'sign',
availableRoles: this.availableRoles.map((role: any) => role.id)
};
loading: boolean = true;
......@@ -58,7 +59,8 @@ export class CreateUserOtpComponent implements OnInit {
public http: HttpClient,
public functions: FunctionsService,
private dialogRef: MatDialogRef<CreateUserOtpComponent>,
public notify: NotificationService
public notify: NotificationService,
@Inject(MAT_DIALOG_DATA) public data: any
) { }
......@@ -72,9 +74,13 @@ export class CreateUserOtpComponent implements OnInit {
tap((data: any) => {
if (data) {
this.sources = data.otp;
this.userOTP.sourceId = this.sources[0].id;
this.userOTP.type = this.sources[0].type;
this.setCurrentSource(this.sources[0].id);
if (this.data === null) {
this.userOTP.sourceId = this.sources[0].id;
this.userOTP.type = this.sources[0].type;
} else {
this.userOTP = this.data;
}
}
this.loading = false;
resolve(true);
......@@ -98,7 +104,7 @@ export class CreateUserOtpComponent implements OnInit {
validFormat() {
const phoneRegex = /^((\+)33)[1-9](\d{2}){4}$/;
const emailReegex = /^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/;
return (this.userOTP.phone.length > 1 && this.userOTP.phone.trim().match(phoneRegex) !== null) && (this.userOTP.email.length > 1 && this.userOTP.email.trim().match(emailReegex) !== null);
return (!this.functions.empty(this.userOTP.phone) && this.userOTP.phone.trim().match(phoneRegex) !== null) && (!this.functions.empty(this.userOTP.email) && this.userOTP.email.trim().match(emailReegex) !== null);
}
setCurrentSource(id: any) {
......
......@@ -2,7 +2,7 @@
<button *ngIf="adminMode && otpConfig > 0" mat-raised-button mat-button color="primary" [title]="'lang.addOtpUser' | translate"
style="margin: 10px; display: flex;" (click)="openCreateUserOtp()">
<mat-icon class="fas fa-user-plus" style="width: auto;height: auto;"></mat-icon>
{{'lang.addOtpUser' | translate}}
{{'lang.addOtp' | translate}}
</button>
<app-plugin-autocomplete *ngIf="adminMode" [labelPlaceholder]="'lang.addPerson' | translate"
[routeDatas]="['/rest/autocomplete/maarchParapheurUsers']" [targetSearchKey]="'idToDisplay'"
......@@ -46,8 +46,8 @@
style="opacity:0.5;"></mat-icon>
</ng-container>
<div mat-line class="workflowLine">
<div class="workflowLineContainer">
<div class="workflowLineLabel" [class.unauthorized]="!diffusion.hasPrivilege || !diffusion.isValid">
<div class="workflowLineContainer" (click)="openCreateUserOtp(diffusion)">
<div class="workflowLineLabel" [class.unauthorized]="!diffusion.hasPrivilege || !diffusion.isValid" [title]="diffusion.labelToDisplay">
{{diffusion.labelToDisplay}}
<ng-container *ngIf="diffusion.process_date != null && diffusion.delegatedBy !== null">
<mat-icon mat-list-icon class="fas fa-exclamation-circle"
......@@ -72,10 +72,10 @@
<ng-container>
<button class="currentRoleButton" [class.readonly]="!adminMode" [color]="diffusion.role === 'visa' ? 'default':'primary'" mat-raised-button
title="{{'lang.' + diffusion.role | translate}}"
[matMenuTriggerFor]="rolesMenu" [disabled]="!adminMode">{{'lang.' + diffusion.role | translate}}</button>
[matMenuTriggerFor]="rolesMenu" [disabled]="!adminMode">{{'lang.' + diffusion.role + (diffusion.role === 'sign' ? 'User' : '') | translate}}</button>
<mat-menu #rolesMenu="matMenu">
<ng-container *ngFor="let role of diffusion.availableRoles">
<button mat-menu-item (click)="diffusion.role=role" [class.selected]="diffusion.role===role" [disabled]="!isValidRole(i,role,diffusion.role)">{{'lang.'+ role | translate}}</button>
<button mat-menu-item (click)="diffusion.role=role" [class.selected]="diffusion.role===role" [disabled]="!isValidRole(i,role,diffusion.role)">{{'lang.'+ role + (role === 'sign' ? 'User' : '') | translate}}</button>
</ng-container>
</mat-menu>
</ng-container>
......
......@@ -345,33 +345,52 @@ export class ExternalVisaWorkflowComponent implements OnInit {
}
}
openCreateUserOtp() {
const dialogRef = this.dialog.open(CreateUserOtpComponent, {
panelClass: 'maarch-modal',
disableClose: true,
width: '500px',
});
dialogRef.afterClosed().pipe(
tap(async (data: any) => {
if (data) {
const user = {
item_id: null,
item_type: 'userOtp',
labelToDisplay: `${data.otp.firstname} ${data.otp.lastname}`,
picture: await this.actionService.getUserOtpIcon(data.otp.type),
hasPrivilege: true,
isValid: true,
role: data.otp.role,
externalId: {
maarchParapheur: null
},
externalInformations: data.otp
};
this.visaWorkflow.items.push(user);
}
})
).subscribe();
openCreateUserOtp(item: any = null) {
if (this.adminMode && (item === null || (item && item.item_id === null))) {
const objToSend: any = item === null || (item && item.item_id) !== null ? null : {
firstname: item.externalInformations.firstname,
lastname: item.externalInformations.lastname,
email: item.externalInformations.email,
phone: item.externalInformations.phone,
security: item.externalInformations.security,
sourceId: item.externalInformations.sourceId,
type: item.externalInformations.type,
role: item.role,
availableRoles: item.externalInformations.availableRoles
};
const dialogRef = this.dialog.open(CreateUserOtpComponent, {
panelClass: 'maarch-modal',
disableClose: true,
width: '500px',
data: objToSend
});
dialogRef.afterClosed().pipe(
tap(async (data: any) => {
if (data) {
const user = {
item_id: null,
item_type: 'userOtp',
labelToDisplay: `${data.otp.firstname} ${data.otp.lastname}`,
picture: await this.actionService.getUserOtpIcon(data.otp.type),
hasPrivilege: true,
isValid: true,
externalId: {
maarchParapheur: null
},
externalInformations: data.otp,
role: data.otp.role,
availableRoles: data.otp.availableRoles
};
if (objToSend !== null) {
this.visaWorkflow.items[this.visaWorkflow.items.indexOf(item)] = user;
this.notify.success(this.translate.instant('lang.modificationSaved'));
} else {
this.visaWorkflow.items.push(user);
}
}
})
).subscribe();
}
}
getOtpConfig() {
......
......@@ -2506,7 +2506,7 @@
"clientSecret": "Client Secret",
"siteUrl": "Sharepoint Online site URL",
"office365sharepointDesc": "<a href=\"https://www.office.com/\" target=\"_blank\"> Office 365 </a> is the online office suite from Microsoft. The editing is done via Sharepoint Online.",
"addOtpUser": "Add OTP user",
"addOtp": "Add external user",
"securityMode": "Mode of sending the security code",
"sms": "SMS",
"securityModeInfo": "The user will be notified by <b>email</b> and will receive a <b> security code </b> by <b> {{mode}} </b> at the time of his turn in the workflow.",
......
......@@ -982,7 +982,7 @@
"modelName": "Nom du modèle",
"modelSaved": "Modèle sauvegardé",
"modelUpdated": "Le modèle a été mis à jour",
"modificationSaved": "Modification enregistrée",
"modificationSaved": "Modification(s) enregistrée(s)",
"modified": "Modifiée",
"modifiedBy": "Modifié par",
"modifiedOn": "Modifié le",
......@@ -2497,7 +2497,7 @@
"clientSecret": "Client Secret",
"siteUrl": "URL de l'espace Sharepoint Online",
"office365sharepointDesc": "<a href=\"https://www.office.com/\" target=\"_blank\"> Office 365 </a> est la suite bureautique en ligne de Microsoft. L'édition se fait via Sharepoint Online.",
"addOtpUser": "Ajouter un utilisateur OTP",
"addOtp": "Ajouter un utilisateur externe",
"securityMode": "Mode d'envoi du code de sécurité",
"sms": "SMS",
"securityModeInfo": "L'utilisateur sera notifié par <b>courriel</b> et recevra un <b>code de sécurité</b> par <b>{{mode}}</b> au moment de son tour dans le circuit.",
......@@ -2505,5 +2505,6 @@
"youSign": "Yousign",
"otp_visa_yousign": "Viseur (yousign)",
"otp_sign_yousign": "Signataire (yousign)",
"source": "Source"
"source": "Source",
"updateOtp": "Modifier l'utilisateur externe"
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment