diff --git a/src/registrar/admin.py b/src/registrar/admin.py index 91bf58512..af2cb3104 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -555,13 +555,10 @@ class DomainApplicationAdmin(ListHeaderAdmin): parameter_name = "investigator" def lookups(self, request, model_admin): - """Lookup reimplementation, gets users by the MANAGER role. + """Lookup reimplementation, gets users of is_staff. Returns a list of tuples consisting of (user.id, user) """ - valid_user_ids = UserDomainRole.objects.filter(role=UserDomainRole.Roles.MANAGER).values_list( - "user__id", flat=True - ) - privileged_users = User.objects.filter(id__in=valid_user_ids) + privileged_users = User.objects.filter(is_staff=True) return [(user.id, user) for user in privileged_users] def queryset(self, request, queryset): @@ -663,6 +660,7 @@ class DomainApplicationAdmin(ListHeaderAdmin): return super().formfield_for_manytomany(db_field, request, **kwargs) def get_queryset(self, request): + """Queryset reimplementation to order the table alphabetically""" query_set = super().get_queryset(request) return query_set.order_by("requested_domain__name") diff --git a/src/registrar/tests/test_admin.py b/src/registrar/tests/test_admin.py index a9181f97e..a3969d386 100644 --- a/src/registrar/tests/test_admin.py +++ b/src/registrar/tests/test_admin.py @@ -848,6 +848,7 @@ class TestDomainApplicationAdmin(MockEppLib): request = self.factory.get("/") request.user = self.superuser + # Grab the current list of table filters readonly_fields = self.admin.get_list_filter(request) expected_fields = ("status", "organization_type", DomainApplicationAdmin.InvestigatorFilter) @@ -859,13 +860,37 @@ class TestDomainApplicationAdmin(MockEppLib): self.client.login(username="staffuser", password=p) response = self.client.get( "/admin/registrar/domainapplication/", - {}, - follow=True, ) + + # Create a mock DomainApplication object, with a fake investigator + application: DomainApplication = generic_domain_object("application", "SomeGuy") + # Add the role manager to the investigator + UserDomainRole.objects.get_or_create( + user=application.investigator, + role=UserDomainRole.Roles.MANAGER, + domain=Domain.objects.create(name="SomeGuy.gov") + ) + + # First, make sure that there is still an investigator field to begin with expected_sort_column = "sortable column-investigator" self.assertContains(response, expected_sort_column, count=1) + # Then, test if the filter actually exists + self.assertIn("filters", response.context) + # Assert the content of filters and search_query + filters = response.context["filters"] + self.assertEqual( + filters, + [ + {"parameter_name": "status", "parameter_value": "started"}, + { + "parameter_name": "investigator", + "parameter_value": "test", + }, + ], + ) + def test_investigator_filter(self): """Tests the custom investigator filter""" # Creates multiple domain applications