From 8a2d48227249df78b57258e178e42d45c69d2fb6 Mon Sep 17 00:00:00 2001
From: "hamza.hramchi" <hamza.hramchi@xelians.fr>
Date: Wed, 26 May 2021 14:40:14 +0200
Subject: [PATCH] FEAT #16982 TIME 3:20 check the existence of the connector
 after the action: return the document

---
 lang/fr.json                                  |  3 ++-
 .../otps/yousign/otp-yousign.component.html   |  2 +-
 .../otps/yousign/otp-yousign.component.ts     |  2 +-
 .../visa-workflow.component.html              |  7 ++++---
 .../visa-workflow.component.scss              |  5 +++++
 .../visa-workflow/visa-workflow.component.ts  | 15 ++++++++++++---
 .../app/indexation/indexation.component.ts    | 19 ++++++++++++-------
 7 files changed, 37 insertions(+), 16 deletions(-)

diff --git a/lang/fr.json b/lang/fr.json
index b114e041b5..125621ba12 100755
--- a/lang/fr.json
+++ b/lang/fr.json
@@ -515,6 +515,7 @@
 		"manage_customization": "Personnalisation",
 		"manage_customizationDesc": "Personnaliser le message à l'écran de connexion",
 		"loginMessage": "Message à l'écran de connexion :",
-		"customization": "Personnalisation"
+		"customization": "Personnalisation",
+		"noConnector": "Le connecteur associé n'existe pas"
 	}
 }
diff --git a/src/frontend/app/document/visa-workflow/otps/yousign/otp-yousign.component.html b/src/frontend/app/document/visa-workflow/otps/yousign/otp-yousign.component.html
index 11d9944f37..e82f8e3bd5 100644
--- a/src/frontend/app/document/visa-workflow/otps/yousign/otp-yousign.component.html
+++ b/src/frontend/app/document/visa-workflow/otps/yousign/otp-yousign.component.html
@@ -12,7 +12,7 @@
         </ion-item>
         <ion-item>
             <ion-label color="secondary" position="floating">{{'lang.phoneAlt' | translate}} *</ion-label>
-            <ion-input name="phone" pattern="^((\+)33)[1-9](\d{2}){4}$" [(ngModel)]="otp.phone" placeholder="+33646342143" required></ion-input>
+            <ion-input name="phone" pattern="^((\+)33)[1-9](\d{2}){4}$" (keyup)="formatPhone()" [(ngModel)]="otp.phone" placeholder="+33646342143" required></ion-input>
         </ion-item>
         <ion-item>
             <ion-label color="secondary" position="floating">{{'lang.email' | translate}} *
diff --git a/src/frontend/app/document/visa-workflow/otps/yousign/otp-yousign.component.ts b/src/frontend/app/document/visa-workflow/otps/yousign/otp-yousign.component.ts
index 2898d53bd3..58481f79d9 100644
--- a/src/frontend/app/document/visa-workflow/otps/yousign/otp-yousign.component.ts
+++ b/src/frontend/app/document/visa-workflow/otps/yousign/otp-yousign.component.ts
@@ -84,7 +84,7 @@ export class OtpYousignComponent implements OnInit {
         return this.otpForm.valid;
     }
 
-    formatPhone(ev: any) {
+    formatPhone() {
         if (this.otp.phone.length > 1 && this.otp.phone[0] === '0') {
             this.otp.phone = this.otp.phone.replace('0', '+33');
         }
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 a8342ff82c..52d241b888 100644
--- a/src/frontend/app/document/visa-workflow/visa-workflow.component.html
+++ b/src/frontend/app/document/visa-workflow/visa-workflow.component.html
@@ -76,10 +76,10 @@
             <ion-label>
                 <p class="secondary" *ngIf="diffusion.current && (diffusion.userId !== null && diffusion.userId !== authService.user.id)">
                     {{'lang.substituteMsg' | translate}}</p>
-                <h2 [title]="diffusion.userDisplay" *ngIf="diffusion.userDisplay !== ''">{{diffusion.userDisplay}}</h2>
+                <h2 [class.interrupt]="diffusion.noConnector !== undefined && diffusion.noConnector === true" [title]="diffusion.userDisplay" *ngIf="diffusion.userDisplay !== ''">{{diffusion.userDisplay}}</h2>
                 <h2 [title]="diffusion.userDisplay" class="danger" *ngIf="diffusion.userDisplay === ''">
                     {{'lang.userDeleted' | translate}}</h2>
-                <p *ngIf="diffusion.processDate === null" style="display: flex;justify-content: start;">
+                <p *ngIf="diffusion.noConnector === undefined && diffusion.processDate === null" style="display: flex;justify-content: start;">
                     <ion-select [(ngModel)]="diffusion.role" [title]="diffusion.userDisplay"
                         interface="popover" [interfaceOptions]="customPopoverOptions"
                         [style.color]="getRole(diffusion.role)?.color" [disabled]="!editMode"
@@ -104,11 +104,12 @@
                         {{diffusion.processDate}}
                     </ion-note>
                 </p>
+                <ion-note *ngIf="diffusion.noConnector !== undefined && diffusion.noConnector === true" style="color: red; font-size: 10px;">{{ 'lang.noConnector' | translate }}</ion-note>
             </ion-label>
             <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"
+                <ion-button style="z-index: 9999" *ngIf="editMode && diffusion.userId === null && hasConnector" 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>
diff --git a/src/frontend/app/document/visa-workflow/visa-workflow.component.scss b/src/frontend/app/document/visa-workflow/visa-workflow.component.scss
index 20b4531c56..1f0ca938d3 100644
--- a/src/frontend/app/document/visa-workflow/visa-workflow.component.scss
+++ b/src/frontend/app/document/visa-workflow/visa-workflow.component.scss
@@ -62,3 +62,8 @@ ion-select {
     padding-bottom: 10px;
 }
 
+.interrupt {
+    color: var(--ion-color-danger);
+    text-decoration: line-through;
+}
+
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 8775c73a7a..ce40212515 100644
--- a/src/frontend/app/document/visa-workflow/visa-workflow.component.ts
+++ b/src/frontend/app/document/visa-workflow/visa-workflow.component.ts
@@ -273,7 +273,8 @@ export class VisaWorkflowComponent implements OnInit {
             this.http.get('../rest/connectors').pipe(
                 tap((data: any) => {
                     this.hasConnector = data.otp.length > 0 ? true : false;
-                    resolve(true);
+                    const connectorIds: any[] = data.otp.map((connector: any) => connector.id)
+                    resolve(connectorIds);
                 }),
                 catchError(err => {
                     this.notificationService.handleErrors(err);
@@ -302,11 +303,11 @@ export class VisaWorkflowComponent implements OnInit {
             });
     }
 
-    formatData(item: any) {
+    async formatData(item: any) {
         if (item.externalInformations) {
             item.role = item.role === 'stamp' ? 'sign' : item.role;
             return new Promise(async (resolve) => {
-                const objToSend: any = {
+                let objToSend: any = {
                     otp: {
                         firstname: item.externalInformations.firstname,
                         lastname: item.externalInformations.lastname,
@@ -326,6 +327,14 @@ export class VisaWorkflowComponent implements OnInit {
                     current: false,
                     modes: ['visa', 'sign'],
                 };
+                const connectorIds: any = await this.getConnectors();
+                if (connectorIds.indexOf(objToSend.otp.sourceId) === -1) {
+                    objToSend.otp.sourceId = connectorIds[0];
+                    objToSend = {
+                        ... objToSend,
+                        noConnector: true
+                    }
+                }
                 this.visaWorkflow[this.visaWorkflow.indexOf(item)] = objToSend;
                 resolve(objToSend);
             });
diff --git a/src/frontend/app/indexation/indexation.component.ts b/src/frontend/app/indexation/indexation.component.ts
index 7c084453d1..68a36dd6da 100644
--- a/src/frontend/app/indexation/indexation.component.ts
+++ b/src/frontend/app/indexation/indexation.component.ts
@@ -95,6 +95,14 @@ export class IndexationComponent implements OnInit {
                     for (let index = 0; index < data.document.attachments.length; index++) {
                         this.getAttachment(data.document.attachments[index].id);
                     }
+
+                    const externalUsers: any[] = this.appVisaWorkflow.getCurrentWorkflow().filter((user: any) => user.userId === null);
+                    if (externalUsers.length > 0) {
+                        externalUsers.forEach(async (element: any) => {
+                            const obj: any = await this.appVisaWorkflow.formatData(element);
+                            element = obj;
+                        });
+                    }                    
                     resolve(true);
                 }),
                 catchError((err: any) => {
@@ -144,13 +152,6 @@ export class IndexationComponent implements OnInit {
     }
 
     onSubmit() {
-        const externalUsers: any[] = this.appVisaWorkflow.getCurrentWorkflow().filter((user: any) => user.userId === null);
-        if (externalUsers.length > 0) {
-            externalUsers.forEach(async (element: any) => {
-                const obj: any = await this.appVisaWorkflow.formatData(element);
-                element = obj;
-            });
-        }
         if (this.isValid()) {
             this.promptSaveDoc();
         }
@@ -378,6 +379,10 @@ export class IndexationComponent implements OnInit {
             this.notificationService.error('lang.workflowUserstMandatory');
             this.menu.open('right-menu');
             return false;
+        } 
+        else if (this.appVisaWorkflow.getCurrentWorkflow().filter((user: any) => user.userId === null && user.noConnector !== undefined).length > 0) {
+            this.notificationService.error('lang.noConnector');
+            return false;
         } else {
             return true;
         }
-- 
GitLab