Skip to content

Commit

Permalink
Rework readonly fields for analysts + hide when org flag is off
Browse files Browse the repository at this point in the history
  • Loading branch information
zandercymatics committed Nov 1, 2024
1 parent 83720c3 commit b05a62e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
25 changes: 13 additions & 12 deletions src/registrar/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from registrar.models import Contact, Domain, DomainRequest, DraftDomain, User, Website, SeniorOfficial
from registrar.utility.constants import BranchChoices
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 django.contrib.admin.views.main import ORDER_VAR
from registrar.widgets import NoAutocompleteFilteredSelectMultiple
Expand Down Expand Up @@ -1863,6 +1864,9 @@ def status_history(self, obj):
"cisa_representative_first_name",
"cisa_representative_last_name",
"cisa_representative_email",
"requested_suborganization",
"suborganization_city",
"suborganization_state_territory",
]
autocomplete_fields = [
"approved_domain",
Expand All @@ -1882,24 +1886,21 @@ def status_history(self, obj):

change_form_template = "django/admin/domain_request_change_form.html"

# While the organization feature is under development, we can gate some fields
# from analysts for now. Remove this array and the get_fieldset overrides once this is done.
# Not my code initially, credit to Nicolle. This was once removed and like a phoenix it has been reborn.
superuser_only_fields = [
"requested_suborganization",
"suborganization_city",
"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"):
# 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",
"suborganization_city",
"suborganization_state_territory",
]
modified_fieldsets = []
for name, data in fieldsets:
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}))
return modified_fieldsets
return fieldsets
Expand Down
6 changes: 4 additions & 2 deletions src/registrar/models/domain_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,8 @@ def requesting_entity_is_portfolio(self) -> bool:
return False

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,
or if is_requesting_new_suborganization() is true.
Returns False otherwise.
Expand All @@ -1145,8 +1146,9 @@ def requesting_entity_is_suborganization(self) -> bool:
return False

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.
Used for the RequestingEntity page.
Returns True if a sub_organization does not exist and if requested_suborganization,
suborganization_city, and suborganization_state_territory all exist.
Expand Down

0 comments on commit b05a62e

Please sign in to comment.