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 %} +
+
+ +
+ +
+ + +
+
+ {% endif %} {% endblock content %} diff --git a/src/registrar/views/user_profile.py b/src/registrar/views/user_profile.py index 47b01f7cb..060369025 100644 --- a/src/registrar/views/user_profile.py +++ b/src/registrar/views/user_profile.py @@ -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