mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-19 02:49:21 +02:00
Further refinement
need to fix unit test
This commit is contained in:
parent
646e375708
commit
b68fe55584
4 changed files with 23 additions and 16 deletions
|
@ -1736,16 +1736,21 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
|
|
||||||
# == Handle action_needed_reason == #
|
# == Handle action_needed_reason == #
|
||||||
|
|
||||||
default_email = self._get_action_needed_reason_default_email(obj, obj.action_needed_reason)
|
|
||||||
reason_changed = obj.action_needed_reason != original_obj.action_needed_reason
|
reason_changed = obj.action_needed_reason != original_obj.action_needed_reason
|
||||||
if reason_changed:
|
if reason_changed:
|
||||||
# Track that we sent out an email
|
# Track the fact that we sent out an email
|
||||||
request.session["action_needed_email_sent"] = True
|
request.session["action_needed_email_sent"] = True
|
||||||
|
|
||||||
# Set the action_needed_reason_email to the default.
|
# Set the action_needed_reason_email to the default if nothing exists.
|
||||||
# Since this check occurs after save, if the user enters a value then
|
# Since this check occurs after save, if the user enters a value then we won't update.
|
||||||
# we won't update.
|
|
||||||
if default_email and default_email == obj.action_needed_reason_email:
|
default_email = self._get_action_needed_reason_default_email(obj, obj.action_needed_reason)
|
||||||
|
if obj.action_needed_reason_email:
|
||||||
|
emails = self.get_all_action_needed_reason_emails(obj)
|
||||||
|
is_custom_email = obj.action_needed_reason_email not in emails.values()
|
||||||
|
if not is_custom_email:
|
||||||
|
obj.action_needed_reason_email = default_email
|
||||||
|
else:
|
||||||
obj.action_needed_reason_email = default_email
|
obj.action_needed_reason_email = default_email
|
||||||
|
|
||||||
# == Handle status == #
|
# == Handle status == #
|
||||||
|
@ -1953,7 +1958,8 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
# Initialize extra_context and add filtered entries
|
# Initialize extra_context and add filtered entries
|
||||||
extra_context = extra_context or {}
|
extra_context = extra_context or {}
|
||||||
extra_context["filtered_audit_log_entries"] = filtered_audit_log_entries
|
extra_context["filtered_audit_log_entries"] = filtered_audit_log_entries
|
||||||
extra_context["action_needed_reason_emails"] = self.get_all_action_needed_reason_emails_as_json(obj)
|
emails = self.get_all_action_needed_reason_emails(obj)
|
||||||
|
extra_context["action_needed_reason_emails"] = json.dumps(emails)
|
||||||
extra_context["has_profile_feature_flag"] = flag_is_active(request, "profile_feature")
|
extra_context["has_profile_feature_flag"] = flag_is_active(request, "profile_feature")
|
||||||
|
|
||||||
# Denote if an action needed email was sent or not
|
# Denote if an action needed email was sent or not
|
||||||
|
@ -1965,16 +1971,18 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
# Call the superclass method with updated extra_context
|
# Call the superclass method with updated extra_context
|
||||||
return super().change_view(request, object_id, form_url, extra_context)
|
return super().change_view(request, object_id, form_url, extra_context)
|
||||||
|
|
||||||
def get_all_action_needed_reason_emails_as_json(self, domain_request):
|
def get_all_action_needed_reason_emails(self, domain_request):
|
||||||
"""Returns a json dictionary of every action needed reason and its associated email
|
"""Returns a json dictionary of every action needed reason and its associated email
|
||||||
for this particular domain request."""
|
for this particular domain request."""
|
||||||
|
|
||||||
emails = {}
|
emails = {}
|
||||||
for action_needed_reason in domain_request.ActionNeededReasons:
|
for action_needed_reason in domain_request.ActionNeededReasons:
|
||||||
# Map the action_needed_reason to its default email
|
# Map the action_needed_reason to its default email
|
||||||
emails[action_needed_reason.value] = self._get_action_needed_reason_default_email(
|
emails[action_needed_reason.value] = self._get_action_needed_reason_default_email(
|
||||||
domain_request, action_needed_reason.value
|
domain_request, action_needed_reason.value
|
||||||
)
|
)
|
||||||
return json.dumps(emails)
|
|
||||||
|
return emails
|
||||||
|
|
||||||
def _get_action_needed_reason_default_email(self, domain_request, action_needed_reason):
|
def _get_action_needed_reason_default_email(self, domain_request, action_needed_reason):
|
||||||
"""Returns the default email associated with the given action needed reason"""
|
"""Returns the default email associated with the given action needed reason"""
|
||||||
|
|
|
@ -563,11 +563,9 @@ function initializeWidgetOnList(list, parentId) {
|
||||||
if (sessionStorage.getItem(emailSentSessionVariableName) !== null) {
|
if (sessionStorage.getItem(emailSentSessionVariableName) !== null) {
|
||||||
// Show the readonly field, hide the editable field
|
// Show the readonly field, hide the editable field
|
||||||
showReadonly(actionNeededEmail.parentElement)
|
showReadonly(actionNeededEmail.parentElement)
|
||||||
console.log("adding data")
|
|
||||||
}else {
|
}else {
|
||||||
// No email was sent out -- show the editable field
|
// No email was sent out -- show the editable field
|
||||||
hideReadonly(actionNeededEmail.parentElement)
|
hideReadonly(actionNeededEmail.parentElement)
|
||||||
console.log("removing data")
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -593,7 +591,6 @@ function initializeWidgetOnList(list, parentId) {
|
||||||
if (oldDropdownValue !== actionNeededReasonDropdown.value || oldEmailValue !== actionNeededEmail.value) {
|
if (oldDropdownValue !== actionNeededReasonDropdown.value || oldEmailValue !== actionNeededEmail.value) {
|
||||||
let emailSent = sessionStorage.getItem(emailSentSessionVariableName)
|
let emailSent = sessionStorage.getItem(emailSentSessionVariableName)
|
||||||
if (emailSent !== null){
|
if (emailSent !== null){
|
||||||
console.log("removing data")
|
|
||||||
addOrRemoveSessionBoolean(emailSentSessionVariableName, add=false)
|
addOrRemoveSessionBoolean(emailSentSessionVariableName, add=false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -597,7 +597,6 @@ class DomainRequest(TimeStampedModel):
|
||||||
def _cache_status_and_action_needed_reason(self):
|
def _cache_status_and_action_needed_reason(self):
|
||||||
"""Maintains a cache of properties so we can avoid a DB call"""
|
"""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 = self.action_needed_reason
|
||||||
self._cached_action_needed_reason_email = self.action_needed_reason_email
|
|
||||||
self._cached_status = self.status
|
self._cached_status = self.status
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
@ -625,6 +624,7 @@ class DomainRequest(TimeStampedModel):
|
||||||
was_already_action_needed = self._cached_status == self.DomainRequestStatus.ACTION_NEEDED
|
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_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
|
reason_changed = self._cached_action_needed_reason != self.action_needed_reason
|
||||||
|
print(f"was_already_action_needed {was_already_action_needed} reason_exists {reason_exists} and {reason_changed}")
|
||||||
if was_already_action_needed and reason_exists and reason_changed:
|
if was_already_action_needed and reason_exists and reason_changed:
|
||||||
# We don't send emails out in state "other"
|
# We don't send emails out in state "other"
|
||||||
if self.action_needed_reason != self.ActionNeededReasons.OTHER:
|
if self.action_needed_reason != self.ActionNeededReasons.OTHER:
|
||||||
|
|
|
@ -1385,6 +1385,9 @@ class TestDomainRequestAdmin(MockEppLib):
|
||||||
# Create a mock request
|
# Create a mock request
|
||||||
request = self.factory.post("/admin/registrar/domainrequest/{}/change/".format(domain_request.pk))
|
request = self.factory.post("/admin/registrar/domainrequest/{}/change/".format(domain_request.pk))
|
||||||
|
|
||||||
|
# Create a fake session to hook to
|
||||||
|
request.session = {}
|
||||||
|
|
||||||
# Modify the domain request's properties
|
# Modify the domain request's properties
|
||||||
domain_request.status = status
|
domain_request.status = status
|
||||||
|
|
||||||
|
@ -1450,6 +1453,7 @@ class TestDomainRequestAdmin(MockEppLib):
|
||||||
# Test the email sent out for already_has_domains
|
# Test the email sent out for already_has_domains
|
||||||
already_has_domains = DomainRequest.ActionNeededReasons.ALREADY_HAS_DOMAINS
|
already_has_domains = DomainRequest.ActionNeededReasons.ALREADY_HAS_DOMAINS
|
||||||
self.transition_state_and_send_email(domain_request, action_needed, action_needed_reason=already_has_domains)
|
self.transition_state_and_send_email(domain_request, action_needed, action_needed_reason=already_has_domains)
|
||||||
|
|
||||||
self.assert_email_is_accurate("ORGANIZATION ALREADY HAS A .GOV DOMAIN", 0, EMAIL, bcc_email_address=BCC_EMAIL)
|
self.assert_email_is_accurate("ORGANIZATION ALREADY HAS A .GOV DOMAIN", 0, EMAIL, bcc_email_address=BCC_EMAIL)
|
||||||
self.assertEqual(len(self.mock_client.EMAILS_SENT), 1)
|
self.assertEqual(len(self.mock_client.EMAILS_SENT), 1)
|
||||||
|
|
||||||
|
@ -1493,6 +1497,7 @@ class TestDomainRequestAdmin(MockEppLib):
|
||||||
action_needed_reason_email="custom email content",
|
action_needed_reason_email="custom email content",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
domain_request.refresh_from_db()
|
||||||
self.assert_email_is_accurate("custom email content", 4, EMAIL, bcc_email_address=BCC_EMAIL)
|
self.assert_email_is_accurate("custom email content", 4, EMAIL, bcc_email_address=BCC_EMAIL)
|
||||||
self.assertEqual(len(self.mock_client.EMAILS_SENT), 5)
|
self.assertEqual(len(self.mock_client.EMAILS_SENT), 5)
|
||||||
|
|
||||||
|
@ -1510,9 +1515,6 @@ class TestDomainRequestAdmin(MockEppLib):
|
||||||
# Set the request back to in review
|
# Set the request back to in review
|
||||||
domain_request.in_review()
|
domain_request.in_review()
|
||||||
|
|
||||||
# no email was sent, so no email should be stored
|
|
||||||
self.assertEqual(domain_request.action_needed_reason_email, None)
|
|
||||||
|
|
||||||
# Try sending another email when changing states AND including content
|
# Try sending another email when changing states AND including content
|
||||||
self.transition_state_and_send_email(
|
self.transition_state_and_send_email(
|
||||||
domain_request,
|
domain_request,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue