mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-17 18:09:25 +02:00
Rework readonly fields for analysts + hide when org flag is off
This commit is contained in:
parent
83720c359f
commit
b05a62ecd1
2 changed files with 17 additions and 14 deletions
|
@ -28,6 +28,7 @@ from waffle.models import Sample, Switch
|
||||||
from registrar.models import Contact, Domain, DomainRequest, DraftDomain, User, Website, SeniorOfficial
|
from registrar.models import Contact, Domain, DomainRequest, DraftDomain, User, Website, SeniorOfficial
|
||||||
from registrar.utility.constants import BranchChoices
|
from registrar.utility.constants import BranchChoices
|
||||||
from registrar.utility.errors import FSMDomainRequestError, FSMErrorCodes
|
from registrar.utility.errors import FSMDomainRequestError, FSMErrorCodes
|
||||||
|
from registrar.utility.waffle import flag_is_active_for_user
|
||||||
from registrar.views.utility.mixins import OrderableFieldsMixin
|
from registrar.views.utility.mixins import OrderableFieldsMixin
|
||||||
from django.contrib.admin.views.main import ORDER_VAR
|
from django.contrib.admin.views.main import ORDER_VAR
|
||||||
from registrar.widgets import NoAutocompleteFilteredSelectMultiple
|
from registrar.widgets import NoAutocompleteFilteredSelectMultiple
|
||||||
|
@ -1863,6 +1864,9 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
"cisa_representative_first_name",
|
"cisa_representative_first_name",
|
||||||
"cisa_representative_last_name",
|
"cisa_representative_last_name",
|
||||||
"cisa_representative_email",
|
"cisa_representative_email",
|
||||||
|
"requested_suborganization",
|
||||||
|
"suborganization_city",
|
||||||
|
"suborganization_state_territory",
|
||||||
]
|
]
|
||||||
autocomplete_fields = [
|
autocomplete_fields = [
|
||||||
"approved_domain",
|
"approved_domain",
|
||||||
|
@ -1882,24 +1886,21 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
|
|
||||||
change_form_template = "django/admin/domain_request_change_form.html"
|
change_form_template = "django/admin/domain_request_change_form.html"
|
||||||
|
|
||||||
# While the organization feature is under development, we can gate some fields
|
def get_fieldsets(self, request, obj=None):
|
||||||
# from analysts for now. Remove this array and the get_fieldset overrides once this is done.
|
fieldsets = super().get_fieldsets(request, obj)
|
||||||
# Not my code initially, credit to Nicolle. This was once removed and like a phoenix it has been reborn.
|
|
||||||
superuser_only_fields = [
|
# Hide certain suborg fields behind the organization feature flag
|
||||||
|
# if it is not enabled
|
||||||
|
if not flag_is_active_for_user(request.user, "organization_feature"):
|
||||||
|
excluded_fields = [
|
||||||
"requested_suborganization",
|
"requested_suborganization",
|
||||||
"suborganization_city",
|
"suborganization_city",
|
||||||
"suborganization_state_territory",
|
"suborganization_state_territory",
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_fieldsets(self, request, obj=None):
|
|
||||||
fieldsets = super().get_fieldsets(request, obj)
|
|
||||||
|
|
||||||
# Create a modified version of fieldsets to exclude certain fields
|
|
||||||
if not request.user.has_perm("registrar.full_access_permission"):
|
|
||||||
modified_fieldsets = []
|
modified_fieldsets = []
|
||||||
for name, data in fieldsets:
|
for name, data in fieldsets:
|
||||||
fields = data.get("fields", [])
|
fields = data.get("fields", [])
|
||||||
fields = tuple(field for field in fields if field not in self.superuser_only_fields)
|
fields = tuple(field for field in fields if field not in excluded_fields)
|
||||||
modified_fieldsets.append((name, {**data, "fields": fields}))
|
modified_fieldsets.append((name, {**data, "fields": fields}))
|
||||||
return modified_fieldsets
|
return modified_fieldsets
|
||||||
return fieldsets
|
return fieldsets
|
||||||
|
|
|
@ -1135,7 +1135,8 @@ class DomainRequest(TimeStampedModel):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def requesting_entity_is_suborganization(self) -> bool:
|
def requesting_entity_is_suborganization(self) -> bool:
|
||||||
"""Used to determine if this domain request is also requesting that it be tied to a suborganization.
|
"""Determines if this record is also requesting that it be tied to a suborganization.
|
||||||
|
Used for the RequestingEntity page.
|
||||||
Returns True if portfolio exists and either sub_organization exists,
|
Returns True if portfolio exists and either sub_organization exists,
|
||||||
or if is_requesting_new_suborganization() is true.
|
or if is_requesting_new_suborganization() is true.
|
||||||
Returns False otherwise.
|
Returns False otherwise.
|
||||||
|
@ -1145,8 +1146,9 @@ class DomainRequest(TimeStampedModel):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def is_requesting_new_suborganization(self) -> bool:
|
def is_requesting_new_suborganization(self) -> bool:
|
||||||
"""Used on the requesting entity form to determine if a user is trying to request
|
"""Determines if a user is trying to request
|
||||||
a new suborganization using the domain request form, rather than one that already exists.
|
a new suborganization using the domain request form, rather than one that already exists.
|
||||||
|
Used for the RequestingEntity page.
|
||||||
|
|
||||||
Returns True if a sub_organization does not exist and if requested_suborganization,
|
Returns True if a sub_organization does not exist and if requested_suborganization,
|
||||||
suborganization_city, and suborganization_state_territory all exist.
|
suborganization_city, and suborganization_state_territory all exist.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue