diff --git a/src/registrar/registrar_middleware.py b/src/registrar/registrar_middleware.py index f9921513b..a1664934a 100644 --- a/src/registrar/registrar_middleware.py +++ b/src/registrar/registrar_middleware.py @@ -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 diff --git a/src/registrar/templates/profile.html b/src/registrar/templates/profile.html index c126204bd..61137742e 100644 --- a/src/registrar/templates/profile.html +++ b/src/registrar/templates/profile.html @@ -35,6 +35,68 @@ Edit your User Profile | {% endif %} {% endif %} + + {% if show_confirmation_modal %} +
+ {{ modal_description }} +
+