Skip to content

Commit

Permalink
move the queryset pagination after principals check in BOP - to calcu…
Browse files Browse the repository at this point in the history
…late the count properly
  • Loading branch information
petracihalova committed Feb 29, 2024
1 parent d003267 commit 878979d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
14 changes: 5 additions & 9 deletions rbac/management/group/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
from management.principal.it_service import ITService
from management.principal.model import Principal
from management.principal.proxy import PrincipalProxy
from management.principal.serializer import PrincipalSerializer, ServiceAccountSerializer
from management.principal.serializer import ServiceAccountSerializer
from management.principal.view import ADMIN_ONLY_KEY, USERNAME_ONLY_KEY, VALID_BOOLEAN_VALUE
from management.querysets import get_group_queryset, get_role_queryset
from management.role.view import RoleViewSet
Expand Down Expand Up @@ -807,25 +807,21 @@ def principals(self, request: Request, uuid: Optional[UUID] = None):
return self.get_paginated_response(serializer.data)

principals_from_params = self.filtered_principals(group, request)
page = self.paginate_queryset(principals_from_params)
serializer = PrincipalSerializer(page, many=True)
principal_data = serializer.data
if principal_data:
username_list = [principal["username"] for principal in principal_data]
else:
username_list = []
proxy = PrincipalProxy()
username_list = [principal.username for principal in principals_from_params]

admin_only = validate_and_get_key(request.query_params, ADMIN_ONLY_KEY, VALID_BOOLEAN_VALUE, False, False)
if admin_only == "true":
options[ADMIN_ONLY_KEY] = True

proxy = PrincipalProxy()
if settings.AUTHENTICATE_WITH_ORG_ID:
resp = proxy.request_filtered_principals(username_list, org_id=org_id, options=options)
else:
resp = proxy.request_filtered_principals(username_list, account=account, options=options)
if isinstance(resp, dict) and "errors" in resp:
return Response(status=resp.get("status_code"), data=resp.get("errors"))

self.paginate_queryset(resp.get("data"))
response = self.get_paginated_response(resp.get("data"))
else:
self.protect_system_groups("remove principals")
Expand Down
11 changes: 10 additions & 1 deletion tests/internal/integration/test_integration_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,16 @@ def test_roles_from_group_invalid_account(self):
"username": "user_a",
"account_number": "1111111",
"is_active": True,
}
},
{
"org_id": "100001",
"is_org_admin": False,
"is_internal": False,
"id": 52567474,
"username": "user_admin",
"account_number": "1111111",
"is_active": True,
},
],
},
)
Expand Down

0 comments on commit 878979d

Please sign in to comment.