fix - profile in install
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# MEMORY.md - Stato del Plugin UrBackup
|
# MEMORY.md - Stato del Plugin UrBackup
|
||||||
|
|
||||||
## Ultima modifica: 22/05/2026
|
## Ultima modifica: 27/05/2026
|
||||||
|
|
||||||
## Performance - Asset Definition vs Computer
|
## 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)
|
- `AssetTab::loadApiData()`: cache sessione 30s (chiave: server_id + client_name)
|
||||||
- API timeout: 30s, connect timeout: 5s
|
- 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
|
## Versione
|
||||||
- 0.6.0
|
- 0.6.1
|
||||||
|
|||||||
@@ -207,3 +207,6 @@ msgstr "Server nicht gefunden"
|
|||||||
|
|
||||||
msgid "Sorry. You cannot access this file directly."
|
msgid "Sorry. You cannot access this file directly."
|
||||||
msgstr "Entschuldigung. Sie können nicht direkt auf diese Datei zugreifen."
|
msgstr "Entschuldigung. Sie können nicht direkt auf diese Datei zugreifen."
|
||||||
|
|
||||||
|
msgid "No assets"
|
||||||
|
msgstr "Keine Assets"
|
||||||
|
|||||||
@@ -207,3 +207,6 @@ msgstr "Server not found"
|
|||||||
|
|
||||||
msgid "Sorry. You cannot access this file directly."
|
msgid "Sorry. You cannot access this file directly."
|
||||||
msgstr "Sorry. You cannot access this file directly."
|
msgstr "Sorry. You cannot access this file directly."
|
||||||
|
|
||||||
|
msgid "No assets"
|
||||||
|
msgstr "No assets"
|
||||||
|
|||||||
@@ -207,3 +207,6 @@ msgstr "Server non trovato"
|
|||||||
|
|
||||||
msgid "Sorry. You cannot access this file directly."
|
msgid "Sorry. You cannot access this file directly."
|
||||||
msgstr "Spiacenti. Non puoi accedere direttamente a questo file."
|
msgstr "Spiacenti. Non puoi accedere direttamente a questo file."
|
||||||
|
|
||||||
|
msgid "No assets"
|
||||||
|
msgstr "Nessun Asset"
|
||||||
|
|||||||
+16
-1
@@ -74,6 +74,21 @@ class Profile extends \Profile
|
|||||||
|
|
||||||
if ($profiles_id > 0) {
|
if ($profiles_id > 0) {
|
||||||
self::setProfileRights($profiles_id, READ | UPDATE | CREATE | DELETE);
|
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;
|
global $DB;
|
||||||
@@ -83,7 +98,7 @@ class Profile extends \Profile
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
foreach ($all_profiles as $profile) {
|
foreach ($all_profiles as $profile) {
|
||||||
if ($profile['id'] !== $profiles_id) {
|
if ((int) $profile['id'] !== $profiles_id) {
|
||||||
$existing = $DB->request([
|
$existing = $DB->request([
|
||||||
'FROM' => 'glpi_profilerights',
|
'FROM' => 'glpi_profilerights',
|
||||||
'WHERE' => [
|
'WHERE' => [
|
||||||
|
|||||||
+13
-3
@@ -433,12 +433,14 @@ class Server extends CommonDBTM
|
|||||||
echo "</td>";
|
echo "</td>";
|
||||||
echo "</tr>";
|
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 "<tr class='tab_bg_1'>";
|
||||||
echo "<td>" . htmlspecialchars(__('API username', 'urbackup')) . "</td>";
|
echo "<td>" . htmlspecialchars(__('API username', 'urbackup')) . "</td>";
|
||||||
echo "<td>";
|
echo "<td>";
|
||||||
if ($canUpdate) {
|
if ($canEdit) {
|
||||||
echo Html::input('api_username', [
|
echo Html::input('api_username', [
|
||||||
'value' => $this->fields['api_username'] ?? '',
|
'value' => $this->fields['api_username'] ?? '',
|
||||||
'size' => 40,
|
'size' => 40,
|
||||||
@@ -451,7 +453,7 @@ class Server extends CommonDBTM
|
|||||||
|
|
||||||
echo "<td>" . htmlspecialchars(__('API password', 'urbackup')) . "</td>";
|
echo "<td>" . htmlspecialchars(__('API password', 'urbackup')) . "</td>";
|
||||||
echo "<td>";
|
echo "<td>";
|
||||||
if ($canUpdate) {
|
if ($canEdit) {
|
||||||
echo "<input type='password' name='api_password' value='" .
|
echo "<input type='password' name='api_password' value='" .
|
||||||
htmlspecialchars((string) ($this->fields['api_password'] ?? '')) .
|
htmlspecialchars((string) ($this->fields['api_password'] ?? '')) .
|
||||||
"' autocomplete='new-password'>";
|
"' autocomplete='new-password'>";
|
||||||
@@ -1126,6 +1128,7 @@ class Server extends CommonDBTM
|
|||||||
$itemtypes = Config::getEnabledItemtypes();
|
$itemtypes = Config::getEnabledItemtypes();
|
||||||
$missingAssets = [];
|
$missingAssets = [];
|
||||||
$candidatesByType = [];
|
$candidatesByType = [];
|
||||||
|
$totalAssets = 0;
|
||||||
|
|
||||||
foreach ($itemtypes as $itemtype) {
|
foreach ($itemtypes as $itemtype) {
|
||||||
if (!class_exists($itemtype)) {
|
if (!class_exists($itemtype)) {
|
||||||
@@ -1148,6 +1151,7 @@ class Server extends CommonDBTM
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
foreach ($iterator as $assetRow) {
|
foreach ($iterator as $assetRow) {
|
||||||
|
$totalAssets++;
|
||||||
$name = (string) ($assetRow['name'] ?? '');
|
$name = (string) ($assetRow['name'] ?? '');
|
||||||
if ($name === '') {
|
if ($name === '') {
|
||||||
continue;
|
continue;
|
||||||
@@ -1204,9 +1208,15 @@ class Server extends CommonDBTM
|
|||||||
unset($asset);
|
unset($asset);
|
||||||
|
|
||||||
if (count($missingAssets) === 0) {
|
if (count($missingAssets) === 0) {
|
||||||
|
if ($totalAssets === 0) {
|
||||||
|
echo '<div class="alert alert-info">';
|
||||||
|
echo htmlspecialchars(__('No assets', 'urbackup'));
|
||||||
|
echo '</div>';
|
||||||
|
} else {
|
||||||
echo '<div class="alert alert-success">';
|
echo '<div class="alert alert-success">';
|
||||||
echo htmlspecialchars(__('All assets in this location are linked or already on the UrBackup server.', 'urbackup'));
|
echo htmlspecialchars(__('All assets in this location are linked or already on the UrBackup server.', 'urbackup'));
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user