mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-19 19:09:22 +02:00
Cleanup
This commit is contained in:
parent
54c532f3b2
commit
f55d0a655a
10 changed files with 38 additions and 43 deletions
|
@ -50,7 +50,7 @@ class OpenIdConnectBackend(ModelBackend):
|
|||
|
||||
user, created = UserModel.objects.get_or_create(**args)
|
||||
|
||||
if created:
|
||||
if created and request is not None:
|
||||
request.session["is_new_user"] = True
|
||||
|
||||
if not created:
|
||||
|
@ -63,6 +63,7 @@ class OpenIdConnectBackend(ModelBackend):
|
|||
try:
|
||||
user = UserModel.objects.get_by_natural_key(username)
|
||||
except UserModel.DoesNotExist:
|
||||
if request is not None:
|
||||
request.session["is_new_user"] = True
|
||||
return None
|
||||
# run this callback for a each login
|
||||
|
|
|
@ -46,4 +46,3 @@ class ContactForm(forms.Form):
|
|||
label="Phone",
|
||||
error_messages={"invalid": "Enter a valid 10-digit phone number.", "required": "Enter your phone number."},
|
||||
)
|
||||
|
||||
|
|
|
@ -202,6 +202,7 @@ NameserverFormset = formset_factory(
|
|||
validate_max=True,
|
||||
)
|
||||
|
||||
|
||||
# TODO - refactor, wait until daves PR
|
||||
class ContactForm(forms.ModelForm):
|
||||
"""Form for updating contacts."""
|
||||
|
|
|
@ -150,7 +150,7 @@ class OrganizationContactForm(RegistrarForm):
|
|||
"""Require something to be selected when this is a federal agency."""
|
||||
federal_agency = self.cleaned_data.get("federal_agency", None)
|
||||
# need the domain request object to know if this is federal
|
||||
if self.domain_request is None:
|
||||
if hasattr(self, "domain_request") and self.domain_request is None:
|
||||
# hmm, no saved domain request object?, default require the agency
|
||||
if not federal_agency:
|
||||
# no answer was selected
|
||||
|
|
|
@ -3,6 +3,7 @@ from django.db import models
|
|||
from .utility.time_stamped_model import TimeStampedModel
|
||||
from phonenumber_field.modelfields import PhoneNumberField # type: ignore
|
||||
|
||||
|
||||
class Contact(TimeStampedModel):
|
||||
"""Contact information follows a similar pattern for each contact."""
|
||||
|
||||
|
|
|
@ -1,17 +1,20 @@
|
|||
"""
|
||||
Contains middleware used in settings.py
|
||||
"""
|
||||
|
||||
from urllib.parse import urlparse, urlunparse, parse_qs, urlencode
|
||||
from django.urls import reverse
|
||||
from django.http import HttpResponseRedirect
|
||||
from waffle.decorators import flag_is_active
|
||||
|
||||
|
||||
class CheckUserProfileMiddleware:
|
||||
"""
|
||||
Checks if the current user has finished_setup = False.
|
||||
If they do, redirect them to the setup page regardless of where they are in
|
||||
the application.
|
||||
"""
|
||||
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
||||
|
@ -32,10 +35,7 @@ class CheckUserProfileMiddleware:
|
|||
# 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:
|
||||
setup_page = reverse(
|
||||
"finish-contact-profile-setup",
|
||||
kwargs={"pk": request.user.contact.pk}
|
||||
)
|
||||
setup_page = reverse("finish-contact-profile-setup", kwargs={"pk": request.user.contact.pk})
|
||||
logout_page = reverse("logout")
|
||||
excluded_pages = [
|
||||
setup_page,
|
||||
|
@ -52,7 +52,7 @@ class CheckUserProfileMiddleware:
|
|||
# Don't redirect on excluded pages (such as the setup page itself)
|
||||
if not any(request.path.startswith(page) for page in excluded_pages):
|
||||
# Preserve the original query parameters, and coerce them into a dict
|
||||
query_params = parse_qs(request.META['QUERY_STRING'])
|
||||
query_params = parse_qs(request.META["QUERY_STRING"])
|
||||
|
||||
if custom_redirect is not None:
|
||||
# Set the redirect value to our redirect location
|
||||
|
@ -66,7 +66,6 @@ class CheckUserProfileMiddleware:
|
|||
# Reassemble the URL
|
||||
setup_page = urlunparse(setup_page_parts)
|
||||
|
||||
|
||||
# Redirect to the setup page
|
||||
return HttpResponseRedirect(setup_page)
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ 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"""
|
||||
|
@ -56,6 +57,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.
|
||||
|
||||
|
@ -80,6 +82,7 @@ class ContactFormBaseView(BaseContactView, FormMixin):
|
|||
class ContactProfileSetupView(ContactFormBaseView):
|
||||
"""This view forces the user into providing additional details that
|
||||
we may have missed from Login.gov"""
|
||||
|
||||
template_name = "finish_contact_setup.html"
|
||||
form_class = ContactForm
|
||||
model = Contact
|
||||
|
@ -99,13 +102,14 @@ class ContactProfileSetupView(ContactFormBaseView):
|
|||
- COMPLETE_SETUP: Indicates that we want to navigate BACK_TO_SELF, but the subsequent
|
||||
redirect after the next POST should be either HOME or TO_SPECIFIC_PAGE
|
||||
"""
|
||||
|
||||
HOME = "home"
|
||||
BACK_TO_SELF = "back_to_self"
|
||||
COMPLETE_SETUP = "complete_setup"
|
||||
TO_SPECIFIC_PAGE = "domain_request"
|
||||
|
||||
# TODO - refactor
|
||||
@waffle_flag('profile_feature')
|
||||
@waffle_flag("profile_feature")
|
||||
@method_decorator(csrf_protect)
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
"""
|
||||
|
@ -140,7 +144,7 @@ class ContactProfileSetupView(ContactFormBaseView):
|
|||
self.RedirectType.HOME,
|
||||
self.RedirectType.COMPLETE_SETUP,
|
||||
self.RedirectType.BACK_TO_SELF,
|
||||
self.RedirectType.TO_SPECIFIC_PAGE
|
||||
self.RedirectType.TO_SPECIFIC_PAGE,
|
||||
]
|
||||
if redirect_type not in default_redirects:
|
||||
self.redirect_type = self.RedirectType.TO_SPECIFIC_PAGE
|
||||
|
@ -178,9 +182,7 @@ class ContactProfileSetupView(ContactFormBaseView):
|
|||
base_url = reverse(desired_view)
|
||||
except NoReverseMatch as err:
|
||||
logger.error(err)
|
||||
logger.error(
|
||||
"ContactProfileSetupView -> get_redirect_url -> Could not find specified page."
|
||||
)
|
||||
logger.error("ContactProfileSetupView -> get_redirect_url -> Could not find specified page.")
|
||||
base_url = reverse("home")
|
||||
case _:
|
||||
base_url = reverse("home")
|
||||
|
@ -232,10 +234,7 @@ class ContactProfileSetupView(ContactFormBaseView):
|
|||
|
||||
def form_valid(self, form):
|
||||
|
||||
completed_states = [
|
||||
self.RedirectType.TO_SPECIFIC_PAGE,
|
||||
self.RedirectType.HOME
|
||||
]
|
||||
completed_states = [self.RedirectType.TO_SPECIFIC_PAGE, self.RedirectType.HOME]
|
||||
if self.redirect_type in completed_states:
|
||||
self.request.user.finished_setup = True
|
||||
self.request.user.save()
|
||||
|
|
|
@ -819,4 +819,3 @@ class DomainRequestDeleteView(DomainRequestPermissionDeleteView):
|
|||
|
||||
duplicates = [item for item, count in object_dict.items() if count > 1]
|
||||
return duplicates
|
||||
|
||||
|
|
|
@ -341,7 +341,6 @@ class ContactPermission(PermissionsLoginMixin):
|
|||
if not self.request.user.is_authenticated:
|
||||
return False
|
||||
|
||||
|
||||
given_contact_pk = self.kwargs["pk"]
|
||||
|
||||
# Grab the user in the DB to do a full object comparision, not just on ids
|
||||
|
@ -354,10 +353,7 @@ class ContactPermission(PermissionsLoginMixin):
|
|||
|
||||
# Check if the object at the id we're searching on actually exists
|
||||
requested_user_exists = User.objects.filter(pk=current_user.pk).exists()
|
||||
requested_contact_exists = Contact.objects.filter(
|
||||
user=current_user.pk,
|
||||
pk=given_contact_pk
|
||||
).exists()
|
||||
requested_contact_exists = Contact.objects.filter(user=current_user.pk, pk=given_contact_pk).exists()
|
||||
|
||||
if not requested_user_exists or not requested_contact_exists:
|
||||
return False
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue