I seem to be unable to save my permission rules in...
# talk-keto
b
I seem to be unable to save my permission rules in Ory Cloud. I put together these simple rules to test it, and it refuses to save with an error message stating "Could not save OPL config:: Error: Errors during parsing. See editor for details.". When i view the editor, the highlighted error is on line 28 of my input stating
expected ")", got "||"
. This error is incorrect, the typescript is properly formatted and there is no syntax error. So, I'm confused why this is happening. My input:
Copy code
import { Namespace, Context } from "@ory/permission-namespace-types"

class Organization implements Namespace {
  related: {
    member: Member[]
    manager: Member[]
  }

  permits = {
    view: (ctx: Context): boolean =>
      this.related.manager.includes(ctx.subject) ||
      this.related.member.includes(ctx.subject),
    edit: (ctx: Context): boolean =>
      this.related.manager.includes(ctx.subject),
  }
}

class Member implements Namespace {
  related: {
    manager: Member[]
    organization: Organization[]
  }

  permits = {
    view: (ctx: Context): boolean =>
      this.related.organization.traverse(
        (o) =>
          o.related.manager.includes(ctx.subject) ||
          o.related.member.includes(ctx.subject)
      ),
    edit: (ctx: Context): boolean =>
      this.related.manager.includes(ctx.subject) ||
      this.related.organization.traverse(
        (o) => o.related.manager.includes(ctx.subject)
      ),
    deactivate: (ctx: Context): boolean =>
      this.related.organization.traverse(
        (o) => o.related.manager.includes(ctx.subject)
      ),
  }
}
s
I see, we do not yet have support in the parser for what you wrote.
Quick workaround: make it
this.related.organization.traverse((o) => o.related.manager.includes(ctx.subject)) || this.related.organization.traverse((o) => o.related.member.includes(ctx.subject)),
b
Do i understand correctly then that this is not actually parsing the input as Typescript code?..
s
it is parsing typescript, but never executing typescript
which would be a nightmare tbh 😅
b
Okay, good to know 👍 I'd highly recommend putting that somewhere in the documentation, or perhaps documenting what the execution is and is not capable of so that others don't waste the 6 hours I wasted on trying to get this working 😓
s
sorry to hear that... we hoped that the editor errors would be enough, but good point in general
@wonderful-lamp-2357
If you can make sense of bad documentation effectively, you're already better than 90% of engineers.
😅
b
lol, strangely relevant 😆
s
haha yeahh, thats what I thought as well 😂