<@U04UQ68083H> Can we put if conditions in OPL?
# ory-copilot
h
@chilly-king-10285 Can we put if conditions in OPL?
c
A message from kapa.ai
The Ory Permission Language (OPL) is a subset of TypeScript, which is a statically typed superset of JavaScript. In JavaScript and TypeScript, you can use if conditions. However, the examples provided in the knowledge sources do not show the use of if conditions in OPL. Instead, they use logical operators like
||
(OR) to combine different conditions. 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 a viewer, editor, or owner of the document, or if the subject can view the parent folder. Each condition is checked using the
includes
method, and the results are combined using the
||
operator. For more complex conditions, you might be able to use if conditions in your OPL code, but this is not shown in the provided examples. For more information, you may want to refer to the [Ory documentation](https://www.ory.sh/docs/keto/modeling/create-permission-model#define-permissions-in-the-opl).