diff --git a/src/registrar/config/urls.py b/src/registrar/config/urls.py index dc6c8acb5..5cf76886b 100644 --- a/src/registrar/config/urls.py +++ b/src/registrar/config/urls.py @@ -22,7 +22,7 @@ from registrar.views.admin_views import ( ) from registrar.views.domain_request import Step -from registrar.views.domain_requests_json import get_domain_requests_json +from registrar.views.domain_requests_json import get_domain_requests_json, get_action_needed_email from registrar.views.domains_json import get_domains_json from registrar.views.utility import always_404 from api.views import available, get_current_federal, get_current_full @@ -213,6 +213,7 @@ 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"), ] # 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 4f306f403..7a7f46f65 100644 --- a/src/registrar/models/domain_request.py +++ b/src/registrar/models/domain_request.py @@ -12,6 +12,7 @@ from registrar.models.federal_agency import FederalAgency from registrar.models.utility.generic_helper import CreateOrUpdateOrganizationTypeHelper from registrar.utility.errors import FSMDomainRequestError, FSMErrorCodes from registrar.utility.constants import BranchChoices +from django.template.loader import get_template from .utility.time_stamped_model import TimeStampedModel from ..utility.email import send_templated_email, EmailSendingError @@ -541,6 +542,29 @@ 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""" + logger.info(f"reason? {action_needed_reason}") + if action_needed_reason is None or action_needed_reason == self.ActionNeededReasons.OTHER: + return {} + + # 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 diff --git a/src/registrar/views/domain_requests_json.py b/src/registrar/views/domain_requests_json.py index 2e58c8e48..21096891b 100644 --- a/src/registrar/views/domain_requests_json.py +++ b/src/registrar/views/domain_requests_json.py @@ -1,3 +1,4 @@ +import logging from django.http import JsonResponse from django.core.paginator import Paginator from registrar.models import DomainRequest @@ -5,6 +6,10 @@ from django.utils.dateformat import format from django.contrib.auth.decorators import login_required from django.urls import reverse from django.db.models import Q +from django.core.exceptions import PermissionDenied + + +logger = logging.getLogger(__name__) @login_required @@ -97,3 +102,21 @@ def get_domain_requests_json(request): "unfiltered_total": unfiltered_total, } ) + + + +@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 + if not has_access: + raise PermissionDenied("You do not have permission to access this resource.") + + logger.info(f"pk: {pk} reason: {reason}") + domain_request = DomainRequest.objects.filter(id=pk).first() + + reason_dict = domain_request.get_action_needed_reason_default_email_text(reason) + + return JsonResponse( + reason_dict + )