mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-17 18:09:25 +02:00
Add endpoint
This commit is contained in:
parent
91a92ae11e
commit
9f89f2e2ff
3 changed files with 49 additions and 1 deletions
|
@ -22,7 +22,7 @@ from registrar.views.admin_views import (
|
||||||
)
|
)
|
||||||
|
|
||||||
from registrar.views.domain_request import Step
|
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.domains_json import get_domains_json
|
||||||
from registrar.views.utility import always_404
|
from registrar.views.utility import always_404
|
||||||
from api.views import available, get_current_federal, get_current_full
|
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-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/", get_domain_requests_json, name="get_domain_requests_json"),
|
||||||
|
path("get-domain-requests-json/<int:pk>/action-needed-email/<str:reason>", get_action_needed_email, name="get_action_needed_email"),
|
||||||
]
|
]
|
||||||
|
|
||||||
# Djangooidc strips out context data from that context, so we define a custom error
|
# Djangooidc strips out context data from that context, so we define a custom error
|
||||||
|
|
|
@ -12,6 +12,7 @@ from registrar.models.federal_agency import FederalAgency
|
||||||
from registrar.models.utility.generic_helper import CreateOrUpdateOrganizationTypeHelper
|
from registrar.models.utility.generic_helper import CreateOrUpdateOrganizationTypeHelper
|
||||||
from registrar.utility.errors import FSMDomainRequestError, FSMErrorCodes
|
from registrar.utility.errors import FSMDomainRequestError, FSMErrorCodes
|
||||||
from registrar.utility.constants import BranchChoices
|
from registrar.utility.constants import BranchChoices
|
||||||
|
from django.template.loader import get_template
|
||||||
|
|
||||||
from .utility.time_stamped_model import TimeStampedModel
|
from .utility.time_stamped_model import TimeStampedModel
|
||||||
from ..utility.email import send_templated_email, EmailSendingError
|
from ..utility.email import send_templated_email, EmailSendingError
|
||||||
|
@ -541,6 +542,29 @@ class DomainRequest(TimeStampedModel):
|
||||||
blank=True,
|
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):
|
def sync_organization_type(self):
|
||||||
"""
|
"""
|
||||||
Updates the organization_type (without saving) to match
|
Updates the organization_type (without saving) to match
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import logging
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
from registrar.models import DomainRequest
|
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.contrib.auth.decorators import login_required
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
from django.core.exceptions import PermissionDenied
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -97,3 +102,21 @@ def get_domain_requests_json(request):
|
||||||
"unfiltered_total": unfiltered_total,
|
"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
|
||||||
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue