diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 9aa9cf7dfd..430ca9d6a1 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -3102,7 +3102,7 @@ function select_agents_for_module_group( 'AND', 'tagente_modulo', true, - [], + $filter['tags'], false ); $sql_tags_inner = 'INNER JOIN ttag_module diff --git a/pandora_console/include/functions_tags.php b/pandora_console/include/functions_tags.php index 2969a80dcd..ebbc2ac376 100644 --- a/pandora_console/include/functions_tags.php +++ b/pandora_console/include/functions_tags.php @@ -748,7 +748,7 @@ function tags_get_acl_tags( $id_user = $config['id_user']; } - if (is_user_admin($id_user)) { + if (is_user_admin($id_user) && empty($childrens_ids)) { switch ($return_mode) { case 'data': return []; @@ -797,7 +797,8 @@ function tags_get_acl_tags( // Return the condition of the tags for tagente_modulo table $condition = tags_get_acl_tags_module_condition( $acltags, - $query_table + $query_table, + empty($childrens_ids) ? [] : $childrens_ids ); if (!empty($condition)) { return " $query_prefix ".$condition; @@ -825,7 +826,7 @@ function tags_get_acl_tags( * * @return string SQL condition for tagente_module */ -function tags_get_acl_tags_module_condition($acltags, $modules_table='') +function tags_get_acl_tags_module_condition($acltags, $modules_table='', $force_tags=[]) { if (!empty($modules_table)) { $modules_table .= '.'; @@ -839,6 +840,17 @@ function tags_get_acl_tags_module_condition($acltags, $modules_table='') // The acltags array contains the groups with the acl propagation applied // after the changes done into the 'tags_get_user_groups_and_tags' function. foreach ($acltags as $group_id => $group_tags) { + if (empty($group_tags)) { + $group_tags = []; + if (!empty($force_tags)) { + $group_tags = $force_tags; + } + } + + if (!empty($group_tags)) { + $group_tags = array_intersect($force_tags, $group_tags); + } + $tag_join = ''; if (!empty($group_tags)) { $tag_join = sprintf('AND ttag_module.id_tag IN (%s)', is_array($group_tags) ? implode(',', $group_tags) : $group_tags); @@ -849,7 +861,7 @@ function tags_get_acl_tags_module_condition($acltags, $modules_table='') } $group_conditions[] = $agent_condition; - } else { + } else if (!empty($force_tags)) { $without_tags[] = $group_id; } } diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js index 37a9987812..c30736cd8b 100644 --- a/pandora_console/include/javascript/pandora.js +++ b/pandora_console/include/javascript/pandora.js @@ -503,6 +503,14 @@ function module_changed_by_multiple_modules(event, id_module, selected) { selection_mode = "common"; } + var tags_selected = []; + + var tags_to_search = $("#tags").val(); + if (tags_to_search != null) { + if (tags_to_search[0] != -1) { + tags_selected = tags_to_search; + } + } jQuery.post( "ajax.php", { @@ -510,7 +518,8 @@ function module_changed_by_multiple_modules(event, id_module, selected) { get_agents_json_for_multiple_modules: 1, status_module: status_module, "module_name[]": idModules, - selection_mode: selection_mode + selection_mode: selection_mode, + tags: tags_selected }, function(data) { $("#agents").append( diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index e3171f61f4..a9a9a076bd 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -177,11 +177,14 @@ if (is_ajax()) { $nameModules = get_parameter('module_name'); $selection_mode = get_parameter('selection_mode', 'common') == 'all'; $status_modulo = (int) get_parameter('status_module', -1); - + $tags_selected = (array) get_parameter('tags', []); $names = select_agents_for_module_group( $nameModules, $selection_mode, - ['status' => $status_modulo], + [ + 'status' => $status_modulo, + 'tags' => $tags_selected, + ], 'AW' );