Skip to content

Commit

Permalink
Fix error when user has no rights to use containers
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-anne committed Sep 14, 2023
1 parent 772f0a6 commit 188c124
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function plugin_fields_getAddSearchOptions($itemtype)
&& count($_SESSION['glpiactiveentities']) > 0
) {
$itemtypes = PluginFieldsContainer::getEntries('all');
if ($itemtypes !== false && in_array($itemtype, $itemtypes)) {
if (in_array($itemtype, $itemtypes)) {
return PluginFieldsContainer::getAddSearchOptions($itemtype);
}
}
Expand Down
12 changes: 5 additions & 7 deletions inc/container.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ public static function getTypes()
];
}

public static function getEntries($type = 'tab', $full = false)
public static function getEntries($type = 'tab', $full = false): array
{
global $DB;

Expand All @@ -1009,7 +1009,7 @@ public static function getEntries($type = 'tab', $full = false)
}

if (!$DB->tableExists(self::getTable())) {
return false;
return [];
}

$itemtypes = [];
Expand All @@ -1031,19 +1031,17 @@ public static function getEntries($type = 'tab', $full = false)
if (Session::isCron() || !isset($_SESSION['glpiactiveprofile']['id'])) {
continue;
}
//profiles restriction

//profiles restriction
if (isset($_SESSION['glpiactiveprofile']['id']) && $_SESSION['glpiactiveprofile']['id'] != null && $item['id'] > 0) {
$right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $item['id']);
if ($right < READ) {
return false;
continue;
}
} else {
return false;
continue;
}



$jsonitemtypes = json_decode($item['itemtypes']);
//show more info or not
foreach ($jsonitemtypes as $v) {
Expand Down
11 changes: 7 additions & 4 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,13 @@ function plugin_init_fields()
$PLUGIN_HOOKS["menu_toadd"]['fields'] = ['config' => 'PluginFieldsMenu'];

// add tabs to itemtypes
Plugin::registerClass(
'PluginFieldsContainer',
['addtabon' => array_unique(PluginFieldsContainer::getEntries())]
);
$itemtypes = array_unique(PluginFieldsContainer::getEntries());
if (count($itemtypes) > 0) {
Plugin::registerClass(
'PluginFieldsContainer',
['addtabon' => $itemtypes]
);
}

//include js and css
$debug = (isset($_SESSION['glpi_use_mode'])
Expand Down

0 comments on commit 188c124

Please sign in to comment.