diff --git a/images/falc-generator.png b/images/falc-generator.png index b45b75a..ee112b8 100644 Binary files a/images/falc-generator.png and b/images/falc-generator.png differ diff --git a/index.html b/index.html index b22456d..6265c55 100644 --- a/index.html +++ b/index.html @@ -73,11 +73,13 @@ function isOffline(app) { return app.status === 'offline' || app.status === 'error' || app.containerRunning === false; } function getPortalOnlyApps() { if (!PORTAL || PORTAL.env !== 'prod' || PORTAL.group !== 'SANTELIS') return []; return PORTAL_ONLY_APPS.filter(function(app) { return isHttpsUrl(app.urls && app.urls[PORTAL.env]); }); } function isAppInCurrentPortal(app) { if (!PORTAL || !app || !isHttpsUrl(app.urls && app.urls[PORTAL.env])) return false; if (app.id === 'santelis-gestion' || app.id === 'portail-santinova') return false; if (PORTAL.group === 'SANTINOVA') return app.category === 'SANTINOVA' || app.category === 'INFRA'; return app.category === PORTAL.group; } + /* Le Dashboard doit fournir des identifiants uniques ; le portail les protège aussi afin qu’un inventaire transitoirement erroné ne duplique jamais une tuile. */ + function uniqueAppsById(apps) { var seen = new Set(); return (Array.isArray(apps) ? apps : []).filter(function(app) { if (!app || typeof app.id !== 'string' || !app.id || seen.has(app.id)) return false; seen.add(app.id); return true; }); } function escapeHtml(value) { return String(value || '').replace(/[&<>'"]/g, function(character) { return ({ '&':'&', '<':'<', '>':'>', "'":''', '"':'"' })[character]; }); } function buildCard(app) { var url = app.urls && app.urls[PORTAL.env], image = APP_IMAGE_OVERRIDES[app.id] || app.image || ('images/' + app.id + '.png'), offline = isOffline(app); return '
' + escapeHtml(app.name) + '
' + escapeHtml(app.name) + '
' + PORTAL.envLabel + '
Hors ligne
'; } function renderPortalHubNavigation() { var navigation = document.getElementById('portal-hub-nav'); if (!PORTAL || PORTAL.group !== 'SANTINOVA') { navigation.innerHTML = ''; navigation.hidden = true; return; } navigation.innerHTML = 'Accès aux portails' + PORTAL_HUB_LINKS.map(function(portal) { return '' + portal.label + ''; }).join(''); navigation.hidden = false; } function setPortalIdentity() { document.documentElement.style.setProperty('--accent', PORTAL.accent); document.title = PORTAL.title + ' — Santinova Soft'; document.getElementById('portal-title').textContent = PORTAL.title; document.getElementById('portal-subtitle').textContent = 'Environnement de ' + PORTAL.envLabel.toLowerCase(); document.getElementById('environment-badge').textContent = PORTAL.envLabel; document.getElementById('entity-heading').firstChild.nodeValue = PORTAL.title; document.getElementById('entity-description').textContent = 'Applications déployées dans l’environnement ' + PORTAL.envLabel.toLowerCase() + '.'; renderPortalHubNavigation(); } - function renderApps(apps) { var visibleApps = apps.filter(isAppInCurrentPortal).concat(getPortalOnlyApps()), grid = document.getElementById('apps-grid'); grid.innerHTML = visibleApps.length ? visibleApps.map(buildCard).join('') : '
Aucune application déployée pour ce portail.
'; document.getElementById('app-count').textContent = visibleApps.length; hasRenderedApps = true; } + function renderApps(apps) { var visibleApps = uniqueAppsById(apps).filter(isAppInCurrentPortal).concat(getPortalOnlyApps()), grid = document.getElementById('apps-grid'); grid.innerHTML = visibleApps.length ? visibleApps.map(buildCard).join('') : '
Aucune application déployée pour ce portail.
'; document.getElementById('app-count').textContent = visibleApps.length; hasRenderedApps = true; } async function requestJson(url) { var controller = new AbortController(), timeoutId = setTimeout(function() { controller.abort(); }, 8000); try { var response = await fetch(url, { cache:'no-store', signal:controller.signal }); if (!response.ok) throw new Error('HTTP ' + response.status); return await response.json(); } finally { clearTimeout(timeoutId); } } async function fetchAndApplyStatuses() { try { var statuses = await requestJson(PORTAL.dashboardStatusUrl); if (!Array.isArray(statuses)) return; var byId = new Map(statuses.map(function(status) { return [status.id,status]; })); document.querySelectorAll('.app-card[data-app-id]').forEach(function(card) { var status = byId.get(card.getAttribute('data-app-id')); if (!status) return; var offline = isOffline(status); card.classList.toggle('offline', offline); card.setAttribute('aria-disabled', String(offline)); }); } catch (error) { console.warn('[Portail] Mise à jour des statuts impossible :', error.message); } } async function loadApps() { try { var apps = await requestJson(PORTAL.dashboardAppsUrl); if (!Array.isArray(apps)) throw new Error('réponse applications invalide'); renderApps(apps); await fetchAndApplyStatuses(); } catch (error) { console.warn('[Portail] Chargement des applications impossible :', error.message); if (!hasRenderedApps) { document.getElementById('apps-grid').innerHTML = '
Dashboard indisponible — veuillez réessayer.
'; document.getElementById('app-count').textContent = '!'; } } } diff --git a/test/portal-contract.test.js b/test/portal-contract.test.js index b1223ef..d639a1b 100644 --- a/test/portal-contract.test.js +++ b/test/portal-contract.test.js @@ -4,6 +4,7 @@ * domaine courant choisit strictement son dashboard, ses URLs et son groupe. */ const assert = require('node:assert/strict'); +const crypto = require('node:crypto'); const fs = require('node:fs'); const path = require('node:path'); const vm = require('node:vm'); @@ -150,6 +151,16 @@ for (const [host, ids] of Object.entries(expectedVisible)) { assert.deepEqual(visible, ids, `${host} ne doit afficher que les tuiles de son portail`); } +const santinovaRecettePortal = loadPortal(hosts.santinovaRecette).sandbox; +assert.deepEqual( + santinovaRecettePortal.uniqueAppsById([ + { id: 'falc-generator', name: 'FALC Generator', category: 'ITINOVA', urls: { recette: 'https://falc-itinova.recette.santinova-soft.org' } }, + { id: 'falc-generator', name: 'FALC Generator dupliqué', category: 'ITINOVA', urls: { recette: 'https://falc-itinova.recette.santinova-soft.org' } } + ]).map(app => app.id), + ['falc-generator'], + 'un inventaire erroné ne doit jamais rendre FALC deux fois dans le portail' +); + const santelisProductionPortal = loadPortal(hosts.santelisProd).sandbox; assert.deepEqual( Array.from(santelisProductionPortal.getPortalOnlyApps(), app => app.id), @@ -167,6 +178,12 @@ for (const imageName of ['budget-si.jpg', 'gestion-astreintes-had.jpg', 'gestion assert.equal(fs.existsSync(imagePath), true, `l’asset ${imageName} doit être publié`); assert.ok(fs.statSync(imagePath).size > 2048, `l’asset ${imageName} ne doit pas être vide`); } +const falcAsset = path.join(root, 'images', 'falc-generator.png'); +assert.equal( + crypto.createHash('sha256').update(fs.readFileSync(falcAsset)).digest('hex'), + '6867b5253e45970cfb21b720804c1d186e53a38d9689ce37c6cdcbf21406e20d', + 'la recette doit utiliser la même vignette FALC de référence que la production' +); for (const historicalHost of [historicalRecetteHost, historicalProductionHost]) { const historicalPortal = loadPortal(historicalHost);