Fixed tags filter on bulk operation (select module first)

This commit is contained in:
fermin831 2018-10-17 11:57:22 +02:00
parent 9ee64b4894
commit 060e46868d
2 changed files with 11 additions and 33 deletions

View File

@ -1069,7 +1069,7 @@ function agents_get_group_agents (
*/
function agents_get_modules ($id_agent = null, $details = false,
$filter = false, $indexed = true, $get_not_init_modules = true,
$noACLs = false) {
$force_tags = false) {
global $config;
@ -1205,7 +1205,7 @@ function agents_get_modules ($id_agent = null, $details = false,
}
$sql_tags_join = "";
if (tags_has_user_acl_tags($config['id_user'])){
if (tags_has_user_acl_tags($config['id_user']) || $force_tags){
$where_tags = tags_get_acl_tags($config['id_user'], $id_groups, 'AR',
'module_condition', 'AND', 'tagente_modulo', false, array(),
true);

View File

@ -675,23 +675,24 @@ if (is_ajax ()) {
else
$search = false;
$force_tags = !empty($tags);
if ($force_tags) {
$filter['ttag_module.id_tag IN '] = "(" . implode(",", $tags) . ")";
}
if (is_metaconsole() && !$force_local_modules) {
if (enterprise_include_once ('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) {
$connection = metaconsole_get_connection($server_name);
if ($server_id > 0) {
$connection = metaconsole_get_connection_by_id($server_id);
}
if (metaconsole_load_external_db($connection) == NOERR) {
/* Get all agents if no agent was given */
if ($id_agent == 0)
$id_agent = array_keys(
agents_get_group_agents(
array_keys (users_get_groups ()), $search, "none"));
$agent_modules = agents_get_modules ($id_agent, $fields, $filter, $indexed, true, false, $tags);
$agent_modules = agents_get_modules ($id_agent, $fields, $filter, $indexed, true, $force_tags);
}
// Restore db connection
metaconsole_restore_db();
@ -703,35 +704,12 @@ if (is_ajax ()) {
$id_agent = array_keys(
agents_get_group_agents(
array_keys(users_get_groups ()), $search, "none"));
$agent_modules = agents_get_modules ($id_agent, $fields, $filter, $indexed, true, false, $tags);
$agent_modules = agents_get_modules ($id_agent, $fields, $filter, $indexed, true, $force_tags);
}
if (empty($agent_modules))
$agent_modules = array();
if (!empty($tags)) {
$implode_tags = implode(",", $tags);
$tag_modules = db_get_all_rows_sql("SELECT DISTINCT id_agente_modulo FROM ttag_module WHERE id_tag IN (" . $implode_tags . ")");
if ($tag_modules) {
$final_modules = array();
foreach ($agent_modules as $key => $module) {
$in_array = false;
foreach ($tag_modules as $t_module) {
if ($module['id_agente_modulo'] == $t_module['id_agente_modulo']) {
$in_array = true;
}
}
if ($in_array) {
$final_modules[] = $module;
}
}
$agent_modules = $final_modules;
}
else {
$agent_modules = array();
}
}
foreach ($agent_modules as $key => $module) {
$agent_modules[$key]['nombre'] = io_safe_output($module['nombre']);
}