From e30650abee974197b5edeab624f80964b7b54b8b Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Tue, 14 May 2024 14:00:32 -0600 Subject: [PATCH 1/6] Set federal agency if none exist --- src/registrar/models/domain_request.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/registrar/models/domain_request.py b/src/registrar/models/domain_request.py index 09f2b9fab..57f901779 100644 --- a/src/registrar/models/domain_request.py +++ b/src/registrar/models/domain_request.py @@ -751,6 +751,10 @@ class DomainRequest(TimeStampedModel): domain request into an admin on that domain. It also triggers an email notification.""" + if self.federal_agency is None: + self.federal_agency = "Non-Federal Agency" + self.save() + # create the domain Domain = apps.get_model("registrar.Domain") From af20a9b52a6daca90c6b43c49bdb046c86b43fde Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Tue, 14 May 2024 14:50:17 -0600 Subject: [PATCH 2/6] Add unit test --- src/registrar/models/domain_request.py | 3 ++- src/registrar/tests/test_models.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/registrar/models/domain_request.py b/src/registrar/models/domain_request.py index 57f901779..2501cdc87 100644 --- a/src/registrar/models/domain_request.py +++ b/src/registrar/models/domain_request.py @@ -9,6 +9,7 @@ from django.db import models from django_fsm import FSMField, transition # type: ignore from django.utils import timezone from registrar.models.domain import Domain +from registrar.models.federal_agency import FederalAgency from registrar.models.utility.generic_helper import CreateOrUpdateOrganizationTypeHelper from registrar.utility.errors import FSMDomainRequestError, FSMErrorCodes @@ -752,7 +753,7 @@ class DomainRequest(TimeStampedModel): notification.""" if self.federal_agency is None: - self.federal_agency = "Non-Federal Agency" + self.federal_agency = FederalAgency.objects.filter(agency="Non-Federal Agency").first() self.save() # create the domain diff --git a/src/registrar/tests/test_models.py b/src/registrar/tests/test_models.py index 1558ab310..847168356 100644 --- a/src/registrar/tests/test_models.py +++ b/src/registrar/tests/test_models.py @@ -12,6 +12,7 @@ from registrar.models import ( DraftDomain, DomainInvitation, UserDomainRole, + FederalAgency, ) import boto3_mocking @@ -75,6 +76,26 @@ class TestDomainRequest(TestCase): with less_console_noise(): return self.assertRaises(Exception, None, exception_type) + def test_federal_agency_set_to_non_federal_on_approve(self): + """Ensures that when the federal_agency field is 'none' when .approve() is called, + the field is set to the 'Non-Federal Agency' record""" + domain_request = completed_domain_request( + status=DomainRequest.DomainRequestStatus.IN_REVIEW, + name="city2.gov", + federal_agency=None, + ) + + # Ensure that the federal agency is None + self.assertEqual(domain_request.federal_agency, None) + + # Approve the request + domain_request.approve() + self.assertEqual(domain_request.status, DomainRequest.DomainRequestStatus.APPROVED) + + # After approval, it should be "Non-Federal agency" + expected_federal_agency = FederalAgency.objects.filter(agency="Non-Federal Agency").first() + self.assertEqual(domain_request.federal_agency, expected_federal_agency) + def test_empty_create_fails(self): """Can't create a completely empty domain request. NOTE: something about theexception this test raises messes up with the From 70cd55f623cf3dd69131cd288fcb8302fe4dae7a Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Wed, 15 May 2024 08:16:46 -0600 Subject: [PATCH 3/6] Fix unit test --- src/registrar/tests/test_admin.py | 2 +- src/registrar/tests/test_models.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/registrar/tests/test_admin.py b/src/registrar/tests/test_admin.py index 632099dde..4a6e76e3d 100644 --- a/src/registrar/tests/test_admin.py +++ b/src/registrar/tests/test_admin.py @@ -646,7 +646,7 @@ class TestDomainAdmin(MockEppLib, WebTest): response = self.client.get("/admin/registrar/domain/") # There are 4 template references to Federal (4) plus four references in the table # for our actual domain_request - self.assertContains(response, "Federal", count=54) + self.assertContains(response, "Federal", count=56) # This may be a bit more robust self.assertContains(response, 'Federal', count=1) # Now let's make sure the long description does not exist diff --git a/src/registrar/tests/test_models.py b/src/registrar/tests/test_models.py index 847168356..fa074c3c6 100644 --- a/src/registrar/tests/test_models.py +++ b/src/registrar/tests/test_models.py @@ -963,6 +963,7 @@ class TestDomainInformation(TestCase): domain=domain, notes="test notes", domain_request=domain_request, + federal_agency=FederalAgency.objects.get(agency="Non-Federal Agency"), ).__dict__ # Test the two records for consistency From c25cbb808c03395acae5f2fa1794373feb250ef1 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Wed, 15 May 2024 13:03:56 -0600 Subject: [PATCH 4/6] Create 0094_create_groups_v12.py --- .../migrations/0094_create_groups_v12.py | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/registrar/migrations/0094_create_groups_v12.py diff --git a/src/registrar/migrations/0094_create_groups_v12.py b/src/registrar/migrations/0094_create_groups_v12.py new file mode 100644 index 000000000..42106cdb5 --- /dev/null +++ b/src/registrar/migrations/0094_create_groups_v12.py @@ -0,0 +1,37 @@ +# This migration creates the create_full_access_group and create_cisa_analyst_group groups +# It is dependent on 0079 (which populates federal agencies) +# If permissions on the groups need changing, edit CISA_ANALYST_GROUP_PERMISSIONS +# in the user_group model then: +# [NOT RECOMMENDED] +# step 1: docker-compose exec app ./manage.py migrate --fake registrar 0035_contenttypes_permissions +# step 2: docker-compose exec app ./manage.py migrate registrar 0036_create_groups +# step 3: fake run the latest migration in the migrations list +# [RECOMMENDED] +# Alternatively: +# step 1: duplicate the migration that loads data +# step 2: docker-compose exec app ./manage.py migrate + +from django.db import migrations +from registrar.models import UserGroup +from typing import Any + + +# For linting: RunPython expects a function reference, +# so let's give it one +def create_groups(apps, schema_editor) -> Any: + UserGroup.create_cisa_analyst_group(apps, schema_editor) + UserGroup.create_full_access_group(apps, schema_editor) + + +class Migration(migrations.Migration): + dependencies = [ + ("registrar", "0093_alter_publiccontact_unique_together"), + ] + + operations = [ + migrations.RunPython( + create_groups, + reverse_code=migrations.RunPython.noop, + atomic=True, + ), + ] From b6797c3486e4156206e5078c566c8e85a56cd033 Mon Sep 17 00:00:00 2001 From: Rachid Mrad Date: Fri, 17 May 2024 15:33:47 -0400 Subject: [PATCH 5/6] Remove widget def for agency name to fix form input on domain manage agency form --- src/registrar/forms/domain.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/registrar/forms/domain.py b/src/registrar/forms/domain.py index da1462bdb..0e9fbb693 100644 --- a/src/registrar/forms/domain.py +++ b/src/registrar/forms/domain.py @@ -385,7 +385,6 @@ class DomainOrgNameAddressForm(forms.ModelForm): # because for this fields we are creating an individual # instance of the Select. For the other fields we use the for loop to set # the class's required attribute to true. - "federal_agency": forms.TextInput, "organization_name": forms.TextInput, "address_line1": forms.TextInput, "address_line2": forms.TextInput, From a1ff0b63ae2547120bc6f48b0b2e2910b51946d0 Mon Sep 17 00:00:00 2001 From: Rachid Mrad Date: Fri, 17 May 2024 16:01:15 -0400 Subject: [PATCH 6/6] fix unit test --- src/registrar/tests/test_views_domain.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/registrar/tests/test_views_domain.py b/src/registrar/tests/test_views_domain.py index 1d9fbb2a8..40613caa2 100644 --- a/src/registrar/tests/test_views_domain.py +++ b/src/registrar/tests/test_views_domain.py @@ -1447,7 +1447,7 @@ class TestDomainOrganization(TestDomainOverview): session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] - org_name_page.form["federal_agency"] = "Department of State" + org_name_page.form["federal_agency"] = FederalAgency.objects.filter(agency="Department of State").get().id org_name_page.form["city"] = "Faketown" self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) @@ -1456,9 +1456,8 @@ class TestDomainOrganization(TestDomainOverview): success_result_page = org_name_page.form.submit() self.assertEqual(success_result_page.status_code, 200) - # Check for the old and new value - self.assertContains(success_result_page, federal_agency.id) - self.assertNotContains(success_result_page, "Department of State") + # Check that the agency has not changed + self.assertEqual(self.domain_information.federal_agency.agency, "AMTRAK") # Do another check on the form itself form = success_result_page.forms[0]