Skip to content

Commit

Permalink
Merge pull request #1776 from BLSQ/IA-3389-fix-filter-for-user
Browse files Browse the repository at this point in the history
IA-3652: Use `filter_for_user` for everybody
  • Loading branch information
quang-le authored Nov 5, 2024
2 parents f14ba4d + c49cb92 commit 88f0abd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 30 deletions.
11 changes: 3 additions & 8 deletions iaso/api/org_unit_change_request_configurations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,9 @@ class OrgUnitChangeRequestConfigurationViewSet(viewsets.ModelViewSet):

def get_queryset(self):
user = self.request.user
if user.is_superuser:
queryset = OrgUnitChangeRequestConfiguration.objects.all()
else:
queryset = OrgUnitChangeRequestConfiguration.objects.filter_for_user(user)

queryset = (
queryset.select_related("project", "org_unit_type", "created_by", "updated_by")
return (
OrgUnitChangeRequestConfiguration.objects.filter_for_user(user)
.select_related("project", "org_unit_type", "created_by", "updated_by")
.prefetch_related(
"possible_types",
"possible_parent_types",
Expand All @@ -65,7 +61,6 @@ def get_queryset(self):
)
.order_by("id")
)
return queryset

def get_permissions(self):
if self.action in ["list", "retrieve"]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,28 +100,6 @@ def test_list_with_restricted_queryset(self):
self.assertEqual(1, len(result))
self.assertEqual(new_oucrc.id, result[0]["id"])

def test_list_superadmin(self):
new_project, new_account = self.create_new_project_and_account(project_name="Palworld", account_name="Palworld")
new_user = self.create_user_with_profile(
username="Not Professor Oak",
account=new_account,
permissions=["iaso_org_unit_change_request_configurations"],
is_superuser=True,
)
new_oucrc = m.OrgUnitChangeRequestConfiguration.objects.create(
org_unit_type=self.ou_type_fire_pokemons,
project=new_project,
created_by=new_user,
org_units_editable=False,
)
# There are now 4 OUCRCs and the new_user should see all of them because he's a superuser
self.client.force_authenticate(new_user)
response = self.client.get(self.OUCRC_API_URL)
self.assertJSONResponse(response, status.HTTP_200_OK)
result = response.json()["results"]
self.assertEqual(4, len(result))
self.assertEqual(new_oucrc.id, result[3]["id"])

# *** Testing retrieve GET endpoint ***
def test_retrieve_ok(self):
self.client.force_authenticate(self.user_misty)
Expand Down

0 comments on commit 88f0abd

Please sign in to comment.