From 24c899c91ac5d5c3bd99894d6c7a624e9a692377 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 3 Oct 2022 12:05:32 +0100 Subject: [PATCH 1/2] break from loop once a valid policy is found. remove old unused list Signed-off-by: Adam --- api/tacticalrmm/agents/models.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/api/tacticalrmm/agents/models.py b/api/tacticalrmm/agents/models.py index 0122dbac..6e75ac24 100644 --- a/api/tacticalrmm/agents/models.py +++ b/api/tacticalrmm/agents/models.py @@ -618,17 +618,18 @@ class Agent(BaseAuditModel): if not agent_policy: agent_policy = WinUpdatePolicy.objects.create(agent=self) + # Get the list of policies applied to the agent and select the + # highest priority one. policies = self.get_agent_policies() - processed_policies: List[int] = [] for _, policy in policies.items(): if ( policy and policy.active - and policy.pk not in processed_policies and policy.winupdatepolicy.exists() ): patch_policy = policy.winupdatepolicy.first() + break # if policy still doesn't exist return the agent patch policy if not patch_policy: From db4540089ae3d415cc239d5025859d7008fcaf94 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 3 Oct 2022 13:17:48 +0100 Subject: [PATCH 2/2] remove parentheses from if statement to fix codestyle test Signed-off-by: Adam --- api/tacticalrmm/agents/models.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/api/tacticalrmm/agents/models.py b/api/tacticalrmm/agents/models.py index 6e75ac24..157ef81e 100644 --- a/api/tacticalrmm/agents/models.py +++ b/api/tacticalrmm/agents/models.py @@ -623,11 +623,7 @@ class Agent(BaseAuditModel): policies = self.get_agent_policies() for _, policy in policies.items(): - if ( - policy - and policy.active - and policy.winupdatepolicy.exists() - ): + if policy and policy.active and policy.winupdatepolicy.exists(): patch_policy = policy.winupdatepolicy.first() break