Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RHCLOUD-30751 Principal links endpoint update #1440

16 changes: 12 additions & 4 deletions rbac/management/principal/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,26 @@ def get(self, request):
count = len(data)
else:
count = None

last_link_offset = int(count) - int(limit) if (int(count) - int(limit)) >= 0 else 0
next_offset = offset + limit
response_data["meta"] = {"count": count, "limit": limit, "offset": offset}
response_data["links"] = {
"first": f"{path}?limit={limit}&offset=0{usernames_filter}",
"next": f"{path}?limit={limit}&offset={offset + limit}{usernames_filter}",
"previous": f"{path}?limit={limit}&offset={previous_offset}{usernames_filter}",
"last": None,
"next": (
f"{path}?limit={limit}&offset={next_offset}{usernames_filter}"
if int(next_offset) < int(count)
else None
),
"previous": (
f"{path}?limit={limit}&offset={previous_offset}{usernames_filter}" if offset - limit >= 0 else None
),
"last": f"{path}?limit={limit}&offset={last_link_offset}{usernames_filter}",
}
response_data["data"] = data
else:
response_data = resp
del response_data["status_code"]

return Response(status=status_code, data=response_data)

def users_from_proxy(self, user, query_params, options, limit, offset):
Expand Down