From ab9d1af8b12f9000588dd48b36f1ad643c3b2d41 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Thu, 16 May 2024 14:46:45 -0600 Subject: [PATCH 1/4] Add readonly fields --- src/registrar/admin.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/registrar/admin.py b/src/registrar/admin.py index 9905cf340..61f814c91 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -1171,7 +1171,7 @@ class DomainInformationAdmin(ListHeaderAdmin, ImportExportModelAdmin): ] # Readonly fields for analysts and superusers - readonly_fields = ("other_contacts", "generic_org_type", "is_election_board") + readonly_fields = ("other_contacts", "generic_org_type", "is_election_board", "federal_agency") # Read only that we'll leverage for CISA Analysts analyst_readonly_fields = [ @@ -1438,6 +1438,7 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin): "alternative_domains", "generic_org_type", "is_election_board", + "federal_agency", ) # Read only that we'll leverage for CISA Analysts @@ -1879,7 +1880,7 @@ class DomainAdmin(ListHeaderAdmin, ImportExportModelAdmin): search_fields = ["name"] search_help_text = "Search by domain name." change_form_template = "django/admin/domain_change_form.html" - readonly_fields = ["state", "expiration_date", "first_ready", "deleted"] + readonly_fields = ("state", "expiration_date", "first_ready", "deleted", "federal_agency") # Table ordering ordering = ["name"] From 921a804cab5c2dfb643717d29618916ce8c2f88b Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Thu, 16 May 2024 14:54:07 -0600 Subject: [PATCH 2/4] Change user group settings --- .../migrations/0095_create_groups_v13.py | 37 +++++++++++++++++++ src/registrar/models/user_group.py | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/registrar/migrations/0095_create_groups_v13.py diff --git a/src/registrar/migrations/0095_create_groups_v13.py b/src/registrar/migrations/0095_create_groups_v13.py new file mode 100644 index 000000000..dc8cf4a57 --- /dev/null +++ b/src/registrar/migrations/0095_create_groups_v13.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", "0094_create_groups_v12"), + ] + + operations = [ + migrations.RunPython( + create_groups, + reverse_code=migrations.RunPython.noop, + atomic=True, + ), + ] diff --git a/src/registrar/models/user_group.py b/src/registrar/models/user_group.py index 76657fe29..23cc59c69 100644 --- a/src/registrar/models/user_group.py +++ b/src/registrar/models/user_group.py @@ -64,7 +64,7 @@ class UserGroup(Group): { "app_label": "registrar", "model": "federalagency", - "permissions": ["add_federalagency", "change_federalagency", "delete_federalagency"], + "permissions": ["change_federalagency"], }, ] From 401309ac5dfe20f476e68df75dc38f0f3bf59444 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Thu, 16 May 2024 15:15:43 -0600 Subject: [PATCH 3/4] Fix tests --- src/registrar/tests/test_admin.py | 4 ++++ src/registrar/tests/test_migrations.py | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/registrar/tests/test_admin.py b/src/registrar/tests/test_admin.py index 4a6e76e3d..8c771a73b 100644 --- a/src/registrar/tests/test_admin.py +++ b/src/registrar/tests/test_admin.py @@ -2232,6 +2232,7 @@ class TestDomainRequestAdmin(MockEppLib): "alternative_domains", "generic_org_type", "is_election_board", + "federal_agency", "id", "created_at", "updated_at", @@ -2286,6 +2287,7 @@ class TestDomainRequestAdmin(MockEppLib): "alternative_domains", "generic_org_type", "is_election_board", + "federal_agency", "creator", "about_your_organization", "requested_domain", @@ -2314,6 +2316,7 @@ class TestDomainRequestAdmin(MockEppLib): "alternative_domains", "generic_org_type", "is_election_board", + "federal_agency", ] self.assertEqual(readonly_fields, expected_fields) @@ -3172,6 +3175,7 @@ class TestDomainInformationAdmin(TestCase): "other_contacts", "generic_org_type", "is_election_board", + "federal_agency", "creator", "type_of_work", "more_organization_information", diff --git a/src/registrar/tests/test_migrations.py b/src/registrar/tests/test_migrations.py index 6d8ff7151..415644200 100644 --- a/src/registrar/tests/test_migrations.py +++ b/src/registrar/tests/test_migrations.py @@ -37,9 +37,7 @@ class TestGroups(TestCase): "add_domaininvitation", "view_domaininvitation", "change_domainrequest", - "add_federalagency", "change_federalagency", - "delete_federalagency", "analyst_access_permission", "change_user", "delete_userdomainrole", From 784d5728ae939b8a3f01b211f3aeeed80cbfab69 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Thu, 16 May 2024 15:25:10 -0600 Subject: [PATCH 4/4] Remove usergroup change --- .../migrations/0095_create_groups_v13.py | 37 ------------------- src/registrar/models/user_group.py | 2 +- src/registrar/tests/test_migrations.py | 2 + 3 files changed, 3 insertions(+), 38 deletions(-) delete mode 100644 src/registrar/migrations/0095_create_groups_v13.py diff --git a/src/registrar/migrations/0095_create_groups_v13.py b/src/registrar/migrations/0095_create_groups_v13.py deleted file mode 100644 index dc8cf4a57..000000000 --- a/src/registrar/migrations/0095_create_groups_v13.py +++ /dev/null @@ -1,37 +0,0 @@ -# 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", "0094_create_groups_v12"), - ] - - operations = [ - migrations.RunPython( - create_groups, - reverse_code=migrations.RunPython.noop, - atomic=True, - ), - ] diff --git a/src/registrar/models/user_group.py b/src/registrar/models/user_group.py index 23cc59c69..76657fe29 100644 --- a/src/registrar/models/user_group.py +++ b/src/registrar/models/user_group.py @@ -64,7 +64,7 @@ class UserGroup(Group): { "app_label": "registrar", "model": "federalagency", - "permissions": ["change_federalagency"], + "permissions": ["add_federalagency", "change_federalagency", "delete_federalagency"], }, ] diff --git a/src/registrar/tests/test_migrations.py b/src/registrar/tests/test_migrations.py index 415644200..6d8ff7151 100644 --- a/src/registrar/tests/test_migrations.py +++ b/src/registrar/tests/test_migrations.py @@ -37,7 +37,9 @@ class TestGroups(TestCase): "add_domaininvitation", "view_domaininvitation", "change_domainrequest", + "add_federalagency", "change_federalagency", + "delete_federalagency", "analyst_access_permission", "change_user", "delete_userdomainrole",