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) { if(data && data.email_body_text) {
actionNeededEmail.value = 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) { }else if (data && !data.email_body_text) {
if (!noEmailMessage) { actionNeededEmail.value = "No email will be sent";
noEmailMessage = document.createElement("p"); }
noEmailMessage.id = "no-email-message";
noEmailMessage.textContent = "No email will be sent";
actionNeededEmail.parentNode.appendChild(noEmailMessage);
}
// Hide the text field if (data) {
hideElement(actionNeededEmail); actionNeededEmail.value = data.email_body_text ? data.email_body_text : "No email will be sent";
// Show the message
showElement(noEmailMessage);
} }
}); });
}); });

View file

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

View file

@ -557,30 +557,6 @@ class DomainRequest(TimeStampedModel):
blank=True, 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): def sync_organization_type(self):
""" """
Updates the organization_type (without saving) to match Updates the organization_type (without saving) to match
@ -623,12 +599,9 @@ class DomainRequest(TimeStampedModel):
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
"""Save override for custom properties""" """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_organization_type()
self.sync_yes_no_form_fields() self.sync_yes_no_form_fields()
self.sync_action_needed_reason_email()
super().save(*args, **kwargs) super().save(*args, **kwargs)
@ -639,6 +612,12 @@ class DomainRequest(TimeStampedModel):
# Update the cached values after saving # Update the cached values after saving
self._cache_status_and_action_needed_reason() 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): def sync_action_needed_reason(self):
"""Checks if we need to send another action needed email""" """Checks if we need to send another action needed email"""
was_already_action_needed = self._cached_status == self.DomainRequestStatus.ACTION_NEEDED was_already_action_needed = self._cached_status == self.DomainRequestStatus.ACTION_NEEDED
@ -1241,3 +1220,27 @@ class DomainRequest(TimeStampedModel):
return False return False
return True 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> </tbody>
</table> </table>
{% if original_object.action_needed_reason_email %}
<div class="dja-readonly-textarea-container padding-1 margin-top-2 thin-border display-none"> <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"> <label class="max-full" for="action_needed_reason_email_view_more">
<strong>Auto-generated email (sent to submitter)</strong> <strong>Auto-generated email (sent to submitter)</strong>
</label> </label>
<textarea id="action_needed_reason_email_view_more" cols="40" rows="20" class="no-border" readonly> <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> </textarea>
</div> </div>
{% endif %}
</div> </div>

View file

@ -145,13 +145,3 @@ def format_phone(value):
phone_number = PhoneNumber.from_string(value) phone_number = PhoneNumber.from_string(value)
return phone_number.as_national return phone_number.as_national
return value 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

@ -922,7 +922,7 @@ def completed_domain_request( # noqa
if organization_type: if organization_type:
domain_request_kwargs["organization_type"] = organization_type domain_request_kwargs["organization_type"] = organization_type
if action_needed_reason: if action_needed_reason:
domain_request_kwargs["action_needed_reason"] = action_needed_reason domain_request_kwargs["action_needed_reason"] = action_needed_reason

View file

@ -1595,14 +1595,14 @@ class TestDomainRequestAdmin(MockEppLib):
# Test Submitted Status Again from in ACTION_NEEDED, no new email should be sent # Test Submitted Status Again from in ACTION_NEEDED, no new email should be sent
self.transition_state_and_send_email(domain_request, DomainRequest.DomainRequestStatus.SUBMITTED) self.transition_state_and_send_email(domain_request, DomainRequest.DomainRequestStatus.SUBMITTED)
self.assertEqual(len(self.mock_client.EMAILS_SENT), 3) self.assertEqual(len(self.mock_client.EMAILS_SENT), 3)
@less_console_noise_decorator @less_console_noise_decorator
def test_model_displays_action_needed_email(self): def test_model_displays_action_needed_email(self):
"""Tests if the action needed email is visible for Domain Requests""" """Tests if the action needed email is visible for Domain Requests"""
_domain_request = completed_domain_request( _domain_request = completed_domain_request(
status=DomainRequest.DomainRequestStatus.ACTION_NEEDED, status=DomainRequest.DomainRequestStatus.ACTION_NEEDED,
action_needed_reason=DomainRequest.ActionNeededReasons.BAD_NAME action_needed_reason=DomainRequest.ActionNeededReasons.BAD_NAME,
) )
p = "userpass" p = "userpass"
@ -1614,11 +1614,6 @@ class TestDomainRequestAdmin(MockEppLib):
self.assertContains(response, "DOMAIN NAME DOES NOT MEET .GOV REQUIREMENTS") 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) @override_settings(IS_PRODUCTION=True)
def test_save_model_sends_submitted_email_with_bcc_on_prod(self): def test_save_model_sends_submitted_email_with_bcc_on_prod(self):
"""When transitioning to submitted from started or withdrawn on a domain request, """When transitioning to submitted from started or withdrawn on a domain request,