From e19923f86fd30a263b945b869cf1eaa86a28a1e2 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Thu, 31 Oct 2024 13:54:43 -0600 Subject: [PATCH] Revert "kind of a solution" This reverts commit f4c6c084a6804c3fe6fa7ddcf3bb6a2e3985af42. --- src/registrar/config/settings.py | 1 - src/registrar/registrar_middleware.py | 40 +-------------------------- src/registrar/views/domain_request.py | 17 +++++------- src/registrar/views/index.py | 1 + src/registrar/views/portfolios.py | 2 ++ src/registrar/views/utility/mixins.py | 2 +- 6 files changed, 12 insertions(+), 51 deletions(-) diff --git a/src/registrar/config/settings.py b/src/registrar/config/settings.py index f931dad5e..da58eee86 100644 --- a/src/registrar/config/settings.py +++ b/src/registrar/config/settings.py @@ -193,7 +193,6 @@ "waffle.middleware.WaffleMiddleware", "registrar.registrar_middleware.CheckUserProfileMiddleware", "registrar.registrar_middleware.CheckPortfolioMiddleware", - "registrar.registrar_middleware.NewRequestMiddleware" ] # application object used by Django's built-in servers (e.g. `runserver`) diff --git a/src/registrar/registrar_middleware.py b/src/registrar/registrar_middleware.py index d8340421a..2ccea9321 100644 --- a/src/registrar/registrar_middleware.py +++ b/src/registrar/registrar_middleware.py @@ -8,8 +8,7 @@ from django.http import HttpResponseRedirect from registrar.models import User from waffle.decorators import flag_is_active -from django.urls import resolve, Resolver404 -from registrar.config.urls import DOMAIN_REQUEST_NAMESPACE + from registrar.models.utility.generic_helper import replace_url_queryparams logger = logging.getLogger(__name__) @@ -170,40 +169,3 @@ def set_portfolio_in_session(self, request): request.session["portfolio"] = request.user.get_first_portfolio() else: request.session["portfolio"] = request.user.get_first_portfolio() - - -class NewRequestMiddleware: - def __init__(self, get_response): - self.get_response = get_response - - def __call__(self, request): - response = self.get_response(request) - return response - - def process_view(self, request, view_func, view_args, view_kwargs): - if not request.user.is_authenticated: - return None - - if request.session.get("new_request") is None: - request.session["new_request"] = True - - resolved = resolve(request.path) - if request.session.get("new_request") is False: - try: - resolved = resolve(request.path) - # Check if we're in the domain-request namespace. - # If not, then a new request is not being made. - if resolved.namespace != DOMAIN_REQUEST_NAMESPACE: - request.session["new_request"] = True - # URL doesn't match any known pattern. - # This shouldn't happen (caught before this), but redundancy is good. - except Resolver404: - # If you somehow see this log, something must have went very, *very* wrong. - # All I can offer in consolidation is this ASCII cat to tend to these hard times: - # ⠀ /l、 - # (゚、 。 7 - # ⠀ l、゙ ~ヽ - #   じしf_, )ノ - logger.error("[CRITICAL] NewRequestMiddleware => Could not resolve the request path.") - - return None diff --git a/src/registrar/views/domain_request.py b/src/registrar/views/domain_request.py index d74897266..7bbe78775 100644 --- a/src/registrar/views/domain_request.py +++ b/src/registrar/views/domain_request.py @@ -308,13 +308,6 @@ def get(self, request, *args, **kwargs): if current_url == self.EDIT_URL_NAME and "id" in kwargs: del self.storage self.storage["domain_request_id"] = kwargs["id"] - elif self.request.session.get("new_request") is True and current_url != self.NEW_URL_NAME and current_url != "": - print(f"what is the url: {current_url} vs type: {type(current_url)}") - # Add some popup here that indicates a new request was started... - logger.info(f"DomainRequestWizard => user {request.user} was redirected to home (because, etc...)") - del self.storage - return HttpResponseRedirect(reverse("home")) - # if accessing this class directly, redirect to either to an acknowledgement # page or to the first step in the processes (if an edit rather than a new request); @@ -500,8 +493,10 @@ def get_step_list(self) -> list: return request_step_list(self, self.get_step_enum()) def goto(self, step): - # We need to avoid creating a new domain request if the user clicks the back button - self.request.session["new_request"] = False + 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}")) @@ -529,6 +524,9 @@ def post(self, request, *args, **kwargs) -> HttpResponse: # 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) @@ -566,7 +564,6 @@ def post(self, request, *args, **kwargs) -> HttpResponse: def handle_intro_acknowledge(self, request): """If we are starting a new request, clear storage and redirect to the first step""" - print(f"path info is: {request.path_info}") if request.path_info == self.NEW_URL_NAME: if self.request.session["new_request"] is True: del self.storage diff --git a/src/registrar/views/index.py b/src/registrar/views/index.py index 7019c8db3..53900a4a7 100644 --- a/src/registrar/views/index.py +++ b/src/registrar/views/index.py @@ -7,6 +7,7 @@ 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) diff --git a/src/registrar/views/portfolios.py b/src/registrar/views/portfolios.py index 42158737a..6fb976d5c 100644 --- a/src/registrar/views/portfolios.py +++ b/src/registrar/views/portfolios.py @@ -46,6 +46,8 @@ 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") diff --git a/src/registrar/views/utility/mixins.py b/src/registrar/views/utility/mixins.py index 31913691c..c1cf97d82 100644 --- a/src/registrar/views/utility/mixins.py +++ b/src/registrar/views/utility/mixins.py @@ -401,7 +401,7 @@ def has_permission(self): id = self.kwargs.get("id") if hasattr(self, "kwargs") else None if not id: domain_request_wizard = self.request.session.get("wizard_domain_request") - if domain_request_wizard and self.request.session.get("new_request") is False: + if domain_request_wizard: id = domain_request_wizard.get("domain_request_id") # If no id is provided, we can assume that the user is starting a new request.