<@U04UQ68083H> In OPL can I define a permission th...
# ory-copilot
l
@chilly-king-10285 In OPL can I define a permission that is granted if there are no relations of a given type on an object.
c
A message from kapa.ai
Based on the provided knowledge sources, Ory Permission Language (OPL) allows you to define permissions based on the relationships an object has with other objects. However, there is no explicit mention of defining a permission that is granted if there are no relations of a given type on an object. In OPL, permissions are expressed as TypeScript functions that take a context containing the subject and answer permission checks based on the relationships the object has to the subject. The permissions are declared as functions inside the
permits
property of the corresponding class in the OPL. Here is an example of how permissions are defined in OPL:
Copy code
typescript class Document implements Namespace {     related: {       owners: User[]       editors: User[]       viewers: User[]       parents: Folder[]     }        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)),     }   }
In this example, the
view
permission is granted if the subject is included in the
viewers
,
editors
, or
owners
of the document, or if the subject can view the parent folder. However, there is no explicit mention of a way to grant a permission if there are no relations of a given type on an object. You might need to implement custom logic in your TypeScript function to handle this case. For more information, you can refer to the [Ory documentation](https://www.ory.sh/docs/keto/modeling/create-permission-model#define-permissions-in-the-opl).