This commit is contained in:
zandercymatics 2024-06-20 13:14:03 -06:00
parent 3441a3974f
commit 214fbc4d5d
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
7 changed files with 42 additions and 68 deletions

View file

@ -586,27 +586,14 @@ function initializeWidgetOnList(list, parentId) {
if(data && data.email_body_text) {
actionNeededEmail.value = data.email_body_text
// Show the text field
showElement(actionNeededEmail);
// Hide the "no email" message
if(noEmailMessage) {
hideElement(noEmailMessage);
}
}else if (data && !data.email_body_text) {
if (!noEmailMessage) {
noEmailMessage = document.createElement("p");
noEmailMessage.id = "no-email-message";
noEmailMessage.textContent = "No email will be sent";
actionNeededEmail.parentNode.appendChild(noEmailMessage);
actionNeededEmail.value = "No email will be sent";
}
// Hide the text field
hideElement(actionNeededEmail);
// Show the message
showElement(noEmailMessage);
if (data) {
actionNeededEmail.value = data.email_body_text ? data.email_body_text : "No email will be sent";
}
});
});

View file

@ -791,7 +791,8 @@ div.dja__model-description{
textarea {
width: 100%;
resize: none;
cursor: pointer;
cursor: auto;
border-width: medium;
&::-webkit-scrollbar {
background-color: transparent;
@ -821,5 +822,5 @@ div.dja__model-description{
}
.no-border {
border: none
border: none;
}

View file

@ -557,30 +557,6 @@ class DomainRequest(TimeStampedModel):
blank=True,
)
def get_action_needed_reason_default_email_text(self, action_needed_reason: str):
"""Returns the default email associated with the given action needed reason"""
if action_needed_reason is None or action_needed_reason == self.ActionNeededReasons.OTHER:
return {
"subject_text": None,
"email_body_text": None,
}
# Get the email body
template_path = f"emails/action_needed_reasons/{action_needed_reason}.txt"
template = get_template(template_path)
# Get the email subject
template_subject_path = f"emails/action_needed_reasons/{action_needed_reason}_subject.txt"
subject_template = get_template(template_subject_path)
# Return the content of the rendered views
context = {"domain_request": self}
return {
"subject_text": subject_template.render(context=context),
"email_body_text": template.render(context=context),
}
def sync_organization_type(self):
"""
Updates the organization_type (without saving) to match
@ -623,12 +599,9 @@ class DomainRequest(TimeStampedModel):
def save(self, *args, **kwargs):
"""Save override for custom properties"""
if self.action_needed_reason and not self.action_needed_reason_email:
text = self.get_action_needed_reason_default_email_text(self.action_needed_reason)
self.action_needed_reason_email = text.get("email_body_text")
self.sync_organization_type()
self.sync_yes_no_form_fields()
self.sync_action_needed_reason_email()
super().save(*args, **kwargs)
@ -639,6 +612,12 @@ class DomainRequest(TimeStampedModel):
# Update the cached values after saving
self._cache_status_and_action_needed_reason()
def sync_action_needed_reason_email(self):
"""If no action_needed_reason_email is defined, add a default one"""
if self.action_needed_reason and not self.action_needed_reason_email:
text = self.get_action_needed_reason_default_email_text(self.action_needed_reason)
self.action_needed_reason_email = text.get("email_body_text")
def sync_action_needed_reason(self):
"""Checks if we need to send another action needed email"""
was_already_action_needed = self._cached_status == self.DomainRequestStatus.ACTION_NEEDED
@ -1241,3 +1220,27 @@ class DomainRequest(TimeStampedModel):
return False
return True
def get_action_needed_reason_default_email_text(self, action_needed_reason: str):
"""Returns the default email associated with the given action needed reason"""
if action_needed_reason is None or action_needed_reason == self.ActionNeededReasons.OTHER:
return {
"subject_text": None,
"email_body_text": None,
}
# Get the email body
template_path = f"emails/action_needed_reasons/{action_needed_reason}.txt"
template = get_template(template_path)
# Get the email subject
template_subject_path = f"emails/action_needed_reasons/{action_needed_reason}_subject.txt"
subject_template = get_template(template_subject_path)
# Return the content of the rendered views
context = {"domain_request": self}
return {
"subject_text": subject_template.render(context=context),
"email_body_text": template.render(context=context),
}

View file

@ -106,16 +106,14 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html)
</tbody>
</table>
{% if original_object.action_needed_reason_email %}
<div class="dja-readonly-textarea-container padding-1 margin-top-2 thin-border display-none">
<label class="max-full" for="action_needed_reason_email_view_more">
<strong>Auto-generated email (sent to submitter)</strong>
</label>
<textarea id="action_needed_reason_email_view_more" cols="40" rows="20" class="no-border" readonly>
{{ original_object.action_needed_reason_email|strip_beginning_newline_and_spaces }}
{{ original_object.action_needed_reason_email }}
</textarea>
</div>
{% endif %}
</div>

View file

@ -145,13 +145,3 @@ def format_phone(value):
phone_number = PhoneNumber.from_string(value)
return phone_number.as_national
return value
@register.filter
def strip_beginning_newline_and_spaces(value):
"""Removes any newline characters (and spaces)
on the first line of a given string"""
if value and isinstance(value, str):
return value.lstrip("\n").lstrip(" ")
else:
return value

View file

@ -1602,7 +1602,7 @@ class TestDomainRequestAdmin(MockEppLib):
_domain_request = completed_domain_request(
status=DomainRequest.DomainRequestStatus.ACTION_NEEDED,
action_needed_reason=DomainRequest.ActionNeededReasons.BAD_NAME
action_needed_reason=DomainRequest.ActionNeededReasons.BAD_NAME,
)
p = "userpass"
@ -1614,11 +1614,6 @@ class TestDomainRequestAdmin(MockEppLib):
self.assertContains(response, "DOMAIN NAME DOES NOT MEET .GOV REQUIREMENTS")
_domain_request.action_needed_reason = DomainRequest.ActionNeededReasons.OTHER
_domain_request.save()
self.assertContains(response, "No email will be sent")
@override_settings(IS_PRODUCTION=True)
def test_save_model_sends_submitted_email_with_bcc_on_prod(self):
"""When transitioning to submitted from started or withdrawn on a domain request,