diff --git a/inc/computer.class.php b/inc/computer.class.php index a6a70ac..d03f5d0 100644 --- a/inc/computer.class.php +++ b/inc/computer.class.php @@ -54,5 +54,18 @@ class PluginExampleComputer extends CommonDBTM { echo ''; } + // 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"; + } + } } diff --git a/setup.php b/setup.php index 6f4ec06..ffb81f8 100755 --- a/setup.php +++ b/setup.php @@ -101,7 +101,10 @@ function plugin_init_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_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 $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['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 $PLUGIN_HOOKS['pre_show_tab']['example'] = array( 'PluginExampleShowtabitem', 'pre_show_tab' ); $PLUGIN_HOOKS['post_show_tab']['example'] = array( 'PluginExampleShowtabitem', 'post_show_tab' );