From 059a99aca1bd62812c6d549b9caab607c17e75fb Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Tue, 14 May 2024 13:26:48 -0600 Subject: [PATCH] Add waffle flags --- src/registrar/registrar_middleware.py | 10 ++++++++-- src/registrar/views/contact.py | 18 +++++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/registrar/registrar_middleware.py b/src/registrar/registrar_middleware.py index a9b2f7a23..427775f34 100644 --- a/src/registrar/registrar_middleware.py +++ b/src/registrar/registrar_middleware.py @@ -2,8 +2,9 @@ Contains middleware used in settings.py """ from urllib.parse import urlparse, urlunparse, parse_qs, urlencode -from django.urls import reverse, resolve +from django.urls import reverse from django.http import HttpResponseRedirect +from waffle.decorators import flag_is_active class CheckUserProfileMiddleware: """ @@ -20,12 +21,17 @@ class CheckUserProfileMiddleware: return response def process_view(self, request, view_func, view_args, view_kwargs): + + # Check that the user is "opted-in" to the profile feature flag + has_profile_feature_flag = flag_is_active(request, "profile_feature") + # If they aren't, skip this entirely + if not has_profile_feature_flag: + return None # Check if setup is not finished finished_setup = hasattr(request.user, "finished_setup") and request.user.finished_setup if request.user.is_authenticated and not finished_setup: - # redirect_to_domain_request = request.GET.get('domain_request', "") != "" setup_page = reverse( "finish-contact-profile-setup", kwargs={"pk": request.user.contact.pk} diff --git a/src/registrar/views/contact.py b/src/registrar/views/contact.py index 0fbd92435..f2f5e29a9 100644 --- a/src/registrar/views/contact.py +++ b/src/registrar/views/contact.py @@ -1,4 +1,4 @@ -from enum import Enum +from waffle.decorators import waffle_flag from urllib.parse import urlencode, urlunparse, urlparse, quote from django.urls import NoReverseMatch, reverse from registrar.forms.contact import ContactForm @@ -18,7 +18,8 @@ logger = logging.getLogger(__name__) class BaseContactView(ContactPermissionView): - + """Provides a base view for the contact object. On get, the contact + is saved in the session and on self.object.""" def get(self, request, *args, **kwargs): """Sets the current contact in cache, defines the current object as self.object then returns render_to_response""" @@ -54,7 +55,7 @@ class BaseContactView(ContactPermissionView): class ContactFormBaseView(BaseContactView, FormMixin): - + """Adds a FormMixin to BaseContactView, and handles post""" def post(self, request, *args, **kwargs): """Form submission posts to this view. @@ -104,6 +105,7 @@ class ContactProfileSetupView(ContactFormBaseView): TO_SPECIFIC_PAGE = "domain_request" # TODO - refactor + @waffle_flag('profile_feature') @method_decorator(csrf_protect) def dispatch(self, request, *args, **kwargs): @@ -140,6 +142,16 @@ class ContactProfileSetupView(ContactFormBaseView): return super().dispatch(request, *args, **kwargs) def get_redirect_url(self): + """ + Returns a URL string based on the current value of self.redirect_type. + + Depending on self.redirect_type, constructs a base URL and appends a + 'redirect' query parameter. Handles different redirection types such as + HOME, BACK_TO_SELF, COMPLETE_SETUP, and TO_SPECIFIC_PAGE. + + Returns: + str: The full URL with the appropriate query parameters. + """ base_url = "" query_params = {} match self.redirect_type: