From e8513c416e82d6195f50e6fa64d07fb7d35021f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Huchet?= Date: Mon, 5 Feb 2024 10:38:52 +0100 Subject: [PATCH 1/3] fix: on rend l'application mano inaccessible --- api/src/middleware/versionCheck.js | 60 +++++++++++++++--------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/api/src/middleware/versionCheck.js b/api/src/middleware/versionCheck.js index 3720b0e27..e8821be4f 100644 --- a/api/src/middleware/versionCheck.js +++ b/api/src/middleware/versionCheck.js @@ -1,39 +1,39 @@ -const { VERSION, MINIMUM_DASHBOARD_VERSION } = require("../config"); +const { QueryTypes } = require("sequelize"); +const { sequelize } = require("../db/sequelize"); -const MINIMUM_MOBILE_APP_VERSION = [2, 37, 0]; +let deploymentCommit = null; +let deploymentDate = null; -module.exports = ({ headers: { version, platform } }, res, next) => { +module.exports = async ({ headers: { version, platform } }, res, next) => { if (platform === "website") return next(); if (platform === "dashboard") { - // Add header with API version to compare with client. - res.header("X-API-VERSION", VERSION); - res.header("X-MINIMUM-DASHBOARD-VERSION", MINIMUM_DASHBOARD_VERSION); + if (deploymentCommit === null) { + try { + const [deployment] = await sequelize.query(`select commit, "createdAt" from mano."Deployment" order by "createdAt" desc limit 1`, { + type: QueryTypes.SELECT, + }); + if (deployment) { + deploymentCommit = deployment.commit; + deploymentDate = deployment.createdAt.toISOString(); + } + } catch (e) { + console.error(e); + } + } + console.log(deploymentDate, typeof deploymentDate); + res.header("X-API-DEPLOYMENT-COMMIT", deploymentCommit); + res.header("X-API-DEPLOYMENT-DATE", deploymentDate); // See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers - res.header("Access-Control-Expose-Headers", "X-API-VERSION, X-MINIMUM-DASHBOARD-VERSION"); + res.header("Access-Control-Expose-Headers", "X-API-DEPLOYMENT-COMMIT, X-API-DEPLOYMENT-DATE"); return next(); } - // now platform is react native app - if (!version) return res.status(403).send({ ok: false, message: "Veuillez mettre à jour votre application!" }); - - const appVer = version.split(".").map((d) => parseInt(d)); - - for (let i = 0; i < 3; i++) { - if (appVer[i] > MINIMUM_MOBILE_APP_VERSION[i]) { - return next(); - } else if (appVer[i] < MINIMUM_MOBILE_APP_VERSION[i]) { - return res.status(403).send({ - ok: false, - message: "Veuillez mettre à jour votre application!", - inAppMessage: [ - `Veuillez mettre à jour votre application\u00A0!`, - `Les fonctionnalités de cette nouvelle version sont\u00A0: -- Compatibilité de l 'historique des actions, consultations, traitements et dossier médical (seulement consultable sur navigateur)`, - [{ text: "Télécharger la dernière version", link: `https://mano-app.fabrique.social.gouv.fr/download?ts=${Date.now()}` }], - ], - }); - } - } - - next(); + // On doit forcer les utilisateurs à télécharger à nouveau Mano + return res.status(403).send({ + ok: false, + message: "Veuillez mettre à jour votre application!", + inAppMessage: [ + `Mano a quitté la fabrique pour rejoindre le groupement d'intérêt public SESAN. Pour continuer à utiliser Mano, vous devez mettre à jour votre application mobile.`, + ], + }); }; From 9cba053face633c0d06fa42759aa6cd231703813 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Huchet?= Date: Mon, 5 Feb 2024 10:40:51 +0100 Subject: [PATCH 2/3] Update versionCheck.js --- api/src/middleware/versionCheck.js | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/api/src/middleware/versionCheck.js b/api/src/middleware/versionCheck.js index e8821be4f..e271e03ff 100644 --- a/api/src/middleware/versionCheck.js +++ b/api/src/middleware/versionCheck.js @@ -1,30 +1,15 @@ -const { QueryTypes } = require("sequelize"); -const { sequelize } = require("../db/sequelize"); +const { VERSION, MINIMUM_DASHBOARD_VERSION } = require("../config"); -let deploymentCommit = null; -let deploymentDate = null; +const MINIMUM_MOBILE_APP_VERSION = [2, 37, 0]; -module.exports = async ({ headers: { version, platform } }, res, next) => { +module.exports = ({ headers: { version, platform } }, res, next) => { if (platform === "website") return next(); if (platform === "dashboard") { - if (deploymentCommit === null) { - try { - const [deployment] = await sequelize.query(`select commit, "createdAt" from mano."Deployment" order by "createdAt" desc limit 1`, { - type: QueryTypes.SELECT, - }); - if (deployment) { - deploymentCommit = deployment.commit; - deploymentDate = deployment.createdAt.toISOString(); - } - } catch (e) { - console.error(e); - } - } - console.log(deploymentDate, typeof deploymentDate); - res.header("X-API-DEPLOYMENT-COMMIT", deploymentCommit); - res.header("X-API-DEPLOYMENT-DATE", deploymentDate); + // Add header with API version to compare with client. + res.header("X-API-VERSION", VERSION); + res.header("X-MINIMUM-DASHBOARD-VERSION", MINIMUM_DASHBOARD_VERSION); // See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers - res.header("Access-Control-Expose-Headers", "X-API-DEPLOYMENT-COMMIT, X-API-DEPLOYMENT-DATE"); + res.header("Access-Control-Expose-Headers", "X-API-VERSION, X-MINIMUM-DASHBOARD-VERSION"); return next(); } From 9ac5aea58af469a4f0ad5609baa4aef08a13d12d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Huchet?= Date: Mon, 5 Feb 2024 10:46:14 +0100 Subject: [PATCH 3/3] Update versionCheck.js --- api/src/middleware/versionCheck.js | 1 + 1 file changed, 1 insertion(+) diff --git a/api/src/middleware/versionCheck.js b/api/src/middleware/versionCheck.js index e271e03ff..f6061c125 100644 --- a/api/src/middleware/versionCheck.js +++ b/api/src/middleware/versionCheck.js @@ -19,6 +19,7 @@ module.exports = ({ headers: { version, platform } }, res, next) => { message: "Veuillez mettre à jour votre application!", inAppMessage: [ `Mano a quitté la fabrique pour rejoindre le groupement d'intérêt public SESAN. Pour continuer à utiliser Mano, vous devez mettre à jour votre application mobile.`, + [{ text: "Télécharger la dernière version", link: `https://mano.sesan.fr/download?ts=${Date.now()}` }], ], }); };