From 3eea6d03135edf58af24c28d8722ddc5390331f2 Mon Sep 17 00:00:00 2001 From: Dan Yishai Date: Sun, 7 Jul 2024 16:17:34 +0300 Subject: [PATCH 1/2] Added multi tenant / user filter for list role assignments --- permit/api/role_assignments.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/permit/api/role_assignments.py b/permit/api/role_assignments.py index 863c675..2486de1 100644 --- a/permit/api/role_assignments.py +++ b/permit/api/role_assignments.py @@ -43,9 +43,9 @@ 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_instance_key: Optional[str] = None, page: int = 1, per_page: int = 100, @@ -70,7 +70,11 @@ 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: @@ -78,7 +82,11 @@ async def list( 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_instance_key is not None: params.append(("resource_instance", resource_instance_key)) return await self.__role_assignments.get( From a1419ed501bc8c9ab29ce5fd4f6bd52b7c42b5d5 Mon Sep 17 00:00:00 2001 From: Dan Yishai Date: Sun, 7 Jul 2024 16:18:40 +0300 Subject: [PATCH 2/2] Added resource filter for list role assignments --- permit/api/role_assignments.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/permit/api/role_assignments.py b/permit/api/role_assignments.py index 2486de1..d895d8c 100644 --- a/permit/api/role_assignments.py +++ b/permit/api/role_assignments.py @@ -46,6 +46,7 @@ async def list( user_key: Optional[Union[str, List[str]]] = None, role_key: Optional[Union[str, List[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, @@ -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). @@ -87,6 +89,8 @@ async def list( 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(