great-crayon-86888
11/09/2023, 4:53 PMchilly-king-10285
11/09/2023, 4:53 PMchilly-king-10285
11/09/2023, 4:54 PMchilly-king-10285
11/09/2023, 4:54 PMUser
table and a Document
table, you could define them as namespaces like this: typescript class User implements Namespace {} class Document implements Namespace {}
2. Define relationships: In each namespace, you can define relationships to other namespaces. For example, a Document
could have relationships to User
(as owners, editors, viewers) and to Folder
(as parents): typescript class Document implements Namespace { related: { owners: User[] editors: User[] viewers: User[] parents: Folder[] } }
3. Define permissions: In each namespace, you can define permissions as functions that take a context and return a boolean. For example, a Document
could have view
, edit
, delete
, and share
permissions: typescript class Document implements Namespace { permits = { view: (ctx: Context): boolean => this.related.viewers.includes(ctx.subject) || this.related.editors.includes(ctx.subject) || this.related.owners.includes(ctx.subject) || this.related.parents.traverse((parent) => parent.permits.view(ctx)), edit: (ctx: Context): boolean => this.related.editors.includes(ctx.subject) || this.related.owners.includes(ctx.subject) || this.related.parents.traverse((parent) => parent.permits.edit(ctx)), delete: (ctx: Context): boolean => this.related.owners.includes(ctx.subject) || this.related.parents.traverse((parent) => parent.permits.delete(ctx)), share: (ctx: Context): boolean => this.related.owners.includes(ctx.subject) || this.related.parents.traverse((parent) => parent.permits.share(ctx)), } }
This way, you can encapsulate your permissions around your data model. For more details, you can refer to the [Ory documentation](https://www.ory.sh/docs/keto/modeling/create-permission-model). Please note that this is a simplified example and you might need to adjust it to fit your specific needs.chilly-king-10285
11/09/2023, 4:55 PMgreat-crayon-86888
11/09/2023, 5:32 PMchilly-king-10285
11/09/2023, 5:32 PMchilly-king-10285
11/09/2023, 5:32 PMUser
, Role
, and Appointment
table, you could define them as namespaces like this: typescript class User implements Namespace {} class Role implements Namespace {} class Appointment implements Namespace {}
2. Define relationships: In each namespace, you can define relationships to other namespaces. For example, a User
could have a relationship to Role
(as members), and Appointment
could have relationships to Role
(as creators, viewers): typescript class User implements Namespace { related: { roles: Role[] } } class Appointment implements Namespace { related: { creators: Role[] viewers: Role[] } }
3. Define permissions: In each namespace, you can define permissions as functions that take a context and return a boolean. For example, an Appointment
could have create
and view
permissions: typescript class Appointment implements Namespace { permits = { create: (ctx: Context): boolean => this.related.creators.includes(ctx.subject), view: (ctx: Context): boolean => this.related.viewers.includes(ctx.subject), } }
This way, you can encapsulate your permissions around your data model. For more details, you can refer to the [Ory documentation](https://www.ory.sh/docs/keto/modeling/create-permission-model). Please note that this is a simplified example and you might need to adjust it to fit your specific needs.