mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-02 16:02:15 +02:00
Merge branch 'main' into za/2047-force-new-users-profile
This commit is contained in:
commit
7d3067a969
4 changed files with 46 additions and 10 deletions
|
@ -5,6 +5,7 @@ import logging
|
|||
from typing import Any
|
||||
from urllib.parse import urlparse, urlunparse, urlencode
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -269,19 +270,25 @@ class CreateOrUpdateOrganizationTypeHelper:
|
|||
return True
|
||||
|
||||
|
||||
def replace_url_queryparams(url_to_modify: str, query_params: dict[Any, list]):
|
||||
def replace_url_queryparams(url_to_modify: str, query_params, convert_list_to_csv=False):
|
||||
"""
|
||||
Replaces the query parameters of a given URL.
|
||||
Because this replaces them, this can be used to either add, delete, or modify.
|
||||
|
||||
Args:
|
||||
url_to_modify (str): The URL whose query parameters need to be modified.
|
||||
query_params (dict): Dictionary of query parameters to use.
|
||||
|
||||
convert_list_to_csv (bool): If the queryparam contains a list of items,
|
||||
convert it to a csv representation instead.
|
||||
Returns:
|
||||
str: The modified URL with the updated query parameters.
|
||||
"""
|
||||
|
||||
# Ensure each key in query_params maps to a single value, not a list
|
||||
if convert_list_to_csv:
|
||||
for key, value in query_params.items():
|
||||
if isinstance(value, list):
|
||||
query_params[key] = ",".join(value)
|
||||
|
||||
# Split the URL into parts
|
||||
url_parts = list(urlparse(url_to_modify))
|
||||
|
||||
|
|
|
@ -13,12 +13,12 @@
|
|||
<p>We’ll use the information you provide to verify your organization’s eligibility for a .gov domain. We’ll also verify that the domain you request meets our guidelines.</p>
|
||||
<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>
|
||||
{% if has_profile_feature_flag %}
|
||||
<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="" target="_blank" class="usa-link">your profile</a> to make updates.</p>
|
||||
{% include "includes/profile_information.html" with user=user%}
|
||||
{% endif %}
|
||||
completing your domain request might take around 15 minutes.</p>
|
||||
{% if has_profile_feature_flag %}
|
||||
<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' %}?return_to_request=True" class="usa-link">your profile</a> to make updates.</p>
|
||||
{% include "includes/profile_information.html" with user=user%}
|
||||
{% endif %}
|
||||
|
||||
|
||||
{% block form_buttons %}
|
||||
|
|
|
@ -704,6 +704,16 @@ class UserProfileTests(TestWithUser, WebTest):
|
|||
response = self.client.get("/user-profile", follow=True)
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_user_profile_back_button_when_coming_from_domain_request(self):
|
||||
"""tests user profile when profile_feature is on,
|
||||
and when they are redirected from the domain request page"""
|
||||
with override_flag("profile_feature", active=True):
|
||||
response = self.client.get("/user-profile?return_to_request=True")
|
||||
self.assertContains(response, "Your profile")
|
||||
self.assertContains(response, "Go back to your domain request")
|
||||
self.assertNotContains(response, "Back to manage your domains")
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_domain_detail_profile_feature_on(self):
|
||||
"""test that domain detail view when profile_feature is on"""
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
from enum import Enum
|
||||
import logging
|
||||
from urllib.parse import parse_qs, unquote
|
||||
|
||||
from urllib.parse import quote
|
||||
|
||||
|
@ -14,6 +15,7 @@ from django.urls import NoReverseMatch, reverse
|
|||
from registrar.models import (
|
||||
Contact,
|
||||
)
|
||||
from registrar.models.utility.generic_helper import replace_url_queryparams
|
||||
from registrar.views.utility.permission_views import UserProfilePermissionView
|
||||
from waffle.decorators import flag_is_active, waffle_flag
|
||||
|
||||
|
@ -39,6 +41,11 @@ class UserProfileView(UserProfilePermissionView, FormMixin):
|
|||
self._refresh_session_and_object(request)
|
||||
form = self.form_class(instance=self.object)
|
||||
context = self.get_context_data(object=self.object, form=form)
|
||||
|
||||
return_to_request = request.GET.get("return_to_request")
|
||||
if return_to_request:
|
||||
context["return_to_request"] = True
|
||||
|
||||
return self.render_to_response(context)
|
||||
|
||||
def _refresh_session_and_object(self, request):
|
||||
|
@ -48,6 +55,9 @@ class UserProfileView(UserProfilePermissionView, FormMixin):
|
|||
|
||||
@waffle_flag("profile_feature") # type: ignore
|
||||
def dispatch(self, request, *args, **kwargs): # type: ignore
|
||||
# Store the original queryparams to persist them
|
||||
query_params = request.META["QUERY_STRING"]
|
||||
request.session["query_params"] = query_params
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
|
@ -64,7 +74,16 @@ class UserProfileView(UserProfilePermissionView, FormMixin):
|
|||
|
||||
def get_success_url(self):
|
||||
"""Redirect to the user's profile page."""
|
||||
return reverse("user-profile")
|
||||
|
||||
query_params = {}
|
||||
if "query_params" in self.session:
|
||||
params = unquote(self.session["query_params"])
|
||||
query_params = parse_qs(params)
|
||||
|
||||
# Preserve queryparams and add them back to the url
|
||||
base_url = reverse("user-profile")
|
||||
new_redirect = replace_url_queryparams(base_url, query_params, convert_list_to_csv=True)
|
||||
return new_redirect
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
"""Handle post requests (form submissions)"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue