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

add missing relationship tuple filters to the rel tuples api #102

Merged
Merged
Show file tree
Hide file tree
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: 19 additions & 1 deletion permit/api/relationship_tuples.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,21 @@ def __relationship_tuples(self) -> SimpleHttpClient:
@validate_arguments
async def list(
self,
subject_key: Optional[str] = None,
relation_key: Optional[str] = None,
object_key: Optional[str] = None,
tenant_key: Optional[str] = None,
asafc marked this conversation as resolved.
Show resolved Hide resolved
Comment on lines +47 to +50
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put those variables last, if someone uses this function like this : permit.api.relationship_tuples.list(2,100) than your changes will break it.

page: int = 1,
per_page: int = 100,
) -> List[RelationshipTupleRead]:
"""
Retrieves a list of relationship tuples based on the specified filters.

Args:
subject_key: if specified, only relationship tuples with this subject will be fetched.
relation_key: if specified, only relationship tuples with this relation will be fetched.
object_key: if specified, only relationship tuples with this object will be fetched.
tenant_key: if specified, only relationship tuples with this tenant will be fetched.
page: The page number to fetch (default: 1).
per_page: How many items to fetch per page (default: 100).

Expand All @@ -61,7 +69,17 @@ async def list(
PermitApiError: If the API returns an error HTTP status code.
PermitContextError: If the configured ApiContext does not match the required endpoint context.
"""
params = pagination_params(page, per_page)
params = list(pagination_params(page, per_page).items())

if subject_key is not None:
params.append(("subject", subject_key))
if relation_key is not None:
params.append(("relation", relation_key))
if object_key is not None:
params.append(("object", object_key))
if tenant_key is not None:
params.append(("tenant", tenant_key))

return await self.__relationship_tuples.get(
"",
model=List[RelationshipTupleRead],
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_readme() -> str:

setup(
name="permit",
version="2.6.0",
version="2.6.1",
packages=find_packages(),
author="Asaf Cohen",
author_email="asaf@permit.io",
Expand Down
Loading