add 'item_can'

This commit is contained in:
Remi Collet 2017-01-17 10:26:52 +01:00
parent 32b18bb4a2
commit d07637d23d
2 changed files with 18 additions and 2 deletions

View File

@ -54,5 +54,18 @@ class PluginExampleComputer extends CommonDBTM {
echo '</table>';
}
// implement "item_can" hook (9.2) for Computer
static function restrict(Computer $comp) {
// no right to see computer from group 1
if (isset($comp->right)) {
// call from ConnDBTM::can method, filter for current item
if ($comp->getField('groups_id') == 1) {
$comp->right = false;
}
} else {
// called from Search::addDefaultWhere method, return additional condition
$comp->add_where = "glpi_computers.groups_id != 1";
}
}
}

View File

@ -103,6 +103,9 @@ function plugin_init_example() {
$PLUGIN_HOOKS['item_empty']['example'] = array('Computer' => 'plugin_item_empty_example');
// Restrict right
$PLUGIN_HOOKS['item_can']['example'] = ['Computer' => ['PluginExampleComputer', 'restrict']];
// Example using a method in class
$PLUGIN_HOOKS['pre_item_add']['example'] = array('Computer' => array('PluginExampleExample',
'pre_item_add_computer'));