Skip to content

Commit

Permalink
Merge pull request RedHatInsights#1157 from petracihalova/order-by-pa…
Browse files Browse the repository at this point in the history
…ram-validation

set the default value for the 'order_by' query param via 'get()' method
  • Loading branch information
petracihalova authored Aug 5, 2024
2 parents 7e2f451 + fff40b1 commit 3e090cf
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions rbac/management/group/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
ROLES_KEY = "roles"
EXCLUDE_KEY = "exclude"
ORDERING_PARAM = "order_by"
NAME_KEY = "name"
PRINCIPAL_TYPE_KEY = "principal_type"
PRINCIPAL_USERNAME_KEY = "principal_username"
VALID_ROLE_ORDER_FIELDS = list(RoleViewSet.ordering_fields)
Expand Down Expand Up @@ -1066,10 +1067,8 @@ def obtain_roles(self, request, group):
roles = group.roles_with_access() if exclude == "false" else self.obtain_roles_with_exclusion(request, group)
filtered_roles = self.filtered_roles(roles, request)
annotated_roles = filtered_roles.annotate(policyCount=Count("policies", distinct=True))
# add default order by name
order_field = "name"
if ORDERING_PARAM in request.query_params:
order_field = request.query_params.get(ORDERING_PARAM)

order_field = request.query_params.get(ORDERING_PARAM, NAME_KEY)
ordered_roles = self.order_queryset(annotated_roles, VALID_ROLE_ORDER_FIELDS, order_field)
return [RoleMinimumSerializer(role).data for role in ordered_roles]

Expand Down

0 comments on commit 3e090cf

Please sign in to comment.