Checking Multiple Subjects or Actions in a Single casl-react Can Check #921
-
Is it possible to check for any one of many abilities in a single For example, it seems like it'd be useful to hide a list entirely if every item in that list cannot be performed by the current ability: <Can I="edit" a={["User", "Post"]}>
<ul>
<Can I="edit" a="User">
<li><a href="users/edit">Edit Users</a></li>
</Can>
<Can I="edit" a="Post">
<li><a href="posts/edit">Edit Posts</a></li>
</Can>
</ul>
</Can> |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Can you use use Your expectations is that This feature was requested many times and once I even tried to work on it but as far as I remember it quickly caused headache :) |
Beta Was this translation helpful? Give feedback.
Can you use use
useAbility
hook instead? if so, then you can just doability.can('edit', 'User') || ability.can('edit', 'Post')
Your expectations is that
ability.can('edit', ['User', 'Post')
should return true if at least one subject type can be edited but somebody else may expect that both should be editable. This complicates types definitions. Then somebody else will request feature likecan(['edit', 'create'], ['Post', 'User'])
afterwardscan(['edit', 'create'], ['Post', 'User'], ['status', 'author'])
This feature was requested many times and once I even tried to work on it but as far as I remember it quickly caused headache :)