Skip to content

Commit

Permalink
add docs for filters to get user permissions (#472)
Browse files Browse the repository at this point in the history
* document user permissions filters

* fix indentation issue
  • Loading branch information
omer9564 authored Dec 31, 2024
1 parent c148313 commit a70ef4e
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions docs/how-to/enforce-permissions/user-permissions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,53 @@ UserPermissions permissions = permit.getUserPermissionsFromOPA(
</TabItem>
</Tabs>

## Filtering out the results

You can filter the results by any one of the following:
- tenants - returns only the permissions for instances or globally for the specified tenants
- resource_types - returns only the permissions for instances of the specified resource types
- To get only top level accesses, please use the `__tenant` resource type
- resources - returns only the permissions for the specified resource instances, format should be `resource_type:resource_key`

<Tabs groupId="language">
<TabItem value="nodejs" label="Node.js">

```js
const { Permit } = require("permitio");

const permit = new Permit({token: "<YOUR_API_KEY>", ...});
const userPermissions = await permit.getUserPermissions(
"john@doe.com",
["tenant-1", "tenant-2"], // tenants
["document:doc-1", "document:doc-2"] // resources
["document", "__tenant"], // resource_types
);
```

</TabItem>
<TabItem value="java" label="Java">

```java
import io.permit.sdk.Permit;
import io.permit.sdk.PermitConfig;
import io.permit.sdk.enforcement.*;
import java.util.Arrays;


Permit permit = new Permit(
new PermitConfig.Builder("[YOUR_API_KEY]").build()
);

UserPermissions permissions = permit.getUserPermissions(
new GetUserPermissionsQuery(
User.fromString("john@doe.com"),
Arrays.asList("tenant-1", "tenant-2"), // tenants
Arrays.asList("document", "__tenant") // resource_types
Arrays.asList("document:doc-1", "document:doc-2"), // resources
)
);

```

</TabItem>
</Tabs>

0 comments on commit a70ef4e

Please sign in to comment.