diff --git a/src/registrar/admin.py b/src/registrar/admin.py index a5e66dff4..6776b8834 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -1,7 +1,8 @@ from datetime import date import logging import copy - +import json +from django.template.loader import get_template from django import forms from django.db.models import Value, CharField, Q from django.db.models.functions import Concat, Coalesce @@ -1845,11 +1846,45 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin): # Initialize extra_context and add filtered entries extra_context = extra_context or {} extra_context["filtered_audit_log_entries"] = filtered_audit_log_entries - extra_context["action_needed_reason_emails"] = obj.get_all_action_needed_reason_emails_as_json() + extra_context["action_needed_reason_emails"] = self.get_all_action_needed_reason_emails_as_json(obj) # Call the superclass method with updated 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): + """Returns a json dictionary of every action needed reason and its associated email + for this particular domain request.""" + emails = {} + for action_needed_reason in domain_request.ActionNeededReasons: + enum_value = action_needed_reason.value + # Change this in #1901. Just add a check for the current value. + emails[enum_value] = self._get_action_needed_reason_default_email_text(domain_request, enum_value) + return json.dumps(emails) + + def _get_action_needed_reason_default_email_text(self, domain_request, 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 == domain_request.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": domain_request} + + return { + "subject_text": subject_template.render(context=context), + "email_body_text": template.render(context=context), + } + def process_log_entry(self, log_entry): """Process a log entry and return filtered entry dictionary if applicable.""" changes = log_entry.changes diff --git a/src/registrar/assets/js/get-gov-admin.js b/src/registrar/assets/js/get-gov-admin.js index 673f5fe6c..140421db5 100644 --- a/src/registrar/assets/js/get-gov-admin.js +++ b/src/registrar/assets/js/get-gov-admin.js @@ -548,8 +548,8 @@ function initializeWidgetOnList(list, parentId) { })(); -/** An IIFE that hooks up to the "show email" button - * which shows the auto generated email on action needed reason +/** An IIFE that hooks up to the "show email" button. + * which shows the auto generated email on action needed reason. */ (function () { let actionNeededReasonDropdown = document.querySelector("#id_action_needed_reason"); @@ -562,7 +562,6 @@ function initializeWidgetOnList(list, parentId) { function handleChangeActionNeededEmail(actionNeededReasonDropdown, actionNeededEmail) { actionNeededReasonDropdown.addEventListener("change", function() { let reason = actionNeededReasonDropdown.value; - const pk = document.querySelector("#domain_request_id").value; // If a reason isn't specified, no email will be sent. // You also cannot save the model in this state. @@ -603,4 +602,4 @@ function initializeWidgetOnList(list, parentId) { showElement(noEmailMessage); } -})(); \ No newline at end of file +})(); diff --git a/src/registrar/assets/sass/_theme/_admin.scss b/src/registrar/assets/sass/_theme/_admin.scss index bdaaf7c98..bf651f663 100644 --- a/src/registrar/assets/sass/_theme/_admin.scss +++ b/src/registrar/assets/sass/_theme/_admin.scss @@ -826,4 +826,4 @@ div.dja__model-description{ .display-none { // Many elements in django admin try to override this, so we need !important. display: none !important; -} \ No newline at end of file +} diff --git a/src/registrar/models/domain_request.py b/src/registrar/models/domain_request.py index 131543178..b44ceb678 100644 --- a/src/registrar/models/domain_request.py +++ b/src/registrar/models/domain_request.py @@ -1,7 +1,6 @@ from __future__ import annotations from typing import Union import logging -import json from django.apps import apps from django.conf import settings @@ -13,7 +12,6 @@ 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 @@ -1220,36 +1218,3 @@ class DomainRequest(TimeStampedModel): return False return True - - def get_all_action_needed_reason_emails_as_json(self): - """Returns a json dictionary of every action needed reason and its associated email - for this particular domain request.""" - emails = {} - for action_needed_reason in self.ActionNeededReasons: - enum_value = action_needed_reason.value - emails[enum_value] = self.get_action_needed_reason_default_email_text(enum_value) - return json.dumps(emails) - - 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), - }