crooked-father-49084
07/04/2024, 10:52 PMcrooked-father-49084
07/04/2024, 10:58 PMcan_manage_accounts
in conjunction with a second attribute like customer_id
which binds that permission to a specific scope of accounts. In the policy for determining whether someone can manage an account, one of the clauses will ask if the resource they're trying to manage intersects on customer_id AND whether that can_manage_accounts attribute is true. Transitioning these kind of boolean attributes that are specifically referenced in policies are what I'm interested in guidance/thoughts on.
I could capture these as relations on a user (the customer id part here would be captured in a different relation on another namespace like an account):
class User implements Namespace {
related: {
can_manage_accounts: User[]
}
permits = {
hasAccess: (ctx: Context): boolean =>
this.related.can_manage_accounts.includes(ctx.subject)
}
}
But this seems intuitively wrong to me using self-references this way?
Another option is to define roles and relations to them, but then they need specific names and I'm not sure whether I can even do this:
class User implements Namespace {
related: {
roles: Role[]
}
permits = {
hasAccess: (ctx: Context): boolean =>
this.related.roles.some(role => role.name === 'can_manage_account')
}
}
class Role implements Namespace {
related: {
users: User[]
}
name: string
}
This seems cleaner at first thought. But I don't know if I can use properties like "name" like this (chatgpt suggested this approach so...) or how I would be specific about particular "can_manage_accounts" role in the policy.
I left the "customer_id" stuff out of here because that is strictly relational and translates very easily to Keto, not many questions about how to achieve that on my end - it is well covered by the existing docs.crooked-father-49084
07/04/2024, 11:06 PMalert-advantage-94977
07/08/2024, 2:53 AMcrooked-father-49084
07/09/2024, 8:39 PMcrooked-father-49084
07/09/2024, 8:44 PMalert-advantage-94977
12/31/2024, 6:31 AM