This commit is contained in:
zandercymatics 2024-06-28 14:55:40 -06:00
parent 98be06e409
commit 7ddf1d87bc
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
4 changed files with 32 additions and 13 deletions

View file

@ -67,8 +67,8 @@ services:
# command: "python"
command: >
bash -c " python manage.py migrate &&
python manage.py load &&
python manage.py createcachetable &&
python manage.py load &&
python manage.py runserver 0.0.0.0:8080"
db:

View file

@ -1690,8 +1690,7 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
return super().save_model(request, obj, form, change)
# == Handle non-status changes == #
# Change this in #1901. Add a check on "not self.action_needed_reason_email"
if obj.action_needed_reason:
if obj.action_needed_reason and not self.action_needed_reason_email:
self._handle_action_needed_reason_email(obj)
should_save = True
@ -1911,14 +1910,17 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
# Call the superclass method with updated extra_context
return super().change_view(request, object_id, form_url, extra_context)
# TODO - scrap this approach and just centralize everything
def get_all_action_needed_reason_emails_as_json(self, domain_request):
"""Returns a json dictionary of every action needed reason and its associated email
for this particular domain request."""
emails = {}
for action_needed_reason in domain_request.ActionNeededReasons:
enum_value = action_needed_reason.value
# Change this in #1901. Just add a check for the current value.
emails[enum_value] = self._get_action_needed_reason_default_email_text(domain_request, enum_value)
if domain_request.action_needed_reason == enum_value and domain_request.action_needed_reason_email:
emails[enum_value] = domain_request.action_needed_reason_email
else:
emails[enum_value] = self._get_action_needed_reason_default_email_text(domain_request, enum_value)
return json.dumps(emails)
def _get_action_needed_reason_default_email_text(self, domain_request, action_needed_reason: str):

View file

@ -672,7 +672,7 @@ class DomainRequest(TimeStampedModel):
logger.error(f"Can't query an approved domain while attempting {called_from}")
def _send_status_update_email(
self, new_status, email_template, email_template_subject, send_email=True, bcc_address="", wrap_email=False
self, new_status, email_template, email_template_subject, bcc_address="", context=None, **kwargs
):
"""Send a status update email to the creator.
@ -683,13 +683,21 @@ class DomainRequest(TimeStampedModel):
If the waffle flag "profile_feature" is active, then this email will be sent to the
domain request creator rather than the submitter
kwargs:
send_email: bool -> Used to bypass the send_templated_email function, in the event
we just want to log that an email would have been sent, rather than actually sending one.
wrap_email: bool -> Wraps emails using `wrap_text_and_preserve_paragraphs` if any given
paragraph exceeds our desired max length (for prettier display).
custom_email_content: str -> Renders an email with the content of this string as its body text.
"""
# Email config options
wrap_email = kwargs.get("wrap_email", False)
send_email = kwargs.get("send_email", True)
custom_email_content = kwargs.get("custom_email_content", None)
recipient = self.creator if flag_is_active(None, "profile_feature") else self.submitter
if recipient is None or recipient.email is None:
logger.warning(
@ -705,15 +713,21 @@ class DomainRequest(TimeStampedModel):
return None
try:
if not context:
context = {
"domain_request": self,
# This is the user that we refer to in the email
"recipient": recipient,
}
if custom_email_content:
context["custom_email_content"] = custom_email_content
send_templated_email(
email_template,
email_template_subject,
recipient.email,
context={
"domain_request": self,
# This is the user that we refer to in the email
"recipient": recipient,
},
context=context,
bcc_address=bcc_address,
wrap_email=wrap_email,
)
@ -844,12 +858,12 @@ class DomainRequest(TimeStampedModel):
if self.action_needed_reason and self.action_needed_reason != self.ActionNeededReasons.OTHER:
self._send_action_needed_reason_email(send_email)
def _send_action_needed_reason_email(self, send_email=True):
def _send_action_needed_reason_email(self, send_email=True, custom_email_content=None):
"""Sends out an automatic email for each valid action needed reason provided"""
# Store the filenames of the template and template subject
email_template_name: str = ""
email_template_subject_name: str = ""
email_template_subject_name: str = "" if not custom_email_content else "custom_email"
# Check for the "type" of action needed reason.
can_send_email = True
@ -877,6 +891,7 @@ class DomainRequest(TimeStampedModel):
email_template_subject=f"emails/action_needed_reasons/{email_template_subject_name}",
send_email=send_email,
bcc_address=bcc_address,
custom_email_content=custom_email_content,
wrap_email=True,
)

View file

@ -0,0 +1,2 @@
{% comment %} {% autoescape off %}{# In a text file, we don't want to have HTML entities escaped #} {% endcomment %}
{{ custom_email_content }}