From 9e7593a82138c148515ac1d38a8fff102ffce6c1 Mon Sep 17 00:00:00 2001
From: Guillaume WEBER <gweber@takima.fr>
Date: Wed, 10 Aug 2022 08:02:05 +0000
Subject: [PATCH] feat: inform user before asking for connexion

---
 .../deadlock-extension/src/core/api.service.ts    |  5 +++--
 .../deadlock-extension/src/core/controller.ts     | 15 +++++++++++++--
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/deadlock-plugins/deadlock-extension/src/core/api.service.ts b/deadlock-plugins/deadlock-extension/src/core/api.service.ts
index b3621800..703db95c 100644
--- a/deadlock-plugins/deadlock-extension/src/core/api.service.ts
+++ b/deadlock-plugins/deadlock-extension/src/core/api.service.ts
@@ -113,8 +113,9 @@ export default class ApiService {
 
   private async onInvalidRefreshToken(originalConfig) {
     try {
-      await Controller.instance.authenticate();
-      return this.axiosInstance(originalConfig);
+      if (await Controller.instance.userAuthenticateMessage('Vous avez été déconnecté. Se reconnecter ?')) {
+        return this.axiosInstance(originalConfig);
+      }
     } catch (_error) {
       return Promise.reject(_error);
     }
diff --git a/deadlock-plugins/deadlock-extension/src/core/controller.ts b/deadlock-plugins/deadlock-extension/src/core/controller.ts
index 2a34a89d..70082bee 100644
--- a/deadlock-plugins/deadlock-extension/src/core/controller.ts
+++ b/deadlock-plugins/deadlock-extension/src/core/controller.ts
@@ -151,6 +151,16 @@ export default class Controller {
     AuthenticationView.instance.isAlreadyConnected = true;
   }
 
+  public async userAuthenticateMessage(message: string): Promise<boolean> {
+    const answer = await window.showInformationMessage(message, { modal: true }, 'Connexion');
+    if (answer === 'Connexion') {
+      await this.authenticate();
+      return true;
+    } else {
+      return false;
+    }
+  }
+
   public static openBrowserWithUrl(url: string) {
     commands.executeCommand(CommandHandler.instance.openUrlInBrowserCommand.command, Uri.parse(url));
   }
@@ -171,8 +181,9 @@ export default class Controller {
     const hadBeenConnected = (await ExtensionStore.instance.getAccessToken()) !== undefined;
 
     if (!hadBeenConnected) {
-      await this.authenticate();
-      window.showInformationMessage('Connexion validée');
+      if (await this.userAuthenticateMessage('Connectez-vous avant de commencer la mission.')) {
+        window.showInformationMessage('Connexion validée');
+      } else return;
     }
 
     const reviewer = await ApiService.instance.getCurrentUser();
-- 
GitLab