mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-30 22:46:30 +02:00
Core logic
This commit is contained in:
parent
3ca79aef90
commit
a6de5293c2
2 changed files with 34 additions and 2 deletions
|
@ -2,7 +2,8 @@ from __future__ import annotations # allows forward references in annotations
|
||||||
import logging
|
import logging
|
||||||
from api.views import DOMAIN_API_MESSAGES
|
from api.views import DOMAIN_API_MESSAGES
|
||||||
from phonenumber_field.formfields import PhoneNumberField # type: ignore
|
from phonenumber_field.formfields import PhoneNumberField # type: ignore
|
||||||
|
from registrar.models.portfolio import Portfolio
|
||||||
|
from registrar.utility.waffle import flag_is_active_anywhere
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.core.validators import RegexValidator, MaxLengthValidator
|
from django.core.validators import RegexValidator, MaxLengthValidator
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
@ -321,7 +322,7 @@ class OrganizationContactForm(RegistrarForm):
|
||||||
# if it has been filled in when required.
|
# if it has been filled in when required.
|
||||||
# uncomment to see if modelChoiceField can be an arg later
|
# uncomment to see if modelChoiceField can be an arg later
|
||||||
required=False,
|
required=False,
|
||||||
queryset=FederalAgency.objects.exclude(agency__in=excluded_agencies),
|
queryset=FederalAgency.objects.none(),
|
||||||
widget=ComboboxWidget,
|
widget=ComboboxWidget,
|
||||||
)
|
)
|
||||||
organization_name = forms.CharField(
|
organization_name = forms.CharField(
|
||||||
|
@ -363,6 +364,21 @@ class OrganizationContactForm(RegistrarForm):
|
||||||
label="Urbanization (required for Puerto Rico only)",
|
label="Urbanization (required for Puerto Rico only)",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
# Set the queryset for federal agency.
|
||||||
|
# If the organization_requests flag is active, we hide data that exists in portfolios.
|
||||||
|
# NOTE: This function assumes that the federal_agency field was first set to None if a portfolio exists.
|
||||||
|
federal_agency_queryset = FederalAgency.objects.exclude(agency__in=self.excluded_agencies)
|
||||||
|
if flag_is_active_anywhere("organization_feature") and flag_is_active_anywhere("organization_requests"):
|
||||||
|
# Exclude both predefined agencies and those matching portfolio names in one query
|
||||||
|
federal_agency_queryset = federal_agency_queryset.exclude(
|
||||||
|
agency__in=Portfolio.objects.values_list("organization_name", flat=True)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.fields["federal_agency"].queryset = federal_agency_queryset
|
||||||
|
|
||||||
def clean_federal_agency(self):
|
def clean_federal_agency(self):
|
||||||
"""Require something to be selected when this is a federal agency."""
|
"""Require something to be selected when this is a federal agency."""
|
||||||
federal_agency = self.cleaned_data.get("federal_agency", None)
|
federal_agency = self.cleaned_data.get("federal_agency", None)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from django.http import HttpRequest
|
from django.http import HttpRequest
|
||||||
from waffle.decorators import flag_is_active
|
from waffle.decorators import flag_is_active
|
||||||
|
from waffle.models import get_waffle_flag_model
|
||||||
|
|
||||||
|
|
||||||
def flag_is_active_for_user(user, flag_name):
|
def flag_is_active_for_user(user, flag_name):
|
||||||
|
@ -10,3 +11,18 @@ def flag_is_active_for_user(user, flag_name):
|
||||||
request = HttpRequest()
|
request = HttpRequest()
|
||||||
request.user = user
|
request.user = user
|
||||||
return flag_is_active(request, flag_name)
|
return flag_is_active(request, flag_name)
|
||||||
|
|
||||||
|
|
||||||
|
def flag_is_active_anywhere(flag_name):
|
||||||
|
"""Checks if the given flag name is active for anyone, anywhere.
|
||||||
|
More specifically, it checks on flag.everyone or flag.users.exists().
|
||||||
|
Does not check self.superuser, self.staff or self.group.
|
||||||
|
|
||||||
|
This function effectively behaves like a switch:
|
||||||
|
If said flag is enabled for someone, somewhere - return true.
|
||||||
|
Otherwise - return false.
|
||||||
|
"""
|
||||||
|
flag = get_waffle_flag_model().get(flag_name)
|
||||||
|
if flag.everyone is None:
|
||||||
|
return flag.users.exists()
|
||||||
|
return flag.everyone
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue