Hello, I have the following OPL code, I want to ad...
# talk-keto
r
Hello, I have the following OPL code, I want to add that
Account
has relation
edit
on itself (
account:alice#edit@account:alice
as a tuple), how can I achieve that?
Copy code
class AccessToken implements Namespace {
}

class Account implements Namespace {
  related: {
    token: AccessToken[]
    admin_token: AccessToken[]
  }

  permits = {
    edit: (ctx: Context): boolean =>
      // this == ctx ||
      this.related.admin_token.includes(ctx.subject),

    view: (ctx: Context): boolean =>
        this.permits.edit(ctx) ||
        this.related.token.includes(ctx.subject),
  }
}
s
Interesting one, pretty sure it is not yet supported. I guess the expression would be
ctx.subject === this
FYI @narrow-van-43826
n
Interesting indeed. I would in this case still go relations and have an
editor
(or whatever is semantically correct in your case) relation from
Account
to `Account`:
Copy code
class AccessToken implements Namespace {
}

class Account implements Namespace {
  related: {
    token: AccessToken[]
    admin_token: AccessToken[]
    editor: Account[]
  }

  permits = {
    edit: (ctx: Context): boolean =>
      this.related.editor.includes(ctx.subject) ||
      this.related.admin_token.includes(ctx.subject),

    view: (ctx: Context): boolean =>
        this.permits.edit(ctx) ||
        this.related.token.includes(ctx.subject),
  }
}
This should then consider relations of the type
account:alice#editor@account:alice
. Does this solve your usecase?
s
I just think that this additional relation should not be necessary, as a workaround for now it is a good idea 👍
r
Will do, thank you! Should I open an issue on github for
ctx.subject == this
?
s
that would be awesome 👍
r
If I were to contribute this, what's a good place to start? Like the OPL language parser and where it's checked?
And I think using
this.equals(ctx.subject)
is easier to add to the existing ts definitions.
s
yeah,
this.equals
would also make more sense to allow typescript unit tests at a later stage
n
I added some implementation guidance to the issue should you want to take it up (you'd be welcome to!): https://github.com/ory/keto/issues/1204#issuecomment-1401843929