diff --git a/ajax/taskjob_moduleitems.php b/ajax/taskjob_moduleitems.php index a01db5f732..e2459218b5 100644 --- a/ajax/taskjob_moduleitems.php +++ b/ajax/taskjob_moduleitems.php @@ -42,6 +42,7 @@ $pfTaskjob = new PluginGlpiinventoryTaskjob(); $params = [ + "taskid" => filter_input(INPUT_GET, "taskid"), "moduletype" => filter_input(INPUT_GET, "moduletype"), "itemtype" => filter_input(INPUT_GET, "itemtype"), "method" => filter_input(INPUT_GET, "method"), diff --git a/inc/taskjobview.class.php b/inc/taskjobview.class.php index 4cdb3613e6..c19dfd3b58 100644 --- a/inc/taskjobview.class.php +++ b/inc/taskjobview.class.php @@ -399,6 +399,7 @@ public function ajaxModuleItemsDropdown($options) $moduletype = $options['moduletype']; $itemtype = $options['itemtype']; $method = $options['method']; + $taskid = $options['taskid']; $title = ''; if ($itemtype === "") { return; @@ -427,7 +428,7 @@ public function ajaxModuleItemsDropdown($options) $modulename = str_replace('DEPLOYINSTALL', 'DEPLOY', strtoupper($method)); // prepare a query to retrieve agent's & computer's id - $iterator = $DB->request([ + $crit = [ 'SELECT' => [ 'agents.id AS agents_id', 'agents.items_id' @@ -462,13 +463,33 @@ public function ajaxModuleItemsDropdown($options) 'agents.id', 'agents.items_id' ] - ]); + ]; + + $item = getItemForItemtype($itemtype); + if ($item->isEntityAssign()) { + // get entity ID from task ID + $pfTask = new PluginGlpiinventoryTask(); + $pfTask->getFromDB($taskid); + + $crit['WHERE'] += getEntitiesRestrictCriteria( + 'agents', + '', + $pfTask->fields['entities_id'] ?? 0, + $item->maybeRecursive() + ); + } + + $iterator = $DB->request($crit); + $filter_id = []; foreach ($iterator as $data_filter) { if ($itemtype == 'Computer') { $filter_id[] = $data_filter['items_id']; } else { - $filter_id[] = $data_filter['agents_id']; + $pfAgentModule = new PluginGlpiinventoryAgentmodule(); + if ($pfAgentModule->isAgentCanDo($modulename, $data_filter['agents_id'])) { + $filter_id[] = $data_filter['agents_id']; + } } } diff --git a/js/taskjobs.js b/js/taskjobs.js index 33e88dc01f..00b0b94e3e 100644 --- a/js/taskjobs.js +++ b/js/taskjobs.js @@ -180,9 +180,12 @@ taskjobs.show_moduletypes = function(ajax_url, moduletype) { taskjobs.show_moduleitems = function(ajax_url, moduletype, itemtype) { taskjobs.hide_moduleitems_dropdown(); + const queryString = window.location.search; + const urlParams = new URLSearchParams(queryString); $.ajax({ url: ajax_url, data: { + "taskid" : (typeof urlParams.get('id') !== null ? urlParams.get('id') : 0), "itemtype" : itemtype, "moduletype" : moduletype, "method" : $('#method_selected').text()