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>'; 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

@ -101,7 +101,10 @@ function plugin_init_example() {
$PLUGIN_HOOKS['pre_item_update']['example'] = array('Computer' => 'plugin_pre_item_update_example'); $PLUGIN_HOOKS['pre_item_update']['example'] = array('Computer' => 'plugin_pre_item_update_example');
$PLUGIN_HOOKS['item_update']['example'] = array('Computer' => 'plugin_item_update_example'); $PLUGIN_HOOKS['item_update']['example'] = array('Computer' => 'plugin_item_update_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
$PLUGIN_HOOKS['item_can']['example'] = ['Computer' => ['PluginExampleComputer', 'restrict']];
// 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',
@ -181,7 +184,7 @@ function plugin_init_example() {
$PLUGIN_HOOKS['display_login']['example'] = "plugin_example_display_login"; $PLUGIN_HOOKS['display_login']['example'] = "plugin_example_display_login";
$PLUGIN_HOOKS['infocom']['example'] = "plugin_example_infocom_hook"; $PLUGIN_HOOKS['infocom']['example'] = "plugin_example_infocom_hook";
// pre_show and post_show for tabs and items, // pre_show and post_show for tabs and items,
// see PluginExampleShowtabitem class for implementation explanations // see PluginExampleShowtabitem class for implementation explanations
$PLUGIN_HOOKS['pre_show_tab']['example'] = array( 'PluginExampleShowtabitem', 'pre_show_tab' ); $PLUGIN_HOOKS['pre_show_tab']['example'] = array( 'PluginExampleShowtabitem', 'pre_show_tab' );
$PLUGIN_HOOKS['post_show_tab']['example'] = array( 'PluginExampleShowtabitem', 'post_show_tab' ); $PLUGIN_HOOKS['post_show_tab']['example'] = array( 'PluginExampleShowtabitem', 'post_show_tab' );