fix other checks getting deleted when deleting a policy check

This commit is contained in:
sadnub
2021-05-04 20:01:44 -04:00
parent 589ff46ea5
commit 10bc133cf1
2 changed files with 4 additions and 2 deletions

View File

@@ -430,11 +430,12 @@ class Policy(BaseAuditModel):
# remove policy checks from agent that fell out of policy scope
agent.agentchecks.filter(
managed_by_policy=True,
parent_check__in=[
checkpk
for checkpk in agent_checks_parent_pks
if checkpk not in [check.pk for check in final_list]
]
],
).delete()
return [

View File

@@ -123,11 +123,12 @@ class GetUpdateDeleteCheck(APIView):
from automation.tasks import generate_agent_checks_task
check = get_object_or_404(Check, pk=pk)
check.delete()
# Policy check deleted
if check.policy:
Check.objects.filter(parent_check=check.pk).delete()
Check.objects.filter(managed_by_policy=True, parent_check=pk).delete()
# Re-evaluate agent checks is policy was enforced
if check.policy.enforced: