diff --git a/src/registrar/models/domain_request.py b/src/registrar/models/domain_request.py
index 8f6dc44e8..b9e3315d5 100644
--- a/src/registrar/models/domain_request.py
+++ b/src/registrar/models/domain_request.py
@@ -704,6 +704,7 @@ class DomainRequest(TimeStampedModel):
# We should never send an email if no reason was specified.
# Additionally, Don't send out emails for reasons that shouldn't send them.
if status_info.get("reason") is None or status_info.get("reason") in status_info.get("excluded_reasons"):
+ logger.warning("send_custom_status_update_email() => Tried sending a status email without a reason.")
return
# Only send out an email if the underlying reason itself changed or if no email was sent previously.
@@ -1064,8 +1065,15 @@ class DomainRequest(TimeStampedModel):
def reject(self):
"""Reject an domain request that has been submitted.
+ This action is logged.
+
+ This action cleans up the action needed status if moving away from action needed.
+
As side effects this will delete the domain and domain_information
- (will cascade), and send an email notification using send_custom_status_update_email.
+ (will cascade) when they exist.
+
+ Afterwards, we send out an email for reject in def save().
+ See the function send_custom_status_update_email.
"""
if self.status == self.DomainRequestStatus.APPROVED:
diff --git a/src/registrar/templates/django/admin/includes/detail_table_fieldset.html b/src/registrar/templates/django/admin/includes/detail_table_fieldset.html
index 6a46fd9f2..f9aa9ac19 100644
--- a/src/registrar/templates/django/admin/includes/detail_table_fieldset.html
+++ b/src/registrar/templates/django/admin/includes/detail_table_fieldset.html
@@ -221,9 +221,9 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html)
{% if original_object.action_needed_reason_email %}
-
+
{% else %}
-
+
{% endif %}
{% elif field.field.name == "rejection_reason_email" %}
@@ -310,9 +310,9 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html)
{% if original_object.rejection_reason_email %}
-
+
{% else %}
-
+
{% endif %}
{% else %}
{{ field.field }}
diff --git a/src/registrar/tests/test_admin_request.py b/src/registrar/tests/test_admin_request.py
index cdff63124..217756359 100644
--- a/src/registrar/tests/test_admin_request.py
+++ b/src/registrar/tests/test_admin_request.py
@@ -637,7 +637,6 @@ class TestDomainRequestAdmin(MockEppLib):
with less_console_noise():
# Access the arguments passed to send_email
call_args = self.mock_client.EMAILS_SENT
- logger.info(f"what are the call args? {call_args}")
kwargs = call_args[email_index]["kwargs"]
# Retrieve the email details from the arguments
diff --git a/src/registrar/tests/test_models_requests.py b/src/registrar/tests/test_models_requests.py
index 3be2225ee..ea0303230 100644
--- a/src/registrar/tests/test_models_requests.py
+++ b/src/registrar/tests/test_models_requests.py
@@ -267,7 +267,6 @@ class TestDomainRequest(TestCase):
domain_request.submit()
self.assertEqual(domain_request.status, domain_request.DomainRequestStatus.SUBMITTED)
- @less_console_noise_decorator
def check_email_sent(
self, domain_request, msg, action, expected_count, expected_content=None, expected_email="mayor@igorville.com"
):
@@ -278,6 +277,7 @@ class TestDomainRequest(TestCase):
# Perform the specified action
action_method = getattr(domain_request, action)
action_method()
+ domain_request.save()
# Check if an email was sent
sent_emails = [
@@ -337,6 +337,31 @@ class TestDomainRequest(TestCase):
domain_request, msg, "withdraw", 1, expected_content="withdrawn", expected_email=user.email
)
+ def test_reject_sends_email(self):
+ "Create a domain request and reject it and see if email was sent."
+ user, _ = User.objects.get_or_create(username="testy")
+ domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.APPROVED, user=user)
+ expected_email=user.email
+ email_allowed, _ = AllowedEmail.objects.get_or_create(email=expected_email)
+ with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
+ domain_request.reject()
+ domain_request.rejection_reason = domain_request.RejectionReasons.CONTACTS_NOT_VERIFIED
+ domain_request.rejection_reason_email = "test"
+ domain_request.save()
+
+ # Check if an email was sent
+ sent_emails = [
+ email
+ for email in MockSESClient.EMAILS_SENT
+ if expected_email in email["kwargs"]["Destination"]["ToAddresses"]
+ ]
+ self.assertEqual(len(sent_emails), 1)
+
+ email_content = sent_emails[0]["kwargs"]["Content"]["Simple"]["Body"]["Text"]["Data"]
+ self.assertIn("test", email_content)
+
+ email_allowed.delete()
+
@less_console_noise_decorator
def test_reject_with_prejudice_does_not_send_email(self):
msg = "Create a domain request and reject it with prejudice and see if email was sent."