Fixed bug in filtered modules by tag

Former-commit-id: 098d3c88a9a30fb1c38074e741f093ff40fd5d02
This commit is contained in:
manuel 2019-02-19 13:05:31 +01:00
parent 39a60639fb
commit 00cba4cbc9
4 changed files with 32 additions and 8 deletions

View File

@ -3102,7 +3102,7 @@ function select_agents_for_module_group(
'AND',
'tagente_modulo',
true,
[],
$filter['tags'],
false
);
$sql_tags_inner = 'INNER JOIN ttag_module

View File

@ -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;
}
}

View File

@ -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(

View File

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