Add logic for if just the email is changed

This commit is contained in:
zandercymatics 2024-07-08 08:47:44 -06:00
parent 204b907a54
commit f18b10d669
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
2 changed files with 28 additions and 6 deletions

View file

@ -598,6 +598,7 @@ class DomainRequest(TimeStampedModel):
def _cache_status_and_action_needed_reason(self):
"""Maintains a cache of properties so we can avoid a DB call"""
self._cached_action_needed_reason = self.action_needed_reason
self._cached_action_needed_reason_email = self.action_needed_reason_email
self._cached_status = self.status
def __init__(self, *args, **kwargs):
@ -614,7 +615,8 @@ class DomainRequest(TimeStampedModel):
# Handle the action needed email. We send one when moving to action_needed,
# but we don't send one when we are _already_ in the state and change the reason.
self.sync_action_needed_reason()
if self.status == self.DomainRequestStatus.ACTION_NEEDED and self.action_needed_reason:
self.sync_action_needed_reason()
# Update the cached values after saving
self._cache_status_and_action_needed_reason()
@ -624,7 +626,8 @@ class DomainRequest(TimeStampedModel):
was_already_action_needed = self._cached_status == self.DomainRequestStatus.ACTION_NEEDED
reason_exists = self._cached_action_needed_reason is not None and self.action_needed_reason is not None
reason_changed = self._cached_action_needed_reason != self.action_needed_reason
if was_already_action_needed and (reason_exists and reason_changed):
reason_email_changed = self._cached_action_needed_reason_email != self.action_needed_reason_email
if was_already_action_needed and (reason_exists and reason_changed or reason_email_changed):
# We don't send emails out in state "other"
if self.action_needed_reason != self.ActionNeededReasons.OTHER:
self._send_action_needed_reason_email(email_content=self.action_needed_reason_email)