-
Hi everyone, I'm exploring CASL as part of a migration from Oso and encountered a challenge regarding relational (or hierarchical) policies. Specifically, I'm looking for a way to express policies where permissions on one subject imply permissions on a related subject. For example, consider this use case:
In Oso, this can be defined like this: However, IIUC, CASL does not natively support relational policies like the following pseudo-code: allow('create', 'Organization', { conditions: { ownerId: user.id } });
allow('create', 'Issue', { conditions: can('create', 'Organization', { ownerId: user.id }) }); Questions
I'd love to hear your thoughts on how best to approach this with CASL or whether this is something that could be added as a feature. Thank you for your input! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
Very often all tenant based application have tenant id over all tenant specific entities. For example, in your case very likely that Issue has relation to organization and basically has If so, then your permissions are translated to this:
pseudocode above to show the idea of how it should be done in casl (user.ownedOrgIds is an array of all owned organizations ids by authenticated user) |
Beta Was this translation helpful? Give feedback.
There is no such thing in casl but you can get it with some restrictions (e.g., you won't be able to translate casl permissions into database query with built-in helpers). To do this, you can switch to lambda based permission definition or define custom
$where
operator.So, the entities:
Lambda version: