Add waffle flags

This commit is contained in:
zandercymatics 2024-05-14 13:26:48 -06:00
parent c352869f6b
commit 059a99aca1
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
2 changed files with 23 additions and 5 deletions

View file

@ -2,8 +2,9 @@
Contains middleware used in settings.py Contains middleware used in settings.py
""" """
from urllib.parse import urlparse, urlunparse, parse_qs, urlencode 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 django.http import HttpResponseRedirect
from waffle.decorators import flag_is_active
class CheckUserProfileMiddleware: class CheckUserProfileMiddleware:
""" """
@ -21,11 +22,16 @@ class CheckUserProfileMiddleware:
def process_view(self, request, view_func, view_args, view_kwargs): 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 # Check if setup is not finished
finished_setup = hasattr(request.user, "finished_setup") and request.user.finished_setup finished_setup = hasattr(request.user, "finished_setup") and request.user.finished_setup
if request.user.is_authenticated and not finished_setup: if request.user.is_authenticated and not finished_setup:
# redirect_to_domain_request = request.GET.get('domain_request', "") != ""
setup_page = reverse( setup_page = reverse(
"finish-contact-profile-setup", "finish-contact-profile-setup",
kwargs={"pk": request.user.contact.pk} kwargs={"pk": request.user.contact.pk}

View file

@ -1,4 +1,4 @@
from enum import Enum from waffle.decorators import waffle_flag
from urllib.parse import urlencode, urlunparse, urlparse, quote from urllib.parse import urlencode, urlunparse, urlparse, quote
from django.urls import NoReverseMatch, reverse from django.urls import NoReverseMatch, reverse
from registrar.forms.contact import ContactForm from registrar.forms.contact import ContactForm
@ -18,7 +18,8 @@ logger = logging.getLogger(__name__)
class BaseContactView(ContactPermissionView): 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): def get(self, request, *args, **kwargs):
"""Sets the current contact in cache, defines the current object as self.object """Sets the current contact in cache, defines the current object as self.object
then returns render_to_response""" then returns render_to_response"""
@ -54,7 +55,7 @@ class BaseContactView(ContactPermissionView):
class ContactFormBaseView(BaseContactView, FormMixin): class ContactFormBaseView(BaseContactView, FormMixin):
"""Adds a FormMixin to BaseContactView, and handles post"""
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
"""Form submission posts to this view. """Form submission posts to this view.
@ -104,6 +105,7 @@ class ContactProfileSetupView(ContactFormBaseView):
TO_SPECIFIC_PAGE = "domain_request" TO_SPECIFIC_PAGE = "domain_request"
# TODO - refactor # TODO - refactor
@waffle_flag('profile_feature')
@method_decorator(csrf_protect) @method_decorator(csrf_protect)
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
@ -140,6 +142,16 @@ class ContactProfileSetupView(ContactFormBaseView):
return super().dispatch(request, *args, **kwargs) return super().dispatch(request, *args, **kwargs)
def get_redirect_url(self): 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 = "" base_url = ""
query_params = {} query_params = {}
match self.redirect_type: match self.redirect_type: