refined-airport-1308
01/23/2023, 7:37 PMAccount
has relation edit
on itself (account:alice#edit@account:alice
as a tuple), how can I achieve that?
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),
}
}
steep-lamp-91158
ctx.subject === this
steep-lamp-91158
narrow-van-43826
01/24/2023, 8:18 AMeditor
(or whatever is semantically correct in your case) relation from Account
to `Account`:
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?steep-lamp-91158
refined-airport-1308
01/24/2023, 10:10 AMctx.subject == this
?steep-lamp-91158
refined-airport-1308
01/24/2023, 11:19 AMrefined-airport-1308
01/24/2023, 11:53 AMrefined-airport-1308
01/24/2023, 11:54 AMthis.equals(ctx.subject)
is easier to add to the existing ts definitions.steep-lamp-91158
this.equals
would also make more sense to allow typescript unit tests at a later stagenarrow-van-43826
01/24/2023, 12:17 PM