wide-machine-60917
04/27/2023, 2:12 PMchilly-king-10285
04/27/2023, 2:12 PMchilly-king-10285
04/27/2023, 2:14 PMrelationships.json file for your Ory Network project, you'll need to define relationships between objects and subjects. Here's an example of how to structure the file: 1. Define a group with members and a folder hierarchy. 2. Set rules in the Ory Permission Language to allow members of the group to access files in the hierarchy. 3. Create additional fine-grained permission rules for certain objects, if needed. Here's an example of a relationships.json file: [ { "namespace": "Group", "object": "developer", "relation": "members", "subject": "User:Patrik" }, { "namespace": "Group", "object": "developer", "relation": "members", "subject": "User:Henning" }, { "namespace": "Folder", "object": "keto/", "relation": "viewers", "subject": "Group:developer#members" }, { "namespace": "File", "object": "keto/README.md", "relation": "parents", "subject": "Folder:keto/" }, { "namespace": "Folder", "object": "keto/src/", "relation": "parents", "subject": "Folder:keto/" }, { "namespace": "File", "object": "keto/src/main.go", "relation": "parents", "subject": "Folder:keto/src/" }, { "namespace": "File", "object": "private", "relation": "owners", "subject": "User:Henning" } ] Save this file as relationships.json in your current working directory. To create these relationships in Ory Permissions, run the following command: ory create relationships relationships.json For more information on relationships, refer to the [Ory documentation on relationships](https://www.ory.sh/docs/guides/permissions/overview).wide-machine-60917
04/27/2023, 2:15 PMclass User implements Namespace {}
class LegalEntity implements Namespace {
related: {
readers: User[]
writers: User[]
}
permits = {
read: (ctx: Context): boolean =>
this.related.readers.includes(ctx.subject) ||
this.related.writers.includes(ctx.subject),
write: (ctx: Context): boolean => this.related.writers.includes(ctx.subject),
}
}chilly-king-10285
04/27/2023, 2:15 PMchilly-king-10285
04/27/2023, 2:16 PMrelationships.json file with the given namespace, you'll need to define relationships between the LegalEntity objects and the User subjects. Here's an example of how to structure the file: json [ { "namespace": "User", "object": "user1", "relation": "readers", "subject": "LegalEntity:entity1" }, { "namespace": "User", "object": "user2", "relation": "readers", "subject": "LegalEntity:entity1" }, { "namespace": "User", "object": "user2", "relation": "writers", "subject": "LegalEntity:entity1" } ] In this example, user1 has read access to LegalEntity:entity1, and user2 has both read and write access to LegalEntity:entity1. Save this file as relationships.json in your current working directory. To create these relationships in Ory Permissions, run the following command: ory create relationships relationships.json For more information on relationships, refer to the [Ory documentation on relationships](https://www.ory.sh/docs/guides/permissions/overview).wide-machine-60917
04/27/2023, 2:31 PMwide-machine-60917
04/27/2023, 2:40 PMimport { Namespace, Context } from "@ory/permission-namespace-types"
class User implements Namespace {}
class LegalEntity implements Namespace {
related: {
readers: User[]
writers: User[]
}
permits = {
read: (ctx: Context): boolean =>
this.related.readers.includes(ctx.subject) ||
this.related.writers.includes(ctx.subject),
write: (ctx: Context): boolean => this.related.writers.includes(ctx.subject),
}
}chilly-king-10285
04/27/2023, 2:40 PMchilly-king-10285
04/27/2023, 2:41 PMrelationships.json file with the given namespace, you'll need to define relationships between the LegalEntity objects and the User subjects. Here's an example of how to structure the file: json [ { "namespace": "LegalEntity", "object": "entity1", "relation": "readers", "subject": "User:user1" }, { "namespace": "LegalEntity", "object": "entity1", "relation": "readers", "subject": "User:user2" }, { "namespace": "LegalEntity", "object": "entity1", "relation": "writers", "subject": "User:user2" } ] In this example, user1 has read access to LegalEntity:entity1, and user2 has both read and write access to LegalEntity:entity1. Save this file as relationships.json in your current working directory. To create these relationships in Ory Permissions, run the following command: ory create relationships relationships.json For more information on relationships, refer to the [Ory documentation on relationships](https://www.ory.sh/docs/guides/permissions/overview).