From 396783cd41f5be21cc7e2014472fa435615ce67c Mon Sep 17 00:00:00 2001 From: DevEnv nis2-agile Date: Wed, 26 Aug 2026 18:14:07 +0200 Subject: [PATCH] [FIX] Documenti Istituzionali (#499): le 5 voci standard non comparivano mai (NO_ORG) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Root cause: InstitutionalDocsController::list() usava requireAuth()+getCurrentOrgId(), ma currentOrgId e' popolato solo da requireOrgAccess() → getCurrentOrgId() = null → l'endpoint rispondeva sempre NO_ORG (400) → loadDocs riceveva standards=[] → la card mostrava solo "Aggiungi voce" (screenshot Simon). L'endpoint NON aveva mai funzionato a runtime. - Backend: list() usa resolveOrgId() (risolve X-Organization-Id senza lanciare) e restituisce SEMPRE le 5 voci standard; i documenti salvati solo se un'org e' selezionata. - Frontend (dashboard.js): render condiviso + STD_FALLBACK → le 5 voci si mostrano sempre, anche se l'API fallisce. Buster dashboard.js 20260825. - Backend attivato via reload php-fpm host. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../InstitutionalDocsController.php | 12 ++-- public/dashboard.html | 2 +- public/js/dashboard.js | 55 +++++++++++-------- 3 files changed, 40 insertions(+), 29 deletions(-) diff --git a/application/controllers/InstitutionalDocsController.php b/application/controllers/InstitutionalDocsController.php index ffbbd5d..50ca7fb 100644 --- a/application/controllers/InstitutionalDocsController.php +++ b/application/controllers/InstitutionalDocsController.php @@ -33,16 +33,18 @@ class InstitutionalDocsController extends BaseController public function list(): void { $this->requireAuth(); - $orgId = $this->getCurrentOrgId(); - if (!$orgId) { $this->jsonError('Nessuna organizzazione selezionata', 400, 'NO_ORG'); } - - $rows = Database::fetchAll( + // BUGFIX (#499): usare requireAuth+getCurrentOrgId dava sempre NO_ORG (currentOrgId + // e' popolato solo da requireOrgAccess) → le 5 voci standard non comparivano MAI. + // Ora risolviamo l'org dall'header e restituiamo SEMPRE le 5 voci standard; + // i documenti salvati si aggiungono solo se un'org e' selezionata. + $orgId = $this->resolveOrgId(); + $rows = $orgId ? Database::fetchAll( "SELECT id, doc_key, title, description, file_url, is_standard, sort_order, updated_at FROM institutional_documents WHERE organization_id = ? ORDER BY is_standard DESC, sort_order ASC, id ASC", [$orgId] - ); + ) : []; $this->jsonSuccess(['docs' => $rows, 'standards' => self::STANDARDS]); } diff --git a/public/dashboard.html b/public/dashboard.html index f818884..12a6757 100644 --- a/public/dashboard.html +++ b/public/dashboard.html @@ -118,7 +118,7 @@ - +