diff --git a/src/registrar/config/urls.py b/src/registrar/config/urls.py index 5cf76886b..486d2269d 100644 --- a/src/registrar/config/urls.py +++ b/src/registrar/config/urls.py @@ -213,7 +213,11 @@ urlpatterns = [ ), path("get-domains-json/", get_domains_json, name="get_domains_json"), path("get-domain-requests-json/", get_domain_requests_json, name="get_domain_requests_json"), - path("get-domain-requests-json//action-needed-email/", get_action_needed_email, name="get_action_needed_email"), + path( + "get-domain-requests-json//action-needed-email/", + get_action_needed_email, + name="get_action_needed_email", + ), ] # Djangooidc strips out context data from that context, so we define a custom error diff --git a/src/registrar/models/domain_request.py b/src/registrar/models/domain_request.py index d393e0380..f9e99f94e 100644 --- a/src/registrar/models/domain_request.py +++ b/src/registrar/models/domain_request.py @@ -557,7 +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: @@ -579,10 +578,9 @@ class DomainRequest(TimeStampedModel): return { "subject_text": subject_template.render(context=context), - "email_body_text": template.render(context=context) + "email_body_text": template.render(context=context), } - def sync_organization_type(self): """ Updates the organization_type (without saving) to match diff --git a/src/registrar/templatetags/custom_filters.py b/src/registrar/templatetags/custom_filters.py index c8eeabf0a..16843ad31 100644 --- a/src/registrar/templatetags/custom_filters.py +++ b/src/registrar/templatetags/custom_filters.py @@ -146,11 +146,12 @@ def format_phone(value): return phone_number.as_national return value + @register.filter def strip_beginning_newline_and_spaces(value): - """Removes any newline characters (and spaces) + """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 \ No newline at end of file + return value diff --git a/src/registrar/tests/common.py b/src/registrar/tests/common.py index 923195bc1..6091e166d 100644 --- a/src/registrar/tests/common.py +++ b/src/registrar/tests/common.py @@ -858,6 +858,7 @@ def completed_domain_request( # noqa is_election_board=False, organization_type=None, federal_agency=None, + action_needed_reason=None, ): """A completed domain request.""" if not user: @@ -921,6 +922,9 @@ def completed_domain_request( # noqa if organization_type: domain_request_kwargs["organization_type"] = organization_type + + if action_needed_reason: + domain_request_kwargs["action_needed_reason"] = action_needed_reason domain_request, _ = DomainRequest.objects.get_or_create(**domain_request_kwargs) diff --git a/src/registrar/tests/test_admin.py b/src/registrar/tests/test_admin.py index 802974b6e..df2869df6 100644 --- a/src/registrar/tests/test_admin.py +++ b/src/registrar/tests/test_admin.py @@ -1595,6 +1595,29 @@ class TestDomainRequestAdmin(MockEppLib): # 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.assertEqual(len(self.mock_client.EMAILS_SENT), 3) + + @less_console_noise_decorator + def test_model_displays_action_needed_email(self): + """Tests if the action needed email is visible for Domain Requests""" + + _domain_request = completed_domain_request( + status=DomainRequest.DomainRequestStatus.ACTION_NEEDED, + action_needed_reason=DomainRequest.ActionNeededReasons.BAD_NAME + ) + + p = "userpass" + self.client.login(username="staffuser", password=p) + response = self.client.get( + "/admin/registrar/domainrequest/{}/change/".format(_domain_request.pk), + follow=True, + ) + + 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): @@ -2290,6 +2313,7 @@ class TestDomainRequestAdmin(MockEppLib): "status", "rejection_reason", "action_needed_reason", + "action_needed_reason_email", "federal_agency", "portfolio", "creator", diff --git a/src/registrar/tests/test_url_auth.py b/src/registrar/tests/test_url_auth.py index 39ca00f4d..362f06dbf 100644 --- a/src/registrar/tests/test_url_auth.py +++ b/src/registrar/tests/test_url_auth.py @@ -24,6 +24,7 @@ SAMPLE_KWARGS = { "object_id": "3", "domain": "whitehouse.gov", "user_pk": "1", + "reason": "bad_name", } # Our test suite will ignore some namespaces. diff --git a/src/registrar/views/domain_requests_json.py b/src/registrar/views/domain_requests_json.py index afc457b00..e7a01e5c9 100644 --- a/src/registrar/views/domain_requests_json.py +++ b/src/registrar/views/domain_requests_json.py @@ -104,17 +104,14 @@ def get_domain_requests_json(request): ) - @login_required def get_action_needed_email(request, pk, reason): has_access = request.user.is_staff or request.user.is_superuser - # TODO also check the perm group + # TODO also check the perm group if not has_access: raise PermissionDenied("You do not have permission to access this resource.") - + domain_request = DomainRequest.objects.filter(id=pk).first() reason_dict = domain_request.get_action_needed_reason_default_email_text(reason) - return JsonResponse( - reason_dict - ) + return JsonResponse(reason_dict)