<@U04UQ68083H> Give me some guidelines to write re...
# ory-copilot
w
@chilly-king-10285 Give me some guidelines to write relationships.json
c
A message from kapa.ai
To create a
relationships.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:
Copy code
[   {     "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:
Copy code
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).
w
@chilly-king-10285 write relationships.json with the following namespace, where user1 has read access and user 2 has both read and write.
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),
}
}
c
A message from kapa.ai
To create a
relationships.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:
Copy code
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:
Copy code
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).
w
Create example relationships.json based on the following namespace: import { 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 Create example relationships.json based on the following namespace:
Copy code
import { 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),
  }
}
c
A message from kapa.ai
To create a
relationships.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:
Copy code
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:
Copy code
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).