fix - profile in install

This commit is contained in:
mariano
2026-05-27 12:25:40 +02:00
parent 41a8f8dbb4
commit 0bdd5476cb
7 changed files with 56 additions and 9 deletions
+15 -2
View File
@@ -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
+3
View File
@@ -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"
+3
View File
@@ -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"
+3
View File
@@ -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"
+16 -1
View File
@@ -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' => [
+16 -6
View File
@@ -433,12 +433,14 @@ class Server extends CommonDBTM
echo "</td>";
echo "</tr>";
$canUpdate = Session::haveRight(self::$rightname, UPDATE);
$canEdit = $ID > 0
? Session::haveRight(self::$rightname, UPDATE)
: Session::haveRight(self::$rightname, CREATE);
echo "<tr class='tab_bg_1'>";
echo "<td>" . htmlspecialchars(__('API username', 'urbackup')) . "</td>";
echo "<td>";
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 "<td>" . htmlspecialchars(__('API password', 'urbackup')) . "</td>";
echo "<td>";
if ($canUpdate) {
if ($canEdit) {
echo "<input type='password' name='api_password' value='" .
htmlspecialchars((string) ($this->fields['api_password'] ?? '')) .
"' autocomplete='new-password'>";
@@ -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 '<div class="alert alert-success">';
echo htmlspecialchars(__('All assets in this location are linked or already on the UrBackup server.', 'urbackup'));
echo '</div>';
if ($totalAssets === 0) {
echo '<div class="alert alert-info">';
echo htmlspecialchars(__('No assets', 'urbackup'));
echo '</div>';
} else {
echo '<div class="alert alert-success">';
echo htmlspecialchars(__('All assets in this location are linked or already on the UrBackup server.', 'urbackup'));
echo '</div>';
}
return;
}