From 11965245816c2f77accd222fdf9185a956189539 Mon Sep 17 00:00:00 2001
From: Luis Calvo <luis.calvo@artica.es>
Date: Fri, 28 Feb 2020 12:33:36 +0100
Subject: [PATCH] Fixed monitor view groups without tags

---
 pandora_console/include/functions_tags.php       |  8 ++++++--
 .../operation/agentes/status_monitor.php         | 16 ----------------
 2 files changed, 6 insertions(+), 18 deletions(-)

diff --git a/pandora_console/include/functions_tags.php b/pandora_console/include/functions_tags.php
index aad6d78efd..affb9926e9 100644
--- a/pandora_console/include/functions_tags.php
+++ b/pandora_console/include/functions_tags.php
@@ -789,6 +789,10 @@ function tags_get_acl_tags(
 
     $acltags = [];
     foreach ($raw_acltags as $group => $taglist) {
+        if (!empty($id_group) && !in_array($group, $id_group)) {
+            continue;
+        }
+
         if (!empty($taglist)) {
             $acltags[$group] = explode(',', $taglist);
         } else {
@@ -861,7 +865,7 @@ function tags_get_acl_tags_module_condition($acltags, $modules_table='', $force_
     // 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 = [];
+            // $group_tags = [];
             if (!empty($force_tags)) {
                 $group_tags = $force_tags;
             }
@@ -881,7 +885,7 @@ function tags_get_acl_tags_module_condition($acltags, $modules_table='', $force_
             }
 
             $group_conditions[] = $agent_condition;
-        } else if (!empty($force_tags)) {
+        } else if (!empty($force_tags) || !empty($group_id)) {
             $without_tags[] = $group_id;
         }
     }
diff --git a/pandora_console/operation/agentes/status_monitor.php b/pandora_console/operation/agentes/status_monitor.php
index 59303227da..154f8194d9 100644
--- a/pandora_console/operation/agentes/status_monitor.php
+++ b/pandora_console/operation/agentes/status_monitor.php
@@ -282,7 +282,6 @@ if ($tag_filter !== 0) {
 $sql_conditions_tags = '';
 
 if (!users_is_admin()) {
-    if ($ag_group !== 0) {
         $sql_conditions_tags = tags_get_acl_tags(
             $config['id_user'],
             $ag_group,
@@ -294,21 +293,6 @@ if (!users_is_admin()) {
             [],
             false
         );
-    } else {
-        // Fix: for tag functionality groups have to be all user_groups (propagate ACL funct!)
-        $groups = users_get_groups($config['id_user']);
-        $sql_conditions_tags = tags_get_acl_tags(
-            $config['id_user'],
-            array_keys($groups),
-            'AR',
-            'module_condition',
-            'AND',
-            'tagente_modulo',
-            true,
-            [],
-            false
-        );
-    }
 
     if (is_numeric($sql_conditions_tags)) {
         $sql_conditions_tags = ' AND 1 = 0';