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

dan/per-10273-add-multiple-tenant-filter-support-for-list-role-assignments #96

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions permit/api/role_assignments.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ def __role_assignments(self) -> SimpleHttpClient:
@validate_arguments
async def list(
self,
user_key: Optional[str] = None,
user_key: Optional[Union[str, List[str]]] = None,
role_key: Optional[Union[str, List[str]]] = None,
tenant_key: Optional[str] = None,
tenant_key: Optional[Union[str, List[str]]] = None,
resource_key: Optional[str] = None,
resource_instance_key: Optional[str] = None,
page: int = 1,
per_page: int = 100,
Expand All @@ -57,6 +58,7 @@ async def list(
user_key: if specified, only role granted to this user will be fetched.
role_key: if specified, only assignments of this role will be fetched.
tenant_key: (for roles) if specified, only role granted within this tenant will be fetched.
resource_key: (for resource roles) if specified, only roles granted on instances of this resource type will be fetched.
resource_instance_key: (for resource roles) if specified, only roles granted with this instance as the object will be fetched.
page: The page number to fetch (default: 1).
per_page: How many items to fetch per page (default: 100).
Expand All @@ -70,15 +72,25 @@ async def list(
"""
params = list(pagination_params(page, per_page).items())
if user_key is not None:
params.append(("user", user_key))
if isinstance(user_key, list):
for user in user_key:
params.append(("user", user))
else:
params.append(("user", user_key))
if role_key is not None:
if isinstance(role_key, list):
for role in role_key:
params.append(("role", role))
else:
params.append(("role", role_key))
if tenant_key is not None:
params.append(("tenant", tenant_key))
if isinstance(tenant_key, list):
for tenant in tenant_key:
params.append(("tenant", tenant))
else:
params.append(("tenant", tenant_key))
if resource_key is not None:
params.append(("resource", resource_key))
if resource_instance_key is not None:
params.append(("resource_instance", resource_instance_key))
return await self.__role_assignments.get(
Expand Down
Loading