From 0bdd5476cb8b157057dcdb14febc27ead44ff54b Mon Sep 17 00:00:00 2001 From: mariano Date: Wed, 27 May 2026 12:25:40 +0200 Subject: [PATCH] fix - profile in install --- MEMORY.md | 17 +++++++++++++++-- locales/de_DE.po | 3 +++ locales/en_GB.po | 3 +++ locales/it_IT.po | 3 +++ {front => removed}/profile.form.php___ | 0 src/Profile.php | 17 ++++++++++++++++- src/Server.php | 22 ++++++++++++++++------ 7 files changed, 56 insertions(+), 9 deletions(-) rename {front => removed}/profile.form.php___ (100%) diff --git a/MEMORY.md b/MEMORY.md index a6d13ba..50a8402 100644 --- a/MEMORY.md +++ b/MEMORY.md @@ -1,6 +1,6 @@ # MEMORY.md - Stato del Plugin UrBackup -## Ultima modifica: 22/05/2026 +## Ultima modifica: 27/05/2026 ## Performance - Asset Definition vs Computer @@ -39,5 +39,18 @@ L'overhead è in GLPI 11 core, non nel plugin: - `AssetTab::loadApiData()`: cache sessione 30s (chiave: server_id + client_name) - API timeout: 30s, connect timeout: 5s +## Bugfix: Campi API username/password non visibili in nuova installazione + +### Problema +In una nuova installazione del plugin, i campi "API username" e "API password" non venivano renderizzati come input — si vedeva solo la label ma non il campo editabile. + +### Cause (2 bug distinti) +1. **`src/Server.php:436`** — `$canUpdate` controllava solo `Session::haveRight(self::$rightname, UPDATE)`. In fase di creazione di un nuovo server, l'utente ha diritto CREATE ma non necessariamente UPDATE, quindi il campo non veniva mostrato. +2. **`src/Profile.php:73-77`** — `installRights()` usava `$_SESSION['glpiactiveprofile']['id']` per assegnare i diritti completi al profilo corrente. In installazione via CLI (`php bin/console glpi:plugin:install`), non c'è sessione, quindi `$profiles_id = 0` e nessun profilo riceveva i diritti completi. + +### Fix applicati +1. **`Server.php::showFormFields()`** — Sostituito `$canUpdate` con `$canEdit`: per nuovi server (`$ID <= 0`) usa `CREATE`, per server esistenti usa `UPDATE`. +2. **`Profile.php::installRights()`** — In assenza di sessione attiva (CLI), cerca il profilo "Super-Admin" tramite query diretta e gli assegna tutti i diritti. + ## Versione -- 0.6.0 +- 0.6.1 diff --git a/locales/de_DE.po b/locales/de_DE.po index 6ed9bc9..0223d3c 100644 --- a/locales/de_DE.po +++ b/locales/de_DE.po @@ -207,3 +207,6 @@ msgstr "Server nicht gefunden" msgid "Sorry. You cannot access this file directly." msgstr "Entschuldigung. Sie können nicht direkt auf diese Datei zugreifen." + +msgid "No assets" +msgstr "Keine Assets" diff --git a/locales/en_GB.po b/locales/en_GB.po index cda4138..fb632d7 100644 --- a/locales/en_GB.po +++ b/locales/en_GB.po @@ -207,3 +207,6 @@ msgstr "Server not found" msgid "Sorry. You cannot access this file directly." msgstr "Sorry. You cannot access this file directly." + +msgid "No assets" +msgstr "No assets" diff --git a/locales/it_IT.po b/locales/it_IT.po index af8df01..ac5aa43 100644 --- a/locales/it_IT.po +++ b/locales/it_IT.po @@ -207,3 +207,6 @@ msgstr "Server non trovato" msgid "Sorry. You cannot access this file directly." msgstr "Spiacenti. Non puoi accedere direttamente a questo file." + +msgid "No assets" +msgstr "Nessun Asset" diff --git a/front/profile.form.php___ b/removed/profile.form.php___ similarity index 100% rename from front/profile.form.php___ rename to removed/profile.form.php___ diff --git a/src/Profile.php b/src/Profile.php index d1700be..5780a5a 100644 --- a/src/Profile.php +++ b/src/Profile.php @@ -74,6 +74,21 @@ class Profile extends \Profile if ($profiles_id > 0) { self::setProfileRights($profiles_id, READ | UPDATE | CREATE | DELETE); + } else { + // CLI installation: no session available. + // Assign full rights to the Super-Admin profile. + global $DB; + $sa_iterator = $DB->request([ + 'FROM' => 'glpi_profiles', + 'WHERE' => [ + 'name' => 'Super-Admin', + ], + 'LIMIT' => 1, + ]); + foreach ($sa_iterator as $sa_profile) { + $profiles_id = (int) $sa_profile['id']; + self::setProfileRights($profiles_id, READ | UPDATE | CREATE | DELETE); + } } global $DB; @@ -83,7 +98,7 @@ class Profile extends \Profile ]); foreach ($all_profiles as $profile) { - if ($profile['id'] !== $profiles_id) { + if ((int) $profile['id'] !== $profiles_id) { $existing = $DB->request([ 'FROM' => 'glpi_profilerights', 'WHERE' => [ diff --git a/src/Server.php b/src/Server.php index c584e37..f57fafc 100644 --- a/src/Server.php +++ b/src/Server.php @@ -433,12 +433,14 @@ class Server extends CommonDBTM echo ""; echo ""; - $canUpdate = Session::haveRight(self::$rightname, UPDATE); + $canEdit = $ID > 0 + ? Session::haveRight(self::$rightname, UPDATE) + : Session::haveRight(self::$rightname, CREATE); echo ""; echo "" . htmlspecialchars(__('API username', 'urbackup')) . ""; echo ""; - if ($canUpdate) { + if ($canEdit) { echo Html::input('api_username', [ 'value' => $this->fields['api_username'] ?? '', 'size' => 40, @@ -451,7 +453,7 @@ class Server extends CommonDBTM echo "" . htmlspecialchars(__('API password', 'urbackup')) . ""; echo ""; - if ($canUpdate) { + if ($canEdit) { echo ""; @@ -1126,6 +1128,7 @@ class Server extends CommonDBTM $itemtypes = Config::getEnabledItemtypes(); $missingAssets = []; $candidatesByType = []; + $totalAssets = 0; foreach ($itemtypes as $itemtype) { if (!class_exists($itemtype)) { @@ -1148,6 +1151,7 @@ class Server extends CommonDBTM ]); foreach ($iterator as $assetRow) { + $totalAssets++; $name = (string) ($assetRow['name'] ?? ''); if ($name === '') { continue; @@ -1204,9 +1208,15 @@ class Server extends CommonDBTM unset($asset); if (count($missingAssets) === 0) { - echo '
'; - echo htmlspecialchars(__('All assets in this location are linked or already on the UrBackup server.', 'urbackup')); - echo '
'; + if ($totalAssets === 0) { + echo '
'; + echo htmlspecialchars(__('No assets', 'urbackup')); + echo '
'; + } else { + echo '
'; + echo htmlspecialchars(__('All assets in this location are linked or already on the UrBackup server.', 'urbackup')); + echo '
'; + } return; }