Skip to content

Commit

Permalink
Revert "kind of a solution"
Browse files Browse the repository at this point in the history
This reverts commit f4c6c08.
  • Loading branch information
zandercymatics committed Oct 31, 2024
1 parent f4c6c08 commit e19923f
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 51 deletions.
1 change: 0 additions & 1 deletion src/registrar/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
40 changes: 1 addition & 39 deletions src/registrar/registrar_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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
17 changes: 7 additions & 10 deletions src/registrar/views/domain_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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}"))

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/registrar/views/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 2 additions & 0 deletions src/registrar/views/portfolios.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down
2 changes: 1 addition & 1 deletion src/registrar/views/utility/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit e19923f

Please sign in to comment.