Skip to content

Commit

Permalink
use id instead of session for domain requests
Browse files Browse the repository at this point in the history
  • Loading branch information
zandercymatics committed Oct 31, 2024
1 parent e19923f commit aa930eb
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 59 deletions.
9 changes: 6 additions & 3 deletions src/registrar/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@
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 [
Expand Down Expand Up @@ -253,7 +254,9 @@
),
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"),
Expand Down
2 changes: 1 addition & 1 deletion src/registrar/registrar_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def _handle_user_setup_not_finished(self, request, profile_page):

# 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)):
Expand Down
2 changes: 1 addition & 1 deletion src/registrar/templates/domain_request_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion src/registrar/templates/domain_request_intro.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h2>Time to complete the form</h2>
<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 we’ll reach you</h2>
<p>While reviewing your domain request, we may need to reach out with questions. We’ll 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. We’ll 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%}


Expand Down
2 changes: 1 addition & 1 deletion src/registrar/templates/domain_request_sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
7 changes: 1 addition & 6 deletions src/registrar/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion src/registrar/templates/includes/header_extended.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
2 changes: 1 addition & 1 deletion src/registrar/templates/includes/request_review_steps.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
8 changes: 2 additions & 6 deletions src/registrar/templates/portfolio_requests.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@ <h1 id="domain-requests-header">Domain requests</h1>
<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>
Expand Down
4 changes: 2 additions & 2 deletions src/registrar/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ def test_new_user_goes_to_domain_request(self):
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
Expand Down Expand Up @@ -927,7 +927,7 @@ def test_user_profile_main_nav(self):
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")
Expand Down
38 changes: 19 additions & 19 deletions src/registrar/tests/test_views_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def tearDown(self):
@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, "You’re about to start your .gov domain request")

@less_console_noise_decorator
Expand Down Expand Up @@ -110,7 +110,7 @@ def test_domain_request_form_intro_is_skipped_when_edit_access(self):
@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
Expand Down Expand Up @@ -141,7 +141,7 @@ def test_domain_request_multiple_domain_requests_exist(self):
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)
Expand All @@ -167,7 +167,7 @@ def test_domain_request_into_acknowledgement_creates_new_request(self):
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]
Expand Down Expand Up @@ -225,7 +225,7 @@ def test_domain_request_form_submission(self):
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
Expand Down Expand Up @@ -549,7 +549,7 @@ def test_domain_request_form_submission_incomplete(self):
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
Expand Down Expand Up @@ -873,7 +873,7 @@ def test_domain_request_form_started_allsteps(self):
@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
Expand Down Expand Up @@ -929,7 +929,7 @@ def test_domain_request_form_conditional_federal(self):
@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
Expand Down Expand Up @@ -984,7 +984,7 @@ def test_domain_request_form_conditional_elections(self):
@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
Expand Down Expand Up @@ -1029,7 +1029,7 @@ def test_domain_request_form_section_skipping(self):
@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
Expand Down Expand Up @@ -1074,7 +1074,7 @@ def test_domain_request_form_nonfederal(self):
@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
Expand Down Expand Up @@ -1104,7 +1104,7 @@ def test_domain_request_about_your_organization_special(self):
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
Expand Down Expand Up @@ -2303,7 +2303,7 @@ def test_edit_creator_in_place(self):
@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
Expand Down Expand Up @@ -2332,7 +2332,7 @@ def test_domain_request_about_your_organiztion_interstate(self):
@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
Expand Down Expand Up @@ -2363,7 +2363,7 @@ def test_domain_request_tribal_government(self):

@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
Expand Down Expand Up @@ -2447,7 +2447,7 @@ def test_domain_request_so_dynamic_text(self):

@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
Expand Down Expand Up @@ -2712,7 +2712,7 @@ def test_long_org_name_in_domain_request(self):
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
Expand Down Expand Up @@ -2751,7 +2751,7 @@ def test_portfolio_user_missing_edit_permissions(self):
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
Expand All @@ -2773,7 +2773,7 @@ def test_portfolio_user_with_edit_permissions(self):
)

# 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
Expand Down
Loading

0 comments on commit aa930eb

Please sign in to comment.