From 5d9886052cafd2553d3119639feb0f3021f20f54 Mon Sep 17 00:00:00 2001 From: Josh Krawczyk Date: Wed, 26 Aug 2020 17:26:22 -0400 Subject: [PATCH] Generate policies and tasks on agent creation --- api/tacticalrmm/api/views.py | 4 ++++ api/tacticalrmm/automation/tests.py | 5 ++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/api/tacticalrmm/api/views.py b/api/tacticalrmm/api/views.py index df78c783..24a4d978 100644 --- a/api/tacticalrmm/api/views.py +++ b/api/tacticalrmm/api/views.py @@ -191,6 +191,10 @@ def add(request): else: WinUpdatePolicy(agent=agent).save() + # Generate policies for new agent + agent.generate_checks_from_policies() + agent.generate_tasks_from_policies() + return Response({"pk": agent.pk}) else: return Response("err", status=status.HTTP_400_BAD_REQUEST) diff --git a/api/tacticalrmm/automation/tests.py b/api/tacticalrmm/automation/tests.py index 61347672..904ff884 100644 --- a/api/tacticalrmm/automation/tests.py +++ b/api/tacticalrmm/automation/tests.py @@ -10,13 +10,12 @@ from .serializers import ( AutoTaskPolicySerializer, PolicyOverviewSerializer, PolicyCheckStatusSerializer, + PolicyCheckSerializer, RelatedAgentPolicySerializer, RelatedSitePolicySerializer, RelatedClientPolicySerializer, ) -from checks.serializers import CheckSerializer - from automation.models import Policy from checks.models import Check from autotasks.models import AutomatedTask @@ -128,7 +127,7 @@ class TestPolicyViews(BaseTestCase): url = f"/automation/{self.policy.pk}/policychecks/" resp = self.client.get(url, format="json") - serializer = CheckSerializer([self.policyDiskCheck], many=True) + serializer = PolicyCheckSerializer([self.policyDiskCheck], many=True) self.assertEqual(resp.status_code, 200) self.assertEqual(resp.data, serializer.data)