mirror of
https://github.com/pluginsGLPI/example.git
synced 2025-05-04 18:08:42 +02:00
Fix setup for new hook
This commit is contained in:
parent
e8acb472eb
commit
a16d0fb850
@ -54,18 +54,27 @@ class PluginExampleComputer extends CommonDBTM {
|
|||||||
echo '</table>';
|
echo '</table>';
|
||||||
}
|
}
|
||||||
|
|
||||||
// implement "item_can" hook (9.2) for Computer
|
|
||||||
static function restrict(Computer $comp) {
|
static function item_can($item) {
|
||||||
// no right to see computer from group 1
|
|
||||||
if (isset($comp->right)) {
|
if (($item-getType() == 'Computer')
|
||||||
// call from ConnDBTM::can method, filter for current item
|
&& ($item->right == READ)
|
||||||
if ($comp->getField('groups_id') == 1) {
|
&& ($item->fields['groups_id'] > 0)
|
||||||
$comp->right = false;
|
&& !in_array($item->fields['groups_id'], $_SESSION["glpigroups"])) {
|
||||||
}
|
$item->right = 0; // unknown, so denied.
|
||||||
} else {
|
|
||||||
// called from Search::addDefaultWhere method, return additional condition
|
|
||||||
$comp->add_where = "glpi_computers.groups_id != 1";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static function add_default_where($in) {
|
||||||
|
|
||||||
|
list($itemtype, $condition) = $in;
|
||||||
|
if ($itemtype == 'Computer') {
|
||||||
|
$table = getTableForItemType($itemtype);
|
||||||
|
$condition .= " (".$table.".groups_id NOT IN (".implode(',', $_SESSION["glpigroups"])."))";
|
||||||
|
}
|
||||||
|
return [$itemtype, $condition];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,8 @@ function plugin_init_example() {
|
|||||||
$PLUGIN_HOOKS['item_empty']['example'] = array('Computer' => 'plugin_item_empty_example');
|
$PLUGIN_HOOKS['item_empty']['example'] = array('Computer' => 'plugin_item_empty_example');
|
||||||
|
|
||||||
// Restrict right
|
// Restrict right
|
||||||
$PLUGIN_HOOKS['item_can']['example'] = ['Computer' => ['PluginExampleComputer', 'restrict']];
|
$PLUGIN_HOOKS['item_can']['example'] = ['Computer' => ['PluginExampleComputer', 'item_can']];
|
||||||
|
$PLUGIN_HOOKS['add_default_where']['example'] = ['Computer' => ['PluginExampleComputer', 'add_default_where']];
|
||||||
|
|
||||||
// Example using a method in class
|
// Example using a method in class
|
||||||
$PLUGIN_HOOKS['pre_item_add']['example'] = array('Computer' => array('PluginExampleExample',
|
$PLUGIN_HOOKS['pre_item_add']['example'] = array('Computer' => array('PluginExampleExample',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user