mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-19 17:25:56 +02:00
updated middleware, started on conditional modal
This commit is contained in:
parent
f468e6cd6e
commit
ff7a745ffa
3 changed files with 90 additions and 4 deletions
|
@ -5,6 +5,7 @@ Contains middleware used in settings.py
|
|||
from urllib.parse import parse_qs
|
||||
from django.urls import reverse
|
||||
from django.http import HttpResponseRedirect
|
||||
from registrar.models.user import User
|
||||
from waffle.decorators import flag_is_active
|
||||
|
||||
from registrar.models.utility.generic_helper import replace_url_queryparams
|
||||
|
@ -38,11 +39,16 @@ class CheckUserProfileMiddleware:
|
|||
self.get_response = get_response
|
||||
|
||||
self.setup_page = reverse("finish-user-profile-setup")
|
||||
self.profile_page = reverse("user-profile")
|
||||
self.logout_page = reverse("logout")
|
||||
self.excluded_pages = [
|
||||
self.regular_excluded_pages = [
|
||||
self.setup_page,
|
||||
self.logout_page,
|
||||
]
|
||||
self.other_excluded_pages = [
|
||||
self.profile_page,
|
||||
self.logout_page,
|
||||
]
|
||||
|
||||
def __call__(self, request):
|
||||
response = self.get_response(request)
|
||||
|
@ -60,13 +66,17 @@ class CheckUserProfileMiddleware:
|
|||
return None
|
||||
|
||||
if request.user.is_authenticated:
|
||||
if hasattr(request.user, "finished_setup") and not request.user.finished_setup:
|
||||
return self._handle_setup_not_finished(request)
|
||||
if request.user.verification_type == User.VerificationTypeChoices.REGULAR:
|
||||
if hasattr(request.user, "finished_setup") and not request.user.finished_setup:
|
||||
return self._handle_regular_user_setup_not_finished(request)
|
||||
else:
|
||||
if hasattr(request.user, "finished_setup") and not request.user.finished_setup:
|
||||
return self._handle_other_user_setup_not_finished(request)
|
||||
|
||||
# Continue processing the view
|
||||
return None
|
||||
|
||||
def _handle_setup_not_finished(self, request):
|
||||
def _handle_regular_user_setup_not_finished(self, request):
|
||||
"""Redirects the given user to the finish setup page.
|
||||
|
||||
We set the "redirect" query param equal to where the user wants to go.
|
||||
|
@ -98,3 +108,14 @@ class CheckUserProfileMiddleware:
|
|||
else:
|
||||
# Process the view as normal
|
||||
return None
|
||||
|
||||
def _handle_other_user_setup_not_finished(self, request):
|
||||
"""Redirects the given user to the profile page to finish setup.
|
||||
"""
|
||||
|
||||
# Don't redirect on excluded pages (such as the setup page itself)
|
||||
if not any(request.path.startswith(page) for page in self.excluded_pages):
|
||||
return HttpResponseRedirect(self.profile_page)
|
||||
else:
|
||||
# Process the view as normal
|
||||
return None
|
||||
|
|
|
@ -35,6 +35,68 @@ Edit your User Profile |
|
|||
{% endif %}
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
{% if show_confirmation_modal %}
|
||||
<div class="usa-modal__content">
|
||||
<div class="usa-modal__main">
|
||||
<h2 class="usa-modal__heading" id="modal-1-heading">
|
||||
{{ modal_heading }}
|
||||
{% if heading_value is not None %}
|
||||
{# Add a breakpoint #}
|
||||
<div aria-hidden="true"></div>
|
||||
{{ heading_value }}
|
||||
{% endif %}
|
||||
</h2>
|
||||
<div class="usa-prose">
|
||||
<p id="modal-1-description">
|
||||
{{ modal_description }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="usa-modal__footer">
|
||||
<ul class="usa-button-group">
|
||||
{% if not_form %}
|
||||
<li class="usa-button-group__item">
|
||||
{{ modal_button }}
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="usa-button-group__item">
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{{ modal_button }}
|
||||
</form>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li class="usa-button-group__item">
|
||||
{% comment %} The cancel button the DS form actually triggers a context change in the view,
|
||||
in addition to being a close modal hook {% endcomment %}
|
||||
{% if cancel_button_resets_ds_form %}
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
<button
|
||||
type="submit"
|
||||
class="usa-button usa-button--unstyled padding-105 text-center"
|
||||
name="btn-cancel-click"
|
||||
data-close-modal
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</form>
|
||||
{% elif not is_domain_request_form or review_form_is_complete %}
|
||||
<button
|
||||
type="button"
|
||||
class="usa-button usa-button--unstyled padding-105 text-center"
|
||||
data-close-modal
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
{% endif %}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% endblock content %}
|
||||
|
||||
|
|
|
@ -41,6 +41,9 @@ class UserProfileView(UserProfilePermissionView, FormMixin):
|
|||
form = self.form_class(instance=self.object)
|
||||
context = self.get_context_data(object=self.object, form=form)
|
||||
|
||||
if hasattr(self.object, "finished_setup") and not self.object.finished_setup:
|
||||
context["show_confirmation_modal"]
|
||||
|
||||
return_to_request = request.GET.get("return_to_request")
|
||||
if return_to_request:
|
||||
context["return_to_request"] = True
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue