From c49f6884a3c5de013f92e7fa2c9ef95e9c93719b Mon Sep 17 00:00:00 2001 From: sadnub Date: Wed, 28 Oct 2020 22:49:41 -0400 Subject: [PATCH] reduced some code and tweaked the UI --- api/tacticalrmm/automation/models.py | 39 +---- api/tacticalrmm/automation/views.py | 2 +- api/tacticalrmm/tacticalrmm/settings.py | 2 +- .../automation/AutomationManager.vue | 93 +++-------- .../automation/modals/RelationsView.vue | 145 +++++++++--------- 5 files changed, 107 insertions(+), 174 deletions(-) diff --git a/api/tacticalrmm/automation/models.py b/api/tacticalrmm/automation/models.py index fc0b6594..c0874dcd 100644 --- a/api/tacticalrmm/automation/models.py +++ b/api/tacticalrmm/automation/models.py @@ -23,12 +23,12 @@ class Policy(BaseAuditModel): return self.name def related_agents(self): - return self.related_server_agents() | self.related_workstation_agents() + return self.get_related("server") | self.get_related("workstation") - def related_server_agents(self): - explicit_agents = self.agents.filter(monitoring_type="server") - explicit_clients = self.server_clients.all() - explicit_sites = self.server_sites.all() + def get_related(self, mon_type): + explicit_agents = self.agents.filter(monitoring_type=mon_type) + explicit_clients = getattr(self, f"{mon_type}_clients").all() + explicit_sites = getattr(self, f"{mon_type}_sites").all() filtered_agents_pks = Policy.objects.none() @@ -37,37 +37,12 @@ class Policy(BaseAuditModel): filtered_agents_pks |= Agent.objects.filter( client=site.client.client, site=site.site, - monitoring_type="server", + monitoring_type=mon_type, ).values_list("pk", flat=True) filtered_agents_pks |= Agent.objects.filter( client__in=[client.client for client in explicit_clients], - monitoring_type="server", - ).values_list("pk", flat=True) - - return Agent.objects.filter( - models.Q(pk__in=filtered_agents_pks) - | models.Q(pk__in=explicit_agents.only("pk")) - ) - - def related_workstation_agents(self): - explicit_agents = self.agents.filter(monitoring_type="workstation") - explicit_clients = self.workstation_clients.all() - explicit_sites = self.workstation_sites.all() - - filtered_agents_pks = Policy.objects.none() - - for site in explicit_sites: - if site.client not in explicit_clients: - filtered_agents_pks |= Agent.objects.filter( - client=site.client.client, - site=site.site, - monitoring_type="workstation", - ).values_list("pk", flat=True) - - filtered_agents_pks |= Agent.objects.filter( - client__in=[client.client for client in explicit_clients], - monitoring_type="workstation", + monitoring_type=mon_type, ).values_list("pk", flat=True) return Agent.objects.filter( diff --git a/api/tacticalrmm/automation/views.py b/api/tacticalrmm/automation/views.py index 1e08adec..2d000801 100644 --- a/api/tacticalrmm/automation/views.py +++ b/api/tacticalrmm/automation/views.py @@ -186,7 +186,7 @@ class GetRelated(APIView): ).data response["agents"] = AgentHostnameSerializer( - policy.related_server_agents() | policy.related_workstation_agents(), + policy.related_agents(), many=True, ).data diff --git a/api/tacticalrmm/tacticalrmm/settings.py b/api/tacticalrmm/tacticalrmm/settings.py index f31f94e9..f6b69cd1 100644 --- a/api/tacticalrmm/tacticalrmm/settings.py +++ b/api/tacticalrmm/tacticalrmm/settings.py @@ -11,7 +11,7 @@ AUTH_USER_MODEL = "accounts.User" # bump this version everytime vue code is changed # to alert user they need to manually refresh their browser -APP_VER = "0.0.81" +APP_VER = "0.0.82" # https://github.com/wh1te909/salt LATEST_SALT_VER = "1.1.0" diff --git a/web/src/components/automation/AutomationManager.vue b/web/src/components/automation/AutomationManager.vue index 4e7a3531..d53d07b5 100644 --- a/web/src/components/automation/AutomationManager.vue +++ b/web/src/components/automation/AutomationManager.vue @@ -1,5 +1,5 @@ @@ -119,6 +117,13 @@ export default { return { tab: "clients", related: {}, + thumbStyle: { + right: "2px", + borderRadius: "5px", + backgroundColor: "#027be3", + width: "5px", + opacity: 0.75, + }, }; }, mounted() {