From 600f43f7ca96d3b5697796d556372a35404b3ada Mon Sep 17 00:00:00 2001
From: "hamza.hramchi" <hamza.hramchi@xelians.fr>
Date: Fri, 21 May 2021 15:58:11 +0200
Subject: [PATCH] FEAT #16982 TIME 1 add button to modify external user +
 translate + fix error when move user

---
 lang/en.json                                           | 10 +++++++++-
 lang/fr.json                                           |  5 +++--
 .../visa-workflow/visa-workflow.component.html         | 10 +++++++---
 .../document/visa-workflow/visa-workflow.component.ts  |  6 ++++--
 4 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/lang/en.json b/lang/en.json
index 828cb8aa76..9b69bc1de7 100755
--- a/lang/en.json
+++ b/lang/en.json
@@ -503,6 +503,14 @@
         "connectorIsUsed": "{{number}} visa workflow currently use this connector.<br>If you continue, these workflows will be interrupted.",
         "connectorNotUsed": "This connector is not used",
         "newTemplateDescWithOtp": "The current workflow will be saved without taking into account the external users.",
-        "otpUser": "External user"
+        "otpUser": "External user",
+        "accessLink": "Access link",
+        "recipientLastname": "Recipient's name",
+        "recipientFirstname": "Recipient's first name",
+        "expiresAt": "Expiration date",
+        "mergedVariablesMsg": "Use tag",
+        "mergedVariablesMsg2": "to display the generated security code.",
+        "mergedVariablesMsgEmail": "You can use the different tags below to enrich your email",
+        "updateOtp": "Update external user"
     }
 }
\ No newline at end of file
diff --git a/lang/fr.json b/lang/fr.json
index 11ed9a2938..3fd4c965f7 100755
--- a/lang/fr.json
+++ b/lang/fr.json
@@ -474,7 +474,7 @@
 		"mailServerOfflineMsg": "Le serveur de messagerie doit être <b>testé</b> et <b>opérationnel</b> pour : <b>{{action}}</b>",
 		"testAndValidate": "Tester et valider",
 		"receiveActivationNotification": "Recevoir le courriel d'activation",
-		"newOtp": "Ajouter un OTP",
+		"newOtp": "Ajouter un utilisateur externe",
 		"otpUser": "Utilisateur externe",
 		"securityCodeSendMode": "Mode d'envoi du code de sécurité",
 		"phoneAlt": "Mobile",
@@ -508,6 +508,7 @@
 		"expiresAt": "Date d'expiration",
 		"mergedVariablesMsg": "Utiliser la balise",
 		"mergedVariablesMsg2": "pour afficher le code de sécurité généré.",
-		"mergedVariablesMsgEmail": "Vous pouvez utiliser les différentes balises ci-dessous pour enrichir votre e-mail"
+		"mergedVariablesMsgEmail": "Vous pouvez utiliser les différentes balises ci-dessous pour enrichir votre e-mail",
+		"updateOtp": "Modifier l'utilisateur externe"
 	}
 }
diff --git a/src/frontend/app/document/visa-workflow/visa-workflow.component.html b/src/frontend/app/document/visa-workflow/visa-workflow.component.html
index c2c8c79b21..af899c7c83 100644
--- a/src/frontend/app/document/visa-workflow/visa-workflow.component.html
+++ b/src/frontend/app/document/visa-workflow/visa-workflow.component.html
@@ -43,7 +43,7 @@
                             </ion-button>
                         </ion-buttons>
                     </ion-item>
-                    <ion-item button (click)="createModel()" [disabled]="visaWorkflow.length === 0">
+                    <ion-item button (click)="createModel()" [disabled]="visaWorkflow.length === 0 || notExternalUsers.length === 0">
                         <ion-label style="font-size: 14px;">{{'lang.newTemplate' | translate}}</ion-label>
                     </ion-item>
                 </mat-menu>
@@ -70,7 +70,7 @@
             <ion-reorder slot="start">
                 <ion-icon [title]="'lang.reorder' | translate" name="reorder-three" style="font-size: 30px;"></ion-icon>
             </ion-reorder>
-            <ion-avatar slot="start" class="avatar-user" style="cursor: grab;" (click)="$event.stopPropagation(); openOtpModal(diffusion)">
+            <ion-avatar slot="start" class="avatar-user" style="cursor: grab;" (click)="$event.stopPropagation();">
                 <img [src]="diffusion.userPicture">
             </ion-avatar>
             <ion-label>
@@ -80,7 +80,7 @@
                 <h2 [title]="diffusion.userDisplay" class="danger" *ngIf="diffusion.userDisplay === ''">
                     {{'lang.userDeleted' | translate}}</h2>
                 <p *ngIf="diffusion.processDate === null" style="display: flex;justify-content: start;">
-                    <ion-select [(ngModel)]="diffusion.role" [title]="'lang.' + diffusion.role + 'User' | translate"
+                    <ion-select [(ngModel)]="diffusion.role" [title]="diffusion.userDisplay"
                         interface="popover" [interfaceOptions]="customPopoverOptions"
                         [style.color]="getRole(diffusion.role)?.color" [disabled]="!editMode"
                         style="width: auto;max-width: 100%;padding-left:0px;">
@@ -108,6 +108,10 @@
             <ion-icon *ngIf="!editMode && diffusion.current" color="success" slot="end" name="caret-back-outline">
             </ion-icon>
             <ion-buttons slot="end">
+                <ion-button style="z-index: 9999" *ngIf="editMode && diffusion.userId === null" fill="clear" slot="icon-only" shape="round"
+                    color="primary" (click)="$event.stopPropagation(); openOtpModal(diffusion)" [title]="'lang.updateOtp' | translate">
+                    <ion-icon name="create-outline"></ion-icon>
+                </ion-button>
                 <ion-button style="z-index: 9999" *ngIf="editMode" fill="clear" slot="icon-only" shape="round"
                     color="danger" (click)="$event.stopPropagation();removeUser(i)">
                     <ion-icon slot="icon-only" name="trash-outline"></ion-icon>
diff --git a/src/frontend/app/document/visa-workflow/visa-workflow.component.ts b/src/frontend/app/document/visa-workflow/visa-workflow.component.ts
index 4fbf3cbef2..fd13fa2139 100644
--- a/src/frontend/app/document/visa-workflow/visa-workflow.component.ts
+++ b/src/frontend/app/document/visa-workflow/visa-workflow.component.ts
@@ -33,7 +33,7 @@ export class VisaWorkflowComponent implements OnInit {
     };
     roles: any[] = [];
     visaWorkflowModels: any[] = [];
-
+    notExternalUsers: any[] = [];
     hasConnector: boolean = false;
 
     constructor(
@@ -67,7 +67,8 @@ export class VisaWorkflowComponent implements OnInit {
     }
 
     canMoveUser(ev: CustomEvent<ItemReorderEventDetail>) {
-        const newWorkflow = this.array_move(this.visaWorkflow.slice(), ev.detail.from, ev.detail.to);
+        let newWorkflow = this.array_move(this.visaWorkflow.slice(), ev.detail.from, ev.detail.to);
+        newWorkflow = newWorkflow.filter((item: any) => item !== undefined);
         const res = this.isValidWorkflow(newWorkflow);
         return res;
     }
@@ -357,6 +358,7 @@ export class VisaWorkflowComponent implements OnInit {
         this.http.get('../rest/workflowTemplates').pipe(
             tap((data: any) => {
                 this.visaWorkflowModels = data.workflowTemplates;
+                this.notExternalUsers = this.visaWorkflow.filter((user: any) => user.userId !== null);
             }),
             catchError(err => {
                 this.notificationService.handleErrors(err);
-- 
GitLab