From 3f655a03eca5e88946506cf49820aa0ead7be0a8 Mon Sep 17 00:00:00 2001
From: Jean-Laurent DUZANT <jean-laurent.duzant@xelians.fr>
Date: Wed, 22 Mar 2023 12:21:32 +0100
Subject: [PATCH] FIX #24074 TIME 0:10 rollback to 'get repo link dynamically
 from BACK'

---
 rest/index.php                                |  3 ++-
 .../controllers/AuthenticationController.php  | 21 +++++++++++++++++++
 .../app/home/aboutUs/about-us.component.ts    | 21 ++++++++++++-------
 3 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/rest/index.php b/rest/index.php
index 6fc30fccd4..a5263adfc8 100755
--- a/rest/index.php
+++ b/rest/index.php
@@ -94,7 +94,8 @@ $app->patch('/configurations/{id}', \Configuration\controllers\ConfigurationCont
 $app->delete('/configurations/{id}', \Configuration\controllers\ConfigurationController::class . ':delete');
 $app->get('/configurations/{id}/connection', \Configuration\controllers\ConfigurationController::class . ':testConnection');
 
-// CommitInformation
+// GitInformation
+$app->get('/repoInformation', \SrcCore\controllers\AuthenticationController::class . ':getGitRepoInformation');
 $app->get('/commitInformation', \SrcCore\controllers\AuthenticationController::class . ':getGitCommitInformation');
 
 //Connectors
diff --git a/src/core/controllers/AuthenticationController.php b/src/core/controllers/AuthenticationController.php
index a8256349f1..bf67b18007 100755
--- a/src/core/controllers/AuthenticationController.php
+++ b/src/core/controllers/AuthenticationController.php
@@ -556,6 +556,27 @@ class AuthenticationController
         return true;
     }
 
+    public function getGitRepoInformation(Request $request, Response $response)
+    {
+        if (!file_exists('package.json')) {
+            return $response->withJson(['url' => null]);
+        }
+
+        $license = json_decode(file_get_contents('package.json'), true);
+
+        if (empty($license) || empty($license['license'])) {
+            return $response->withJson(['url' => null]);
+        }
+
+        if ($license['license'] == "GPL-3.0") {
+            return $response->withJson(['url' => "https://labs.maarch.org/maarch/MaarchParapheur"]);
+        } elseif (strtolower($license['license']) == "maarch") {
+            return $response->withJson(['url' => "https://labs.maarch.org/maarch/MaarchParapheurPro"]);
+        } else {
+            return $response->withJson(['url' => null]);
+        }
+    }
+
     public function getGitCommitInformation(Request $request, Response $response)
     {
         if (!file_exists('.git/HEAD')) {
diff --git a/src/frontend/app/home/aboutUs/about-us.component.ts b/src/frontend/app/home/aboutUs/about-us.component.ts
index 4bf180906b..96fbf1b3a7 100644
--- a/src/frontend/app/home/aboutUs/about-us.component.ts
+++ b/src/frontend/app/home/aboutUs/about-us.component.ts
@@ -79,7 +79,7 @@ export class AboutUsComponent implements OnInit {
         this.license = environment.LICENSE;
         this.currentYear = new Date().getFullYear();
         await this.loadCommitInformation();
-        this.repoUrl = this.getGitRepoLink();
+        await this.getGitRepoLink();
         this.loading = false;
     }
 
@@ -99,12 +99,17 @@ export class AboutUsComponent implements OnInit {
     }
 
     getGitRepoLink() {
-        if (this.license === 'GPL-3.0') {
-            return 'https://labs.maarch.org/maarch/MaarchParapheur';
-        } else if (this.license === 'MAARCH') {
-            return 'https://labs.maarch.org/maarch/MaarchParapheurPro';
-        } else {
-            return null;
-        }
+        return new Promise((resolve) => {
+            this.http.get('../rest/repoInformation').pipe(
+                tap((data: any) => {
+                    this.repoUrl = data.url !== null ? data.url : this.translate.instant('lang.undefined');
+                    resolve(true);
+                }),
+                catchError((err: any) => {
+                    this.notify.handleErrors(err);
+                    return of(false);
+                })
+            ).subscribe();
+        });
     }
 }
-- 
GitLab