Fixed the ajax of get modules when the user have profiles with tags and without tags.

This commit is contained in:
mdtrooper 2015-03-26 18:44:16 +01:00
parent c7b3104224
commit b72af65bd0
2 changed files with 31 additions and 14 deletions

View File

@ -1161,9 +1161,11 @@ function agents_get_modules ($id_agent = null, $details = false,
//$where .= " AND id_policy_module = 0 ";
$where_tags = tags_get_acl_tags($config['id_user'], $id_groups, 'AR', 'module_condition', 'AND', 'tagente_modulo');
$where_tags = tags_get_acl_tags($config['id_user'], $id_groups, 'AR',
'module_condition', 'AND', 'tagente_modulo', false, array(),
true);
$where .= $where_tags;
$where .= "\n\n" . $where_tags;
switch ($config["dbtype"]) {
case "mysql":
@ -1189,6 +1191,7 @@ function agents_get_modules ($id_agent = null, $details = false,
break;
}
$result = db_get_all_rows_sql ($sql);
if (empty ($result)) {

View File

@ -596,7 +596,10 @@ function tags_get_tags_formatted ($tags_array, $get_url = true) {
* @return mixed/string Tag ids
*/
function tags_get_acl_tags($id_user, $id_group, $access = 'AR', $return_mode = 'module_condition', $query_prefix = '', $query_table = '', $meta = false, $childrens_ids = array(), $force_group_and_tag = false) {
function tags_get_acl_tags($id_user, $id_group, $access = 'AR',
$return_mode = 'module_condition', $query_prefix = '',
$query_table = '', $meta = false, $childrens_ids = array(),
$force_group_and_tag = false) {
global $config;
@ -635,6 +638,7 @@ function tags_get_acl_tags($id_user, $id_group, $access = 'AR', $return_mode = '
$acltags = tags_get_user_module_and_tags($id_user, $access);
// Delete the groups without tag restrictions from the acl tags array if $force_group_and_tag == false
// Delete the groups that aren't in the received groups id
$acltags_aux = array();
@ -660,7 +664,9 @@ function tags_get_acl_tags($id_user, $id_group, $access = 'AR', $return_mode = '
break;
case 'module_condition':
// Return the condition of the tags for tagente_modulo table
$condition = tags_get_acl_tags_module_condition($acltags, $query_table, true);
$condition = tags_get_acl_tags_module_condition($acltags,
$query_table);
if (!empty($condition)) {
return " $query_prefix " . $condition;
}
@ -701,7 +707,7 @@ function tags_get_acl_tags_module_condition($acltags, $modules_table = '') {
// Fix: Wrap SQL expression with "()" to avoid bad SQL sintax that makes Pandora retrieve all modules without taking care of id_agent => id_agent = X AND (sql_tag_expression)
if ($i == 0)
$condition .= ' ( ';
$condition .= ' ( ' . "\n";
// Group condition (The module belongs to an agent of the group X)
// Juanma (08/05/2014) Fix: Now group and tag is checked at the same time, before only tag was checked due to a bad condition
@ -713,7 +719,7 @@ function tags_get_acl_tags_module_condition($acltags, $modules_table = '') {
//Avoid the user profiles with all group access.
$group_condition = " 1 = 1 ";
}
//When the acl is only group without tags
if (empty($group_tags)) {
$condition .= "($group_condition)\n";
@ -727,9 +733,14 @@ function tags_get_acl_tags_module_condition($acltags, $modules_table = '') {
// Tags condition (The module has at least one of the restricted tags)
$tags_condition = sprintf('%sid_agente_modulo IN (SELECT id_agente_modulo FROM ttag_module WHERE id_tag IN (%s))', $modules_table, $group_tags_query);
$condition .= "($group_condition AND \n$tags_condition)\n";
$condition .=
" ( \n" .
" $group_condition \n" .
" AND \n" .
" $tags_condition \n" .
" )\n";
}
$i++;
}
@ -2147,10 +2158,10 @@ function tags_get_monitors_alerts ($id_tag, $groups_and_tags = array(), $id_agen
AND tagente_modulo.id_agente_modulo IN (SELECT id_agente_modulo FROM ttag_module WHERE id_tag = $id_tag)
$agents_clause
$groups_clause";
$count = db_get_sql ($sql);
return $count;
return $count;
}
function __add_acltags (&$acltags, $group_id, $tags_str) {
@ -2215,7 +2226,7 @@ function tags_get_user_module_and_tags ($id_user = false, $access = 'AR', $stric
tperfil.%s = 1
ORDER BY id_grupo", $id_user, $acl_column);
$tags_and_groups = db_get_all_rows_sql($sql);
if ($tags_and_groups === false)
$tags_and_groups = array();
@ -2226,11 +2237,12 @@ function tags_get_user_module_and_tags ($id_user = false, $access = 'AR', $stric
$all_groups = groups_get_all();
if (!empty($all_groups))
$all_group_ids = array_keys($all_groups);
$tags_and_groups_aux = array();
foreach ($tags_and_groups as $data) {
// All group
if ($data['id_grupo'] == 0) {
if ($data['id_grupo'] === 0) {
// All group with empty tags. All groups without tags permission!
if (empty($data['tags'])) {
foreach ($all_group_ids as $group_id) {
@ -2257,10 +2269,12 @@ function tags_get_user_module_and_tags ($id_user = false, $access = 'AR', $stric
$tags_and_groups = $tags_and_groups_aux;
unset($tags_and_groups_aux);
foreach ($tags_and_groups as $group_tag) {
__add_acltags($acltags, $group_tag['id_grupo'], $group_tag['tags']);
}
return $acltags;
}