From a961328d78407b92daa1e92e06fbce6fccbea920 Mon Sep 17 00:00:00 2001 From: Rachid Mrad Date: Wed, 1 May 2024 18:18:21 -0400 Subject: [PATCH 01/10] Add CISA region on domain requests change form --- .../admin/includes/detail_table_fieldset.html | 12 ++++ src/registrar/templatetags/custom_filters.py | 63 +++++++++++++++++++ src/registrar/tests/test_admin.py | 60 ++++++++++++++++++ src/registrar/views/utility/generic_helper.py | 63 +++++++++++++++++++ 4 files changed, 198 insertions(+) create mode 100644 src/registrar/views/utility/generic_helper.py diff --git a/src/registrar/templates/django/admin/includes/detail_table_fieldset.html b/src/registrar/templates/django/admin/includes/detail_table_fieldset.html index ea8e7579f..eafec405e 100644 --- a/src/registrar/templates/django/admin/includes/detail_table_fieldset.html +++ b/src/registrar/templates/django/admin/includes/detail_table_fieldset.html @@ -1,4 +1,5 @@ {% extends "admin/fieldset.html" %} +{% load custom_filters %} {% load static url_helpers %} {% comment %} @@ -126,5 +127,16 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html) {% endif %} {% endwith %} + {% elif field.field.name == "state_territory" %} +
+ + CISA Region: + {% if original_object.generic_org_type != "federal" %} + {{ original_object.state_territory|get_region }} + {% else %} + N/A + {% endif %} + +
{% endif %} {% endblock after_help_text %} diff --git a/src/registrar/templatetags/custom_filters.py b/src/registrar/templatetags/custom_filters.py index 9fa5c9aa9..af2c15db2 100644 --- a/src/registrar/templatetags/custom_filters.py +++ b/src/registrar/templatetags/custom_filters.py @@ -67,3 +67,66 @@ def get_organization_long_name(generic_org_type): @register.filter(name="has_permission") def has_permission(user, permission): return user.has_perm(permission) + + +@register.filter +def get_region(state): + regions = { + "CT": 1, + "ME": 1, + "MA": 1, + "NH": 1, + "RI": 1, + "VT": 1, + "NJ": 2, + "NY": 2, + "PR": 2, + "VI": 2, + "DE": 3, + "DC": 3, + "MD": 3, + "PA": 3, + "VA": 3, + "WV": 3, + "AL": 4, + "FL": 4, + "GA": 4, + "KY": 4, + "MS": 4, + "NC": 4, + "SC": 4, + "TN": 4, + "IL": 5, + "IN": 5, + "MI": 5, + "MN": 5, + "OH": 5, + "WI": 5, + "AR": 6, + "LA": 6, + "NM": 6, + "OK": 6, + "TX": 6, + "IA": 7, + "KS": 7, + "MO": 7, + "NE": 7, + "CO": 8, + "MT": 8, + "ND": 8, + "SD": 8, + "UT": 8, + "WY": 8, + "AZ": 9, + "CA": 9, + "HI": 9, + "NV": 9, + "GU": 9, + "AS": 9, + "MP": 9, + "AK": 10, + "ID": 10, + "OR": 10, + "WA": 10, + } + return regions.get(state.upper(), None) diff --git a/src/registrar/tests/test_admin.py b/src/registrar/tests/test_admin.py index b42667e01..00e6265a0 100644 --- a/src/registrar/tests/test_admin.py +++ b/src/registrar/tests/test_admin.py @@ -2392,6 +2392,66 @@ class TestDomainRequestAdmin(MockEppLib): self.assertEqual(expected_list, actual_list) + @less_console_noise_decorator + def test_staff_can_see_cisa_region_federal(self): + """Tests if staff can see CISA Region: N/A""" + + # Create a fake domain request + _domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.IN_REVIEW) + + p = "userpass" + self.client.login(username="staffuser", password=p) + response = self.client.get( + "/admin/registrar/domainrequest/{}/change/".format(_domain_request.pk), + follow=True, + ) + + # Make sure the page loaded, and that we're on the right page + self.assertEqual(response.status_code, 200) + self.assertContains(response, _domain_request.requested_domain.name) + + # Test if the page has the right CISA region + expected_html = '
' "CISA Region: N/A" "
" + # Remove whitespace from expected_html + expected_html = "".join(expected_html.split()) + + # Remove whitespace from response content + response_content = "".join(response.content.decode().split()) + + # Check if response contains expected_html + self.assertIn(expected_html, response_content) + + @less_console_noise_decorator + def test_staff_can_see_cisa_region_non_federal(self): + """Tests if staff can see the correct CISA region""" + + # Create a fake domain request. State will be NY (2). + _domain_request = completed_domain_request( + status=DomainRequest.DomainRequestStatus.IN_REVIEW, generic_org_type="interstate" + ) + + p = "userpass" + self.client.login(username="staffuser", password=p) + response = self.client.get( + "/admin/registrar/domainrequest/{}/change/".format(_domain_request.pk), + follow=True, + ) + + # Make sure the page loaded, and that we're on the right page + self.assertEqual(response.status_code, 200) + self.assertContains(response, _domain_request.requested_domain.name) + + # Test if the page has the right CISA region + expected_html = '
' 'CISA Region: 2' "
" + # Remove whitespace from expected_html + expected_html = "".join(expected_html.split()) + + # Remove whitespace from response content + response_content = "".join(response.content.decode().split()) + + # Check if response contains expected_html + self.assertIn(expected_html, response_content) + def tearDown(self): super().tearDown() Domain.objects.all().delete() diff --git a/src/registrar/views/utility/generic_helper.py b/src/registrar/views/utility/generic_helper.py new file mode 100644 index 000000000..16ef1435d --- /dev/null +++ b/src/registrar/views/utility/generic_helper.py @@ -0,0 +1,63 @@ +"""This file contains general purpose helpers that don't belong in any specific location""" + + +def get_region(state): + regions = { + "CT": 1, + "ME": 1, + "MA": 1, + "NH": 1, + "RI": 1, + "VT": 1, + "NJ": 2, + "NY": 2, + "PR": 2, + "VI": 2, + "DE": 3, + "DC": 3, + "MD": 3, + "PA": 3, + "VA": 3, + "WV": 3, + "AL": 4, + "FL": 4, + "GA": 4, + "KY": 4, + "MS": 4, + "NC": 4, + "SC": 4, + "TN": 4, + "IL": 5, + "IN": 5, + "MI": 5, + "MN": 5, + "OH": 5, + "WI": 5, + "AR": 6, + "LA": 6, + "NM": 6, + "OK": 6, + "TX": 6, + "IA": 7, + "KS": 7, + "MO": 7, + "NE": 7, + "CO": 8, + "MT": 8, + "ND": 8, + "SD": 8, + "UT": 8, + "WY": 8, + "AZ": 9, + "CA": 9, + "HI": 9, + "NV": 9, + "GU": 9, + "AS": 9, + "MP": 9, + "AK": 10, + "ID": 10, + "OR": 10, + "WA": 10, + } + return regions.get(state.upper(), None) From 501f68ea77a02fe5afc124b24eafa176667769d2 Mon Sep 17 00:00:00 2001 From: Rachid Mrad Date: Wed, 1 May 2024 18:22:25 -0400 Subject: [PATCH 02/10] cleanup --- src/registrar/tests/test_admin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/registrar/tests/test_admin.py b/src/registrar/tests/test_admin.py index 00e6265a0..49f3f681a 100644 --- a/src/registrar/tests/test_admin.py +++ b/src/registrar/tests/test_admin.py @@ -2411,7 +2411,7 @@ class TestDomainRequestAdmin(MockEppLib): self.assertContains(response, _domain_request.requested_domain.name) # Test if the page has the right CISA region - expected_html = '
' "CISA Region: N/A" "
" + expected_html = '
' "CISA region: N/A" "
" # Remove whitespace from expected_html expected_html = "".join(expected_html.split()) @@ -2442,7 +2442,7 @@ class TestDomainRequestAdmin(MockEppLib): self.assertContains(response, _domain_request.requested_domain.name) # Test if the page has the right CISA region - expected_html = '
' 'CISA Region: 2' "
" + expected_html = '
' 'CISA region: 2' "
" # Remove whitespace from expected_html expected_html = "".join(expected_html.split()) From e454831426ae85c26e192e668e77615634c02c42 Mon Sep 17 00:00:00 2001 From: Rachid Mrad Date: Wed, 1 May 2024 18:24:11 -0400 Subject: [PATCH 03/10] cleanup --- src/registrar/views/utility/generic_helper.py | 63 ------------------- 1 file changed, 63 deletions(-) delete mode 100644 src/registrar/views/utility/generic_helper.py diff --git a/src/registrar/views/utility/generic_helper.py b/src/registrar/views/utility/generic_helper.py deleted file mode 100644 index 16ef1435d..000000000 --- a/src/registrar/views/utility/generic_helper.py +++ /dev/null @@ -1,63 +0,0 @@ -"""This file contains general purpose helpers that don't belong in any specific location""" - - -def get_region(state): - regions = { - "CT": 1, - "ME": 1, - "MA": 1, - "NH": 1, - "RI": 1, - "VT": 1, - "NJ": 2, - "NY": 2, - "PR": 2, - "VI": 2, - "DE": 3, - "DC": 3, - "MD": 3, - "PA": 3, - "VA": 3, - "WV": 3, - "AL": 4, - "FL": 4, - "GA": 4, - "KY": 4, - "MS": 4, - "NC": 4, - "SC": 4, - "TN": 4, - "IL": 5, - "IN": 5, - "MI": 5, - "MN": 5, - "OH": 5, - "WI": 5, - "AR": 6, - "LA": 6, - "NM": 6, - "OK": 6, - "TX": 6, - "IA": 7, - "KS": 7, - "MO": 7, - "NE": 7, - "CO": 8, - "MT": 8, - "ND": 8, - "SD": 8, - "UT": 8, - "WY": 8, - "AZ": 9, - "CA": 9, - "HI": 9, - "NV": 9, - "GU": 9, - "AS": 9, - "MP": 9, - "AK": 10, - "ID": 10, - "OR": 10, - "WA": 10, - } - return regions.get(state.upper(), None) From 1821735c8bf89f0a9bbb5b9b40e87b1cba9577e6 Mon Sep 17 00:00:00 2001 From: Rachid Mrad Date: Wed, 1 May 2024 18:32:34 -0400 Subject: [PATCH 04/10] cleanup --- .../templates/django/admin/includes/detail_table_fieldset.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/registrar/templates/django/admin/includes/detail_table_fieldset.html b/src/registrar/templates/django/admin/includes/detail_table_fieldset.html index eafec405e..6954b1fea 100644 --- a/src/registrar/templates/django/admin/includes/detail_table_fieldset.html +++ b/src/registrar/templates/django/admin/includes/detail_table_fieldset.html @@ -130,7 +130,7 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html) {% elif field.field.name == "state_territory" %}
- CISA Region: + CISA region: {% if original_object.generic_org_type != "federal" %} {{ original_object.state_territory|get_region }} {% else %} From f24fd1f510a985847e5322b791281dbe5548d3ee Mon Sep 17 00:00:00 2001 From: Rachid Mrad Date: Wed, 1 May 2024 18:46:21 -0400 Subject: [PATCH 05/10] fix tests --- src/registrar/tests/test_admin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/registrar/tests/test_admin.py b/src/registrar/tests/test_admin.py index 49f3f681a..8ed966fc4 100644 --- a/src/registrar/tests/test_admin.py +++ b/src/registrar/tests/test_admin.py @@ -2411,7 +2411,7 @@ class TestDomainRequestAdmin(MockEppLib): self.assertContains(response, _domain_request.requested_domain.name) # Test if the page has the right CISA region - expected_html = '
' "CISA region: N/A" "
" + expected_html = '
CISA region: N/A
' # Remove whitespace from expected_html expected_html = "".join(expected_html.split()) @@ -2442,7 +2442,7 @@ class TestDomainRequestAdmin(MockEppLib): self.assertContains(response, _domain_request.requested_domain.name) # Test if the page has the right CISA region - expected_html = '
' 'CISA region: 2' "
" + expected_html = '
CISA region: 2
' # Remove whitespace from expected_html expected_html = "".join(expected_html.split()) From b198120ef8d9979e1acb4debf4aa31d1114dedfe Mon Sep 17 00:00:00 2001 From: Rachid Mrad Date: Thu, 2 May 2024 14:19:15 -0400 Subject: [PATCH 06/10] handle case where state is empty --- src/registrar/templatetags/custom_filters.py | 122 ++++++++++--------- 1 file changed, 63 insertions(+), 59 deletions(-) diff --git a/src/registrar/templatetags/custom_filters.py b/src/registrar/templatetags/custom_filters.py index af2c15db2..169064cb8 100644 --- a/src/registrar/templatetags/custom_filters.py +++ b/src/registrar/templatetags/custom_filters.py @@ -71,62 +71,66 @@ def has_permission(user, permission): @register.filter def get_region(state): - regions = { - "CT": 1, - "ME": 1, - "MA": 1, - "NH": 1, - "RI": 1, - "VT": 1, - "NJ": 2, - "NY": 2, - "PR": 2, - "VI": 2, - "DE": 3, - "DC": 3, - "MD": 3, - "PA": 3, - "VA": 3, - "WV": 3, - "AL": 4, - "FL": 4, - "GA": 4, - "KY": 4, - "MS": 4, - "NC": 4, - "SC": 4, - "TN": 4, - "IL": 5, - "IN": 5, - "MI": 5, - "MN": 5, - "OH": 5, - "WI": 5, - "AR": 6, - "LA": 6, - "NM": 6, - "OK": 6, - "TX": 6, - "IA": 7, - "KS": 7, - "MO": 7, - "NE": 7, - "CO": 8, - "MT": 8, - "ND": 8, - "SD": 8, - "UT": 8, - "WY": 8, - "AZ": 9, - "CA": 9, - "HI": 9, - "NV": 9, - "GU": 9, - "AS": 9, - "MP": 9, - "AK": 10, - "ID": 10, - "OR": 10, - "WA": 10, - } - return regions.get(state.upper(), None) + if state and isinstance(state, str): + regions = { + "CT": 1, + "ME": 1, + "MA": 1, + "NH": 1, + "RI": 1, + "VT": 1, + "NJ": 2, + "NY": 2, + "PR": 2, + "VI": 2, + "DE": 3, + "DC": 3, + "MD": 3, + "PA": 3, + "VA": 3, + "WV": 3, + "AL": 4, + "FL": 4, + "GA": 4, + "KY": 4, + "MS": 4, + "NC": 4, + "SC": 4, + "TN": 4, + "IL": 5, + "IN": 5, + "MI": 5, + "MN": 5, + "OH": 5, + "WI": 5, + "AR": 6, + "LA": 6, + "NM": 6, + "OK": 6, + "TX": 6, + "IA": 7, + "KS": 7, + "MO": 7, + "NE": 7, + "CO": 8, + "MT": 8, + "ND": 8, + "SD": 8, + "UT": 8, + "WY": 8, + "AZ": 9, + "CA": 9, + "HI": 9, + "NV": 9, + "GU": 9, + "AS": 9, + "MP": 9, + "AK": 10, + "ID": 10, + "OR": 10, + "WA": 10, + } + return regions.get(state.upper(), None) + else: + return None + From a502be9c40ab63f9181e0afb815b3ca8945039a8 Mon Sep 17 00:00:00 2001 From: Rachid Mrad Date: Thu, 2 May 2024 14:22:52 -0400 Subject: [PATCH 07/10] cleanup --- src/registrar/templatetags/custom_filters.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/registrar/templatetags/custom_filters.py b/src/registrar/templatetags/custom_filters.py index 169064cb8..ff350197c 100644 --- a/src/registrar/templatetags/custom_filters.py +++ b/src/registrar/templatetags/custom_filters.py @@ -133,4 +133,3 @@ def get_region(state): return regions.get(state.upper(), None) else: return None - From c41b21aa8ebdc0802de7882d433f7a4b172c161a Mon Sep 17 00:00:00 2001 From: Rachid Mrad Date: Thu, 2 May 2024 14:37:32 -0400 Subject: [PATCH 08/10] push missing JS --- src/registrar/assets/js/dja-collapse.js | 45 +++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/registrar/assets/js/dja-collapse.js diff --git a/src/registrar/assets/js/dja-collapse.js b/src/registrar/assets/js/dja-collapse.js new file mode 100644 index 000000000..e1a16cc1a --- /dev/null +++ b/src/registrar/assets/js/dja-collapse.js @@ -0,0 +1,45 @@ +/* + * We will run our own version of + * https://github.com/django/django/blob/195d885ca01b14e3ce9a1881c3b8f7074f953736/django/contrib/admin/static/admin/js/collapse.js + * Works with our fieldset override +*/ + +/*global gettext*/ +'use strict'; +{ + window.addEventListener('load', function() { + // Add anchor tag for Show/Hide link + const fieldsets = document.querySelectorAll('fieldset.collapse--dotgov'); + for (const [i, elem] of fieldsets.entries()) { + // Don't hide if fields in this fieldset have errors + if (elem.querySelectorAll('div.errors, ul.errorlist').length === 0) { + elem.classList.add('collapsed'); + const button = elem.querySelector('button'); + button.id = 'fieldsetcollapser' + i; + button.className = 'collapse-toggle--dotgov usa-button usa-button--unstyled'; + } + } + // Add toggle to hide/show anchor tag + const toggleFuncDotgov = function(e) { + e.preventDefault(); + e.stopPropagation(); + const fieldset = this.closest('fieldset'); + const spanElement = this.querySelector('span'); + const useElement = this.querySelector('use'); + if (fieldset.classList.contains('collapsed')) { + // Show + spanElement.textContent = 'Hide details'; + useElement.setAttribute('xlink:href', '/public/img/sprite.svg#expand_less'); + fieldset.classList.remove('collapsed'); + } else { + // Hide + spanElement.textContent = 'Show details'; + useElement.setAttribute('xlink:href', '/public/img/sprite.svg#expand_more'); + fieldset.classList.add('collapsed'); + } + }; + document.querySelectorAll('.collapse-toggle--dotgov').forEach(function(el) { + el.addEventListener('click', toggleFuncDotgov); + }); + }); +} \ No newline at end of file From 7f92aaf55bf085c1bbd438020804a00372d244df Mon Sep 17 00:00:00 2001 From: Rachid Mrad <107004823+rachidatecs@users.noreply.github.com> Date: Thu, 2 May 2024 18:11:01 -0400 Subject: [PATCH 09/10] Update src/registrar/templates/django/admin/includes/detail_table_fieldset.html Co-authored-by: zandercymatics <141044360+zandercymatics@users.noreply.github.com> --- .../templates/django/admin/includes/detail_table_fieldset.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/registrar/templates/django/admin/includes/detail_table_fieldset.html b/src/registrar/templates/django/admin/includes/detail_table_fieldset.html index 6954b1fea..adbe3f7d1 100644 --- a/src/registrar/templates/django/admin/includes/detail_table_fieldset.html +++ b/src/registrar/templates/django/admin/includes/detail_table_fieldset.html @@ -131,7 +131,7 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html)
CISA region: - {% if original_object.generic_org_type != "federal" %} + {% if original_object.generic_org_type and original_object.generic_org_type != original_object.OrganizationChoices.FEDERAL %} {{ original_object.state_territory|get_region }} {% else %} N/A From ec70c28848a437afa2ab6d515b513c3309fc5839 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Mon, 6 May 2024 08:51:06 -0600 Subject: [PATCH 10/10] Return N/A on edgecase --- src/registrar/templatetags/custom_filters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/registrar/templatetags/custom_filters.py b/src/registrar/templatetags/custom_filters.py index ff350197c..798558355 100644 --- a/src/registrar/templatetags/custom_filters.py +++ b/src/registrar/templatetags/custom_filters.py @@ -130,6 +130,6 @@ def get_region(state): "OR": 10, "WA": 10, } - return regions.get(state.upper(), None) + return regions.get(state.upper(), "N/A") else: return None