From 2edea2e25b5f524ed90b8ca2193a002db8123d10 Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Thu, 27 Oct 2022 16:26:47 +0200
Subject: [PATCH] FEAT #21979 TIME 2 auto close and open for refresh certs

---
 lang/fr.json                                  |  4 +--
 .../app/document/document.component.ts        | 31 ++++++++++++-------
 .../signature-method-modal.component.html     |  2 +-
 .../signature-method-modal.component.ts       |  8 +++--
 4 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/lang/fr.json b/lang/fr.json
index b1ce5ed2c3..3d7c3c12a9 100755
--- a/lang/fr.json
+++ b/lang/fr.json
@@ -665,7 +665,7 @@
 		"cannotAcces": "Impossible d'accéder au document",
 		"softDeleted": "Marqué comme supprimé",
 		"hardDeleted":"Fichiers supprimés",
-		"inputCardReaderUpdateCerts": "Une entrée de carte détectée, veuillez mettre à jour vos certificats",
-		"outputCardReaderUpdateCerts": "Une sortie de carte détectée, veuillez mettre à jour vos certificats"
+		"inputCardReaderUpdateCerts": "Une entrée de carte détectée, actualisation des certificats...",
+		"outputCardReaderUpdateCerts": "Une sortie de carte détectée, actualisation des certificats..."
 	}
 }
diff --git a/src/frontend/app/document/document.component.ts b/src/frontend/app/document/document.component.ts
index 99d0490b9d..823c33e785 100755
--- a/src/frontend/app/document/document.component.ts
+++ b/src/frontend/app/document/document.component.ts
@@ -635,18 +635,7 @@ export class DocumentComponent implements OnInit, OnDestroy {
                 {
                     text: this.getLabel(event),
                     handler: async (data: any) => {
-                        const currentUserWorkflow = this.mainDocument.workflow.filter((line: { current: boolean }) => line.current === true)[0];
-                        const idsToProcess = await this.actionsService.checkGroupMail(this.mainDocument, 'validate');
-                        const res = await this.signatureMethodService.checkAuthenticationAndLaunchAction(currentUserWorkflow, data.paragraph, idsToProcess);
-
-                        if (!this.functionsService.empty(res)) {
-                            const config: MatBottomSheetConfig = {
-                                disableClose: true,
-                                direction: 'ltr'
-                            };
-                            this.bottomSheet.open(SuccessInfoValidBottomSheetComponent, config);
-                            this.localStorage.remove(this.mainDocument.id.toString());
-                        }
+                        await this.processToSign(data);
                     }
                 }
             ]
@@ -655,6 +644,24 @@ export class DocumentComponent implements OnInit, OnDestroy {
         await alert.present();
     }
 
+    async processToSign(data: any) {
+        const currentUserWorkflow = this.mainDocument.workflow.filter((line: { current: boolean }) => line.current === true)[0];
+        const idsToProcess = await this.actionsService.checkGroupMail(this.mainDocument, 'validate');
+        const res = await this.signatureMethodService.checkAuthenticationAndLaunchAction(currentUserWorkflow, data.paragraph, idsToProcess);
+        if (!this.functionsService.empty(res)) {
+            if (res === 'refresh_certs') {
+                this.processToSign(data);
+            } else {
+                const config: MatBottomSheetConfig = {
+                    disableClose: true,
+                    direction: 'ltr'
+                };
+                this.bottomSheet.open(SuccessInfoValidBottomSheetComponent, config);
+                this.localStorage.remove(this.mainDocument.id.toString());
+            }
+        }
+    }
+
     async removeTags() {
         this.signaturesService.currentAction = 0;
 
diff --git a/src/frontend/app/service/signature-method/signature-method-modal.component.html b/src/frontend/app/service/signature-method/signature-method-modal.component.html
index b779d18068..4628f0e3c7 100644
--- a/src/frontend/app/service/signature-method/signature-method-modal.component.html
+++ b/src/frontend/app/service/signature-method/signature-method-modal.component.html
@@ -1,4 +1,4 @@
 <ion-content>
-    <peculiar-fortify-certificates style="height: 100%;width: 100%;" language="fr" [filters]="filters"
+    <peculiar-fortify-certificates *ngIf="!loading" style="height: 100%;width: 100%;" language="fr" [filters]="filters"
         (selectionSuccess)="certificateChosen($event)" (selectionCancel)="cancelSign()" hide-footer></peculiar-fortify-certificates>
 </ion-content>
diff --git a/src/frontend/app/service/signature-method/signature-method-modal.component.ts b/src/frontend/app/service/signature-method/signature-method-modal.component.ts
index ae46867041..b51e894b57 100644
--- a/src/frontend/app/service/signature-method/signature-method-modal.component.ts
+++ b/src/frontend/app/service/signature-method/signature-method-modal.component.ts
@@ -87,6 +87,7 @@ export class SignatureMethodModalComponent implements OnInit, OnDestroy {
         if (challenge) {
             await this.api.login();
         }
+        this.updateProvider(null);
         this.api.server.cardReader
             .on('insert', (event: any) => this.updateProvider(event))
             .on('remove', (event: any) => this.updateProvider(event));
@@ -142,15 +143,16 @@ export class SignatureMethodModalComponent implements OnInit, OnDestroy {
     async updateProvider(event: any) {
         const info = await this.api.server.info();
         for (const provider of info.providers) {
-            console.log('Provider:' + provider.id + ', name=' + provider.name + ', atr=' + provider.atr);
             const crypto = await this.api.server.getCrypto(provider.id);
             await crypto.reset();
         }
 
-        if (!this.functionsService.empty(event.action) && event.action.includes('insert')) {
+        if (!this.functionsService.empty(event?.action) && event?.action.includes('insert')) {
             this.notificationService.message('lang.inputCardReaderUpdateCerts');
-        } else if (!this.functionsService.empty(event.action) && event.action.includes('remove')) {
+            this.modalController.dismiss('refresh_certs');
+        } else if (!this.functionsService.empty(event?.action) && event?.action.includes('remove')) {
             this.notificationService.message('lang.outputCardReaderUpdateCerts');
+            this.modalController.dismiss('refresh_certs');
         }
     }
 
-- 
GitLab