use id instead of session for domain requests

This commit is contained in:
zandercymatics 2024-10-31 15:10:12 -06:00
parent e19923f86f
commit aa930eb77c
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
16 changed files with 46 additions and 59 deletions

View file

@ -39,10 +39,11 @@ from registrar.views.utility import always_404
from api.views import available, rdap, get_current_federal, get_current_full
DOMAIN_REQUEST_NAMESPACE = views.DomainRequestWizard.URL_NAMESPACE
domain_request_urls = [
path("", views.DomainRequestWizard.as_view(), name=""),
domain_request_start_and_finished_urls = [
path("start/", views.DomainRequestWizard.as_view(), name="start"),
path("finished/", views.Finished.as_view(), name="finished"),
]
domain_request_urls = []
# dynamically generate the other domain_request_urls
for step, view in [
@ -253,7 +254,9 @@ urlpatterns = [
),
path("health", views.health, name="health"),
path("openid/", include("djangooidc.urls")),
path("request/", include((domain_request_urls, DOMAIN_REQUEST_NAMESPACE))),
path("request/start/", views.DomainRequestWizard.as_view(), name="start"),
#path("request/", include((domain_request_start_and_finished_urls, DOMAIN_REQUEST_NAMESPACE))),
path("request/<int:pk>/", include((domain_request_urls, DOMAIN_REQUEST_NAMESPACE))),
path("api/v1/available/", available, name="available"),
path("api/v1/rdap/", rdap, name="rdap"),
path("api/v1/get-report/current-federal", get_current_federal, name="get-current-federal"),

View file

@ -100,7 +100,7 @@ class CheckUserProfileMiddleware:
# In some cases, we don't want to redirect to home. This handles that.
# Can easily be generalized if need be, but for now lets keep this easy to read.
custom_redirect = "domain-request:" if request.path == "/request/" else None
custom_redirect = "domain-request:start" if request.path == "/request/" else None
# Don't redirect on excluded pages (such as the setup page itself)
if not any(request.path.startswith(page) for page in self._get_excluded_pages(profile_page)):

View file

@ -11,7 +11,7 @@
<div class="tablet:grid-col-9">
<main id="main-content" class="grid-container register-form-step">
{% if steps.prev %}
<a href="{% namespaced_url 'domain-request' steps.prev %}" class="breadcrumb__back">
<a href="{% namespaced_url 'domain-request' steps.prev pk=domain_request_id %}" class="breadcrumb__back">
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img" width="24" height="24">
<use xlink:href="{%static 'img/sprite.svg'%}#arrow_back"></use>
</svg><span class="margin-left-05">Previous step</span>

View file

@ -21,7 +21,7 @@
<p>If you have <a href="{% public_site_url 'domains/before/#information-you%E2%80%99ll-need-to-complete-the-domain-request-form' %}" target="_blank" class="usa-link">all the information you need</a>,
completing your domain request might take around 15 minutes.</p>
<h2>How well reach you</h2>
<p>While reviewing your domain request, we may need to reach out with questions. Well also email you when we complete our review. If the contact information below is not correct, visit <a href="{% url 'user-profile' %}?redirect=domain-request:" class="usa-link">your profile</a> to make updates.</p>
<p>While reviewing your domain request, we may need to reach out with questions. Well also email you when we complete our review. If the contact information below is not correct, visit <a href="{% url 'user-profile' %}?redirect=domain-request:start" class="usa-link">your profile</a> to make updates.</p>
{% include "includes/profile_information.html" with user=user%}

View file

@ -15,7 +15,7 @@
</svg>
{% endif %}
{% endif %}
<a href="{% namespaced_url 'domain-request' this_step %}"
<a href="{% namespaced_url 'domain-request' this_step pk=domain_request_id %}"
{% if this_step == steps.current %}
class="usa-current"
{% else %}

View file

@ -17,13 +17,8 @@
<h1>Manage your domains</h1>
{% comment %}
IMPORTANT:
If this button is added on any other page, make sure to update the
relevant view to reset request.session["new_request"] = True
{% endcomment %}
<p class="margin-top-4">
<a href="{% url 'domain-request:' %}" class="usa-button"
<a href="{% url 'start' %}" class="usa-button"
>
Start a new domain request
</a>

View file

@ -72,7 +72,7 @@
>
</li>
<li class="usa-nav__submenu-item">
<a href="{% url 'domain-request:' %}"
<a href="{% url 'domain-request:start' %}"
><span>Start a new domain request</span></a
>
</li>

View file

@ -4,7 +4,7 @@
{% for step in steps %}
<section class="summary-item margin-top-3">
{% if is_editable %}
{% namespaced_url 'domain-request' step as domain_request_url %}
{% namespaced_url 'domain-request' step pk=domain_request_id as domain_request_url %}
{% endif %}
{% if step == Step.REQUESTING_ENTITY %}

View file

@ -4,7 +4,7 @@
{% for step in steps %}
<section class="summary-item margin-top-3">
{% if is_editable %}
{% namespaced_url 'domain-request' step as domain_request_url %}
{% namespaced_url 'domain-request' step pk=domain_request_id as domain_request_url %}
{% endif %}
{% if step == Step.ORGANIZATION_TYPE %}

View file

@ -22,13 +22,9 @@
<p class="margin-y-0">Domain requests can only be modified by the person who created the request.</p>
</div>
<div class="mobile:grid-col-12 tablet:grid-col-6">
{% comment %}
IMPORTANT:
If this button is added on any other page, make sure to update the
relevant view to reset request.session["new_request"] = True
{% endcomment %}
<p class="float-right-tablet tablet:margin-y-0">
<a href="{% url 'domain-request:' %}" class="usa-button"
<a href="{% url 'domain-request:start' %}" class="usa-button"
>
Start a new domain request
</a>

View file

@ -718,7 +718,7 @@ class FinishUserProfileTests(TestWithUser, WebTest):
self.app.set_user(incomplete_regular_user.username)
with override_flag("", active=True):
# This will redirect the user to the setup page
finish_setup_page = self.app.get(reverse("domain-request:")).follow()
finish_setup_page = self.app.get(reverse("domain-request:start")).follow()
self._set_session_cookie()
# Assert that we're on the right page
@ -927,7 +927,7 @@ class UserProfileTests(TestWithUser, WebTest):
def test_user_profile_back_button_when_coming_from_domain_request(self):
"""tests user profile,
and when they are redirected from the domain request page"""
response = self.client.get("/user-profile?redirect=domain-request:")
response = self.client.get("/user-profile?redirect=domain-request:start")
self.assertContains(response, "Your profile")
self.assertContains(response, "Go back to your domain request")
self.assertNotContains(response, "Back to manage your domains")

View file

@ -54,7 +54,7 @@ class DomainRequestTests(TestWithUser, WebTest):
@less_console_noise_decorator
def test_domain_request_form_intro_acknowledgement(self):
"""Tests that user is presented with intro acknowledgement page"""
intro_page = self.app.get(reverse("domain-request:"))
intro_page = self.app.get(reverse("domain-request:start"))
self.assertContains(intro_page, "Youre about to start your .gov domain request")
@less_console_noise_decorator
@ -110,7 +110,7 @@ class DomainRequestTests(TestWithUser, WebTest):
@less_console_noise_decorator
def test_domain_request_form_empty_submit(self):
"""Tests empty submit on the first page after the acknowledgement page"""
intro_page = self.app.get(reverse("domain-request:"))
intro_page = self.app.get(reverse("domain-request:start"))
# django-webtest does not handle cookie-based sessions well because it keeps
# resetting the session key on each new request, thus destroying the concept
# of a "session". We are going to do it manually, saving the session ID here
@ -141,7 +141,7 @@ class DomainRequestTests(TestWithUser, WebTest):
domain_request.save()
# now, attempt to create another one
intro_page = self.app.get(reverse("domain-request:"))
intro_page = self.app.get(reverse("domain-request:start"))
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
intro_form = intro_page.forms[0]
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
@ -167,7 +167,7 @@ class DomainRequestTests(TestWithUser, WebTest):
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
intro_page = self.app.get(reverse("domain-request:"))
intro_page = self.app.get(reverse("domain-request:start"))
# Select the form
intro_form = intro_page.forms[0]
@ -225,7 +225,7 @@ class DomainRequestTests(TestWithUser, WebTest):
SKIPPED_PAGES = 3
num_pages = len(self.TITLES) - SKIPPED_PAGES
intro_page = self.app.get(reverse("domain-request:"))
intro_page = self.app.get(reverse("domain-request:start"))
# django-webtest does not handle cookie-based sessions well because it keeps
# resetting the session key on each new request, thus destroying the concept
# of a "session". We are going to do it manually, saving the session ID here
@ -549,7 +549,7 @@ class DomainRequestTests(TestWithUser, WebTest):
num_pages_tested = 0
# skipping elections, type_of_work, tribal_government
intro_page = self.app.get(reverse("domain-request:"))
intro_page = self.app.get(reverse("domain-request:start"))
# django-webtest does not handle cookie-based sessions well because it keeps
# resetting the session key on each new request, thus destroying the concept
# of a "session". We are going to do it manually, saving the session ID here
@ -873,7 +873,7 @@ class DomainRequestTests(TestWithUser, WebTest):
@less_console_noise_decorator
def test_domain_request_form_conditional_federal(self):
"""Federal branch question is shown for federal organizations."""
intro_page = self.app.get(reverse("domain-request:"))
intro_page = self.app.get(reverse("domain-request:start"))
# django-webtest does not handle cookie-based sessions well because it keeps
# resetting the session key on each new request, thus destroying the concept
# of a "session". We are going to do it manually, saving the session ID here
@ -929,7 +929,7 @@ class DomainRequestTests(TestWithUser, WebTest):
@less_console_noise_decorator
def test_domain_request_form_conditional_elections(self):
"""Election question is shown for other organizations."""
intro_page = self.app.get(reverse("domain-request:"))
intro_page = self.app.get(reverse("domain-request:start"))
# django-webtest does not handle cookie-based sessions well because it keeps
# resetting the session key on each new request, thus destroying the concept
# of a "session". We are going to do it manually, saving the session ID here
@ -984,7 +984,7 @@ class DomainRequestTests(TestWithUser, WebTest):
@less_console_noise_decorator
def test_domain_request_form_section_skipping(self):
"""Can skip forward and back in sections"""
intro_page = self.app.get(reverse("domain-request:"))
intro_page = self.app.get(reverse("domain-request:start"))
# django-webtest does not handle cookie-based sessions well because it keeps
# resetting the session key on each new request, thus destroying the concept
# of a "session". We are going to do it manually, saving the session ID here
@ -1029,7 +1029,7 @@ class DomainRequestTests(TestWithUser, WebTest):
@less_console_noise_decorator
def test_domain_request_form_nonfederal(self):
"""Non-federal organizations don't have to provide their federal agency."""
intro_page = self.app.get(reverse("domain-request:"))
intro_page = self.app.get(reverse("domain-request:start"))
# django-webtest does not handle cookie-based sessions well because it keeps
# resetting the session key on each new request, thus destroying the concept
# of a "session". We are going to do it manually, saving the session ID here
@ -1074,7 +1074,7 @@ class DomainRequestTests(TestWithUser, WebTest):
@less_console_noise_decorator
def test_domain_request_about_your_organization_special(self):
"""Special districts have to answer an additional question."""
intro_page = self.app.get(reverse("domain-request:"))
intro_page = self.app.get(reverse("domain-request:start"))
# django-webtest does not handle cookie-based sessions well because it keeps
# resetting the session key on each new request, thus destroying the concept
# of a "session". We are going to do it manually, saving the session ID here
@ -1104,7 +1104,7 @@ class DomainRequestTests(TestWithUser, WebTest):
def test_federal_agency_dropdown_excludes_expected_values(self):
"""The Federal Agency dropdown on a domain request form should not
include options for gov Administration and Non-Federal Agency"""
intro_page = self.app.get(reverse("domain-request:"))
intro_page = self.app.get(reverse("domain-request:start"))
# django-webtest does not handle cookie-based sessions well because it keeps
# resetting the session key on each new request, thus destroying the concept
# of a "session". We are going to do it manually, saving the session ID here
@ -2303,7 +2303,7 @@ class DomainRequestTests(TestWithUser, WebTest):
@less_console_noise_decorator
def test_domain_request_about_your_organiztion_interstate(self):
"""Special districts have to answer an additional question."""
intro_page = self.app.get(reverse("domain-request:"))
intro_page = self.app.get(reverse("domain-request:start"))
# django-webtest does not handle cookie-based sessions well because it keeps
# resetting the session key on each new request, thus destroying the concept
# of a "session". We are going to do it manually, saving the session ID here
@ -2332,7 +2332,7 @@ class DomainRequestTests(TestWithUser, WebTest):
@less_console_noise_decorator
def test_domain_request_tribal_government(self):
"""Tribal organizations have to answer an additional question."""
intro_page = self.app.get(reverse("domain-request:"))
intro_page = self.app.get(reverse("domain-request:start"))
# django-webtest does not handle cookie-based sessions well because it keeps
# resetting the session key on each new request, thus destroying the concept
# of a "session". We are going to do it manually, saving the session ID here
@ -2363,7 +2363,7 @@ class DomainRequestTests(TestWithUser, WebTest):
@less_console_noise_decorator
def test_domain_request_so_dynamic_text(self):
intro_page = self.app.get(reverse("domain-request:"))
intro_page = self.app.get(reverse("domain-request:start"))
# django-webtest does not handle cookie-based sessions well because it keeps
# resetting the session key on each new request, thus destroying the concept
# of a "session". We are going to do it manually, saving the session ID here
@ -2447,7 +2447,7 @@ class DomainRequestTests(TestWithUser, WebTest):
@less_console_noise_decorator
def test_domain_request_dotgov_domain_dynamic_text(self):
intro_page = self.app.get(reverse("domain-request:"))
intro_page = self.app.get(reverse("domain-request:start"))
# django-webtest does not handle cookie-based sessions well because it keeps
# resetting the session key on each new request, thus destroying the concept
# of a "session". We are going to do it manually, saving the session ID here
@ -2712,7 +2712,7 @@ class DomainRequestTests(TestWithUser, WebTest):
Make sure the long name is displaying in the domain request form,
org step
"""
intro_page = self.app.get(reverse("domain-request:"))
intro_page = self.app.get(reverse("domain-request:start"))
# django-webtest does not handle cookie-based sessions well because it keeps
# resetting the session key on each new request, thus destroying the concept
# of a "session". We are going to do it manually, saving the session ID here
@ -2751,7 +2751,7 @@ class DomainRequestTests(TestWithUser, WebTest):
user=self.user, portfolio=portfolio, roles=[UserPortfolioRoleChoices.ORGANIZATION_MEMBER]
)
# This user should be forbidden from creating new domain requests
intro_page = self.app.get(reverse("domain-request:"), expect_errors=True)
intro_page = self.app.get(reverse("domain-request:start"), expect_errors=True)
self.assertEqual(intro_page.status_code, 403)
# This user should also be forbidden from editing existing ones
@ -2773,7 +2773,7 @@ class DomainRequestTests(TestWithUser, WebTest):
)
# This user should be allowed to create new domain requests
intro_page = self.app.get(reverse("domain-request:"))
intro_page = self.app.get(reverse("domain-request:start"))
self.assertEqual(intro_page.status_code, 200)
# This user should also be allowed to edit existing ones

View file

@ -53,7 +53,7 @@ class DomainRequestWizard(DomainRequestWizardPermissionView, TemplateView):
URL_NAMESPACE = "domain-request"
# name for accessing /domain-request/<id>/edit
EDIT_URL_NAME = "edit-domain-request"
NEW_URL_NAME = "/request/"
NEW_URL_NAME = "/request/start/"
# region: Titles
# We need to pass our human-readable step titles as context to the templates.
@ -315,6 +315,7 @@ class DomainRequestWizard(DomainRequestWizardPermissionView, TemplateView):
# send users "to the domain request wizard" without needing to know which view
# is first in the list of steps.
if self.__class__ == DomainRequestWizard:
print(F"what is this? {request.path_info}")
if request.path_info == self.NEW_URL_NAME:
# Clear context so the prop getter won't create a request here.
# Creating a request will be handled in the post method for the
@ -485,6 +486,7 @@ class DomainRequestWizard(DomainRequestWizardPermissionView, TemplateView):
# Hides the requests and domains buttons in the navbar
context_stuff["hide_requests"] = self.is_portfolio
context_stuff["hide_domains"] = self.is_portfolio
context_stuff["domain_request_id"] = self.domain_request.id
return context_stuff
@ -493,12 +495,12 @@ class DomainRequestWizard(DomainRequestWizardPermissionView, TemplateView):
return request_step_list(self, self.get_step_enum())
def goto(self, step):
if step == "generic_org_type" or step == "portfolio_requesting_entity":
# We need to avoid creating a new domain request if the user
# clicks the back button
self.request.session["new_request"] = False
self.steps.current = step
return redirect(reverse(f"{self.URL_NAMESPACE}:{step}"))
self.domain_request
# Get or create the domain request
domain_request = self.domain_request
test = self.storage.get("domain_request_id")
return redirect(reverse(f"{self.URL_NAMESPACE}:{step}", kwargs={"pk": domain_request.pk}))
def goto_next_step(self):
"""Redirects to the next step."""
@ -524,9 +526,6 @@ class DomainRequestWizard(DomainRequestWizardPermissionView, TemplateView):
# which button did the user press?
button: str = request.POST.get("submit_button", "")
if "new_request" not in request.session:
request.session["new_request"] = True
# if user has acknowledged the intro message
if button == "intro_acknowledge":
# Split into a function: C901 'DomainRequestWizard.post' is too complex (11)
@ -564,9 +563,6 @@ class DomainRequestWizard(DomainRequestWizardPermissionView, TemplateView):
def handle_intro_acknowledge(self, request):
"""If we are starting a new request, clear storage
and redirect to the first step"""
if request.path_info == self.NEW_URL_NAME:
if self.request.session["new_request"] is True:
del self.storage
return self.goto(self.steps.first)
def save(self, forms: list):

View file

@ -7,7 +7,6 @@ def index(request):
if request and request.user and request.user.is_authenticated:
# This controls the creation of a new domain request in the wizard
request.session["new_request"] = True
context["user_domain_count"] = request.user.get_user_domain_ids(request).count()
return render(request, "home.html", context)

View file

@ -46,8 +46,6 @@ class PortfolioDomainRequestsView(PortfolioDomainRequestsPermissionView, View):
template_name = "portfolio_requests.html"
def get(self, request):
if self.request.user.is_authenticated:
request.session["new_request"] = True
return render(request, "portfolio_requests.html")

View file

@ -53,7 +53,7 @@ class UserProfileView(UserProfilePermissionView, FormMixin):
context = super().get_context_data(**kwargs)
# Set the profile_back_button_text based on the redirect parameter
if kwargs.get("redirect") == "domain-request:":
if kwargs.get("redirect") == "domain-request:start":
context["profile_back_button_text"] = "Go back to your domain request"
else:
context["profile_back_button_text"] = "Go to manage your domains"