mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-29 14:06:32 +02:00
a working not final solution
This commit is contained in:
parent
a32ec351ca
commit
4b1f3f348f
3 changed files with 180 additions and 132 deletions
|
@ -1798,91 +1798,95 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
]
|
]
|
||||||
search_help_text = "Search by domain or creator."
|
search_help_text = "Search by domain or creator."
|
||||||
|
|
||||||
fieldsets = [
|
common_fields = [
|
||||||
(
|
"portfolio",
|
||||||
None,
|
"sub_organization",
|
||||||
{
|
"requested_suborganization",
|
||||||
"fields": [
|
"suborganization_city",
|
||||||
"portfolio",
|
"suborganization_state_territory",
|
||||||
"sub_organization",
|
"status_history",
|
||||||
"requested_suborganization",
|
"status",
|
||||||
"suborganization_city",
|
"rejection_reason",
|
||||||
"suborganization_state_territory",
|
"rejection_reason_email",
|
||||||
"status_history",
|
"action_needed_reason",
|
||||||
"status",
|
"action_needed_reason_email",
|
||||||
"rejection_reason",
|
"investigator",
|
||||||
"rejection_reason_email",
|
"creator",
|
||||||
"action_needed_reason",
|
"approved_domain",
|
||||||
"action_needed_reason_email",
|
"notes",
|
||||||
"investigator",
|
]
|
||||||
"creator",
|
|
||||||
"approved_domain",
|
contact_fields_with_portfolio = [
|
||||||
"notes",
|
"converted_senior_official",
|
||||||
]
|
"other_contacts",
|
||||||
},
|
"no_other_contacts_rationale",
|
||||||
),
|
"cisa_representative_first_name",
|
||||||
(".gov domain", {"fields": ["requested_domain", "alternative_domains"]}),
|
"cisa_representative_last_name",
|
||||||
(
|
"cisa_representative_email",
|
||||||
"Contacts",
|
]
|
||||||
{
|
|
||||||
"fields": [
|
contact_fields_without_portfolio = [
|
||||||
"converted_senior_official",
|
"senior_official",
|
||||||
"other_contacts",
|
"other_contacts",
|
||||||
"no_other_contacts_rationale",
|
"no_other_contacts_rationale",
|
||||||
"cisa_representative_first_name",
|
"cisa_representative_first_name",
|
||||||
"cisa_representative_last_name",
|
"cisa_representative_last_name",
|
||||||
"cisa_representative_email",
|
"cisa_representative_email",
|
||||||
]
|
]
|
||||||
},
|
|
||||||
),
|
background_fields = ["purpose", "anything_else", "current_websites"]
|
||||||
("Background info", {"fields": ["purpose", "anything_else", "current_websites"]}),
|
|
||||||
(
|
extends_type_of_org_base_end = [
|
||||||
"Type of organization",
|
"tribe_name",
|
||||||
{
|
"federally_recognized_tribe",
|
||||||
"fields": [
|
"state_recognized_tribe",
|
||||||
"is_election_board",
|
"about_your_organization",
|
||||||
"converted_generic_org_type",
|
]
|
||||||
]
|
|
||||||
},
|
extends_type_of_org_without_portfolio_start = [
|
||||||
),
|
"federal_type",
|
||||||
(
|
"federal_agency",
|
||||||
"Show details",
|
]
|
||||||
{
|
|
||||||
"classes": ["collapse--dgfieldset"],
|
extends_type_of_org_with_portfolio_start = [
|
||||||
"description": "Extends type of organization",
|
"converted_federal_type",
|
||||||
"fields": [
|
"converted_federal_agency",
|
||||||
"converted_federal_type",
|
]
|
||||||
"converted_federal_agency",
|
|
||||||
"tribe_name",
|
organization_address_fields_with_portfolio = [
|
||||||
"federally_recognized_tribe",
|
"converted_organization_name",
|
||||||
"state_recognized_tribe",
|
"converted_state_territory",
|
||||||
"about_your_organization",
|
]
|
||||||
],
|
|
||||||
},
|
organization_address_fields_without_portfolio = [
|
||||||
),
|
"organization_name",
|
||||||
(
|
"state_territory",
|
||||||
"Organization name and mailing address",
|
]
|
||||||
{
|
|
||||||
"fields": [
|
type_of_org_fields_with_portfolio = [
|
||||||
"converted_organization_name",
|
"is_election_board",
|
||||||
"converted_state_territory",
|
"converted_generic_org_type",
|
||||||
]
|
]
|
||||||
},
|
|
||||||
),
|
type_of_org_fields_without_portfolio = [
|
||||||
(
|
"is_election_board",
|
||||||
"Show details",
|
"generic_org_type",
|
||||||
{
|
]
|
||||||
"classes": ["collapse--dgfieldset"],
|
|
||||||
"description": "Extends organization name and mailing address",
|
show_details_address_with_portfolio = [
|
||||||
"fields": [
|
"converted_address_line1",
|
||||||
"converted_address_line1",
|
"converted_address_line2",
|
||||||
"converted_address_line2",
|
"converted_city",
|
||||||
"converted_city",
|
"converted_zipcode",
|
||||||
"converted_zipcode",
|
"converted_urbanization",
|
||||||
"converted_urbanization",
|
]
|
||||||
],
|
|
||||||
},
|
show_details_address_without_portfolio = [
|
||||||
),
|
"address_line1",
|
||||||
|
"address_line2",
|
||||||
|
"city",
|
||||||
|
"zipcode",
|
||||||
|
"urbanization",
|
||||||
]
|
]
|
||||||
|
|
||||||
# Readonly fields for analysts and superusers
|
# Readonly fields for analysts and superusers
|
||||||
|
@ -1892,6 +1896,9 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
"alternative_domains",
|
"alternative_domains",
|
||||||
"is_election_board",
|
"is_election_board",
|
||||||
"status_history",
|
"status_history",
|
||||||
|
)
|
||||||
|
|
||||||
|
readonly_fields_with_portfolio = [
|
||||||
"converted_senior_official",
|
"converted_senior_official",
|
||||||
"converted_federal_type",
|
"converted_federal_type",
|
||||||
"converted_federal_agency",
|
"converted_federal_agency",
|
||||||
|
@ -1903,7 +1910,21 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
"converted_urbanization",
|
"converted_urbanization",
|
||||||
"converted_city",
|
"converted_city",
|
||||||
"converted_generic_org_type",
|
"converted_generic_org_type",
|
||||||
)
|
]
|
||||||
|
|
||||||
|
readonly_fields_without_portfolio = [
|
||||||
|
"senior_official",
|
||||||
|
"federal_type",
|
||||||
|
"federal_agency",
|
||||||
|
"state_territory",
|
||||||
|
"organization_name",
|
||||||
|
"address_line1",
|
||||||
|
"address_line2",
|
||||||
|
"zipcode",
|
||||||
|
"urbanization",
|
||||||
|
"city",
|
||||||
|
"generic_org_type",
|
||||||
|
]
|
||||||
|
|
||||||
# Read only that we'll leverage for CISA Analysts
|
# Read only that we'll leverage for CISA Analysts
|
||||||
analyst_readonly_fields = [
|
analyst_readonly_fields = [
|
||||||
|
@ -1924,6 +1945,7 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
"suborganization_city",
|
"suborganization_city",
|
||||||
"suborganization_state_territory",
|
"suborganization_state_territory",
|
||||||
]
|
]
|
||||||
|
|
||||||
autocomplete_fields = [
|
autocomplete_fields = [
|
||||||
"approved_domain",
|
"approved_domain",
|
||||||
"requested_domain",
|
"requested_domain",
|
||||||
|
@ -1932,6 +1954,7 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
"portfolio",
|
"portfolio",
|
||||||
"sub_organization",
|
"sub_organization",
|
||||||
]
|
]
|
||||||
|
|
||||||
filter_horizontal = ("current_websites", "alternative_domains", "other_contacts")
|
filter_horizontal = ("current_websites", "alternative_domains", "other_contacts")
|
||||||
|
|
||||||
# Table ordering
|
# Table ordering
|
||||||
|
@ -1942,22 +1965,78 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
change_form_template = "django/admin/domain_request_change_form.html"
|
change_form_template = "django/admin/domain_request_change_form.html"
|
||||||
|
|
||||||
def get_fieldsets(self, request, obj=None):
|
def get_fieldsets(self, request, obj=None):
|
||||||
fieldsets = super().get_fieldsets(request, obj)
|
# fieldsets = list(super().get_fieldsets(request, obj)) # Get the default fieldsets
|
||||||
|
has_portfolio = obj and obj.portfolio # Check once for portfolio presence
|
||||||
|
|
||||||
# Hide certain suborg fields behind the organization feature flag
|
# Common fields
|
||||||
# if it is not enabled
|
fieldsets = [(None, {"fields": self.common_fields})]
|
||||||
|
fieldsets.append((".gov domain", {"fields": ["requested_domain", "alternative_domains"]}))
|
||||||
|
|
||||||
|
# Contacts fields based on portfolio
|
||||||
|
contacts_fields = self.contact_fields_with_portfolio if has_portfolio else self.contact_fields_without_portfolio
|
||||||
|
fieldsets.append(("Contacts", {"fields": contacts_fields}))
|
||||||
|
|
||||||
|
# Background info
|
||||||
|
fieldsets.append(("Background info", {"fields": self.background_fields}))
|
||||||
|
|
||||||
|
# Type of organization based on portfolio
|
||||||
|
type_of_org_fields = (
|
||||||
|
self.type_of_org_fields_with_portfolio if has_portfolio else self.type_of_org_fields_without_portfolio
|
||||||
|
)
|
||||||
|
fieldsets.append(("Type of organization", {"fields": type_of_org_fields}))
|
||||||
|
|
||||||
|
fieldsets.append(
|
||||||
|
(
|
||||||
|
"Show details",
|
||||||
|
{
|
||||||
|
"classes": ["collapse--dgfieldset"],
|
||||||
|
"description": "Extends type of organization",
|
||||||
|
"fields": (
|
||||||
|
self.extends_type_of_org_with_portfolio_start
|
||||||
|
if has_portfolio
|
||||||
|
else self.extends_type_of_org_without_portfolio_start + self.extends_type_of_org_base_end
|
||||||
|
),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Organization name and address
|
||||||
|
address_fields = (
|
||||||
|
self.organization_address_fields_with_portfolio
|
||||||
|
if has_portfolio
|
||||||
|
else self.organization_address_fields_without_portfolio
|
||||||
|
)
|
||||||
|
fieldsets.append(("Organization name and mailing address", {"fields": address_fields}))
|
||||||
|
|
||||||
|
# Additional "Show details" sections
|
||||||
|
fieldsets.append(
|
||||||
|
(
|
||||||
|
"Show details",
|
||||||
|
{
|
||||||
|
"classes": ["collapse--dgfieldset"],
|
||||||
|
"description": "Extends organization name and mailing address",
|
||||||
|
"fields": (
|
||||||
|
self.show_details_address_with_portfolio
|
||||||
|
if has_portfolio
|
||||||
|
else self.show_details_address_without_portfolio
|
||||||
|
),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Flag-based field exclusion
|
||||||
if not flag_is_active_for_user(request.user, "organization_feature"):
|
if not flag_is_active_for_user(request.user, "organization_feature"):
|
||||||
excluded_fields = [
|
excluded_fields = [
|
||||||
"requested_suborganization",
|
"requested_suborganization",
|
||||||
"suborganization_city",
|
"suborganization_city",
|
||||||
"suborganization_state_territory",
|
"suborganization_state_territory",
|
||||||
]
|
]
|
||||||
modified_fieldsets = []
|
# Filter out the excluded fields
|
||||||
for name, data in fieldsets:
|
fieldsets = [
|
||||||
fields = data.get("fields", [])
|
(name, {**data, "fields": [f for f in data["fields"] if f not in excluded_fields]})
|
||||||
fields = tuple(field for field in fields if field not in excluded_fields)
|
for name, data in fieldsets
|
||||||
modified_fieldsets.append((name, {**data, "fields": fields}))
|
]
|
||||||
return modified_fieldsets
|
|
||||||
return fieldsets
|
return fieldsets
|
||||||
|
|
||||||
# Trigger action when a fieldset is changed
|
# Trigger action when a fieldset is changed
|
||||||
|
@ -2150,7 +2229,8 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
we'll use the baseline readonly_fields and extend it as needed.
|
we'll use the baseline readonly_fields and extend it as needed.
|
||||||
"""
|
"""
|
||||||
readonly_fields = list(self.readonly_fields)
|
readonly_fields = list(self.readonly_fields)
|
||||||
|
if obj and obj.portfolio:
|
||||||
|
readonly_fields.extend(self.readonly_fields_with_portfolio)
|
||||||
# Check if the creator is restricted
|
# Check if the creator is restricted
|
||||||
if obj and obj.creator.status == models.User.RESTRICTED:
|
if obj and obj.creator.status == models.User.RESTRICTED:
|
||||||
# For fields like CharField, IntegerField, etc., the widget used is
|
# For fields like CharField, IntegerField, etc., the widget used is
|
||||||
|
|
|
@ -327,7 +327,7 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html)
|
||||||
{% if not skip_additional_contact_info %}
|
{% if not skip_additional_contact_info %}
|
||||||
{% include "django/admin/includes/user_detail_list.html" with user=original_object.creator no_title_top_padding=field.is_readonly %}
|
{% include "django/admin/includes/user_detail_list.html" with user=original_object.creator no_title_top_padding=field.is_readonly %}
|
||||||
{% endif%}
|
{% endif%}
|
||||||
{% elif field.field.name == "converted_senior_official" or field.field.name == "senior_official" %}
|
{% elif field.field.name == "senior_official" or field.field.name == "converted_senior_official" %}
|
||||||
<div class="flex-container">
|
<div class="flex-container">
|
||||||
<label aria-label="Senior official contact details"></label>
|
<label aria-label="Senior official contact details"></label>
|
||||||
{% include "django/admin/includes/contact_detail_list.html" with user=original_object.senior_official no_title_top_padding=field.is_readonly %}
|
{% include "django/admin/includes/contact_detail_list.html" with user=original_object.senior_official no_title_top_padding=field.is_readonly %}
|
||||||
|
@ -388,7 +388,7 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html)
|
||||||
</details>
|
</details>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
{% elif field.field.name == "converted_state_territory" or field.field.name == "state_territory" and original_object|model_name_lowercase != 'portfolio' %}
|
{% elif field.field.name == "state_territory" and original_object|model_name_lowercase != 'portfolio' %}
|
||||||
<div class="flex-container margin-top-2">
|
<div class="flex-container margin-top-2">
|
||||||
<span>
|
<span>
|
||||||
CISA region:
|
CISA region:
|
||||||
|
|
|
@ -160,6 +160,7 @@ class TestDomainRequestAdmin(MockEppLib):
|
||||||
("no_other_contacts_rationale", "Required if creator does not list other employees"),
|
("no_other_contacts_rationale", "Required if creator does not list other employees"),
|
||||||
("alternative_domains", "Other domain names the creator provided for consideration"),
|
("alternative_domains", "Other domain names the creator provided for consideration"),
|
||||||
("no_other_contacts_rationale", "Required if creator does not list other employees"),
|
("no_other_contacts_rationale", "Required if creator does not list other employees"),
|
||||||
|
("Urbanization", "Required for Puerto Rico only"),
|
||||||
]
|
]
|
||||||
self.test_helper.assert_response_contains_distinct_values(response, expected_values)
|
self.test_helper.assert_response_contains_distinct_values(response, expected_values)
|
||||||
|
|
||||||
|
@ -1630,17 +1631,6 @@ class TestDomainRequestAdmin(MockEppLib):
|
||||||
"alternative_domains",
|
"alternative_domains",
|
||||||
"is_election_board",
|
"is_election_board",
|
||||||
"status_history",
|
"status_history",
|
||||||
"converted_senior_official",
|
|
||||||
"converted_federal_type",
|
|
||||||
"converted_federal_agency",
|
|
||||||
"converted_state_territory",
|
|
||||||
"converted_organization_name",
|
|
||||||
"converted_address_line1",
|
|
||||||
"converted_address_line2",
|
|
||||||
"converted_zipcode",
|
|
||||||
"converted_urbanization",
|
|
||||||
"converted_city",
|
|
||||||
"converted_generic_org_type",
|
|
||||||
"id",
|
"id",
|
||||||
"created_at",
|
"created_at",
|
||||||
"updated_at",
|
"updated_at",
|
||||||
|
@ -1706,17 +1696,6 @@ class TestDomainRequestAdmin(MockEppLib):
|
||||||
"alternative_domains",
|
"alternative_domains",
|
||||||
"is_election_board",
|
"is_election_board",
|
||||||
"status_history",
|
"status_history",
|
||||||
"converted_senior_official",
|
|
||||||
"converted_federal_type",
|
|
||||||
"converted_federal_agency",
|
|
||||||
"converted_state_territory",
|
|
||||||
"converted_organization_name",
|
|
||||||
"converted_address_line1",
|
|
||||||
"converted_address_line2",
|
|
||||||
"converted_zipcode",
|
|
||||||
"converted_urbanization",
|
|
||||||
"converted_city",
|
|
||||||
"converted_generic_org_type",
|
|
||||||
"converted_federal_agency",
|
"converted_federal_agency",
|
||||||
"creator",
|
"creator",
|
||||||
"about_your_organization",
|
"about_your_organization",
|
||||||
|
@ -1749,17 +1728,6 @@ class TestDomainRequestAdmin(MockEppLib):
|
||||||
"alternative_domains",
|
"alternative_domains",
|
||||||
"is_election_board",
|
"is_election_board",
|
||||||
"status_history",
|
"status_history",
|
||||||
"converted_senior_official",
|
|
||||||
"converted_federal_type",
|
|
||||||
"converted_federal_agency",
|
|
||||||
"converted_state_territory",
|
|
||||||
"converted_organization_name",
|
|
||||||
"converted_address_line1",
|
|
||||||
"converted_address_line2",
|
|
||||||
"converted_zipcode",
|
|
||||||
"converted_urbanization",
|
|
||||||
"converted_city",
|
|
||||||
"converted_generic_org_type",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
self.assertEqual(readonly_fields, expected_fields)
|
self.assertEqual(readonly_fields, expected_fields)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue