great-crayon-86888
11/12/2023, 2:48 PMchilly-king-10285
11/12/2023, 2:48 PMchilly-king-10285
11/12/2023, 2:49 PMtypescript import { Namespace, Context } from "@ory/keto-namespace-types" class Patient implements Namespace { // All relationships for a single patient. related: { doctors: User[] nurses: User[] } // The permissions derived from the relationships and context. permits = { // A permission is a function that takes the context and returns a boolean. It can reference `this.related` and `this.permits`. viewSSN: (ctx: Context): boolean => this.related.doctors.includes(ctx.subject), viewPHI: (ctx: Context): boolean => this.permits.viewSSN(ctx) || this.related.nurses.includes(ctx.subject), } }
In this example, the viewSSN
permission allows doctors to view the SSN of a patient, and the viewPHI
permission allows doctors and nurses to view the Protected Health Information (PHI) of a patient. You can create these permission rules using the Ory Console. Go to the Ory Console → Namespaces & Rules and use the editor in the Permission Rules tab. Please note that this is a simplified example and you might need to adjust it to fit the specific needs of your application. For more information on how to use OPL, you can refer to the [Ory Permission Language specification](https://www.ory.sh/docs/keto/reference/ory-permission-language) and the [Ory Keto guides](https://www.ory.sh/docs/keto/guides/simple-access-check-guide).great-crayon-86888
11/12/2023, 3:06 PMchilly-king-10285
11/12/2023, 3:06 PMchilly-king-10285
11/12/2023, 3:06 PMPatient
and PHI
objects: typescript import { Namespace, Context } from "@ory/keto-namespace-types" class User implements Namespace {} class Patient implements Namespace { related: { doctors: User[] nurses: User[] phi: PHI[] } } class PHI implements Namespace { related: { owners: Patient[] } permits = { view: (ctx: Context): boolean => this.related.owners.includes(ctx.subject), } }
In this example, the Patient
object has relationships with User
objects (doctors and nurses) and PHI
objects. The PHI
object has a relationship with the Patient
object and a view
permission that allows the owners (patients) to view their own PHI. You can create these permission rules using the Ory Console. Go to the Ory Console → Namespaces & Rules and use the editor in the Permission Rules tab. Please note that this is a simplified example and you might need to adjust it to fit the specific needs of your application. For more information on how to use OPL, you can refer to the [Ory Permission Language specification](https://www.ory.sh/docs/keto/reference/ory-permission-language) and the [Ory Keto guides](https://www.ory.sh/docs/keto/guides/simple-access-check-guide).