Skip to content

Commit

Permalink
handle alert template when montype/site changes fixes #1733
Browse files Browse the repository at this point in the history
  • Loading branch information
wh1te909 committed Jan 30, 2024
1 parent 971c218 commit 97b9253
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions api/tacticalrmm/agents/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ class Meta:
def __str__(self) -> str:
return self.hostname

def save(self, *args, **kwargs):
# prevent recursion since calling set_alert_template() also calls save()
if not hasattr(self, "_processing_set_alert_template"):
self._processing_set_alert_template = False

if self.pk and not self._processing_set_alert_template:
orig = Agent.objects.get(pk=self.pk)
mon_type_changed = self.monitoring_type != orig.monitoring_type
site_changed = self.site_id != orig.site_id
if mon_type_changed or site_changed:
self._processing_set_alert_template = True
self.set_alert_template()
self._processing_set_alert_template = False

super().save(*args, **kwargs)

@property
def client(self) -> "Client":
return self.site.client
Expand Down

0 comments on commit 97b9253

Please sign in to comment.