Skip to content

Commit

Permalink
Merge pull request #585 from coderbydesign/use-queryset-in-permission…
Browse files Browse the repository at this point in the history
…-filter

Use queryset in permission filter for `allowed_only`
  • Loading branch information
coderbydesign authored Dec 9, 2021
2 parents c16ba45 + 99e988a commit fd8e0e5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rbac/management/permission/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def allowed_only_filter(self, queryset, field, value):
"""Filter to return only permissions from roles in the ROLE_CREATE_ALLOW_LIST."""
query_field = validate_and_get_key(self.request.query_params, field, VALID_BOOLEAN_PARAM_VALS, "false")
if query_field == "true":
queryset = Permission.objects.filter(application__in=settings.ROLE_CREATE_ALLOW_LIST)
queryset = queryset.filter(application__in=settings.ROLE_CREATE_ALLOW_LIST)
return queryset

application = filters.CharFilter(field_name="application", method="multiple_values_in")
Expand Down
6 changes: 6 additions & 0 deletions tests/management/permission/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,12 @@ def test_allowed_only_filters_any_roles_not_in_allow_list_out_when_true(self):
self.assertEqual(len(response.data.get("data")), 1)
self.assertCountEqual(expected, response_permissions)

def test_allowed_only_filters_any_roles_not_in_allow_list_out_when_true_in_chain(self):
"""Test that we filter out any permissions not in the allow list when allowed_only=true, chained with other filters."""
response = CLIENT.get(f"{LIST_URL}?allowed_only=true&exclude_globals=true", **self.headers)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.data.get("data")), 0)

def test_allowed_only_filters_no_permissions_out_when_false(self):
"""Test that we do not filter out any permissions not in the allow list when allowed_only=false."""
with tenant_context(self.tenant):
Expand Down

0 comments on commit fd8e0e5

Please sign in to comment.