I have a flat component permission-wise, I do not really use the "of" -part (or subject) of the
Casl seems to work fine with me leaving it out but the React component gives prop type warnings.
I have worked around this by creating a custom can-component but I'm wondering if the prop-type validation could be loosened or if there is a more elegant way handling cases like:
<Can I="post" />
Tasks:
ForbiddenError.throwUnlessCancan, cannot, relevantRuleFor, rulesFor,possibleRulesForofAbility`can & cannot of AbilityBuildercasl/angularcasl/aureliacasl/vuecasl/reactI thought about this recently. Actually it's a valid use case when app has a simple permission system which is based only on actions.
My thoughts on this:
can with single parameter for AbilityBuilder.can and for Ability.can<Can> components sift.js)CASL is awesome - thank you! Looking forward to this being addressed. Any thoughts on when it will be available?
Currently I鈥檓 pretty busy at my job, so it鈥檚 hard to say. But PRs are welcome :)
Meanwhile you can define permissions using all subject and create a simple wrapper around ability which uses all subject as default value.
After some thinking about this, I realised that on @casl/ability level it can be implemented without changes. The only thing which you need to do is to define custom subjectName function:
const subjectName = () => 'all'
const ability = AbilityBuilder.define({ subjectName }, (can) => {
can('read')
can('think')
})
console.log(ability.can('think')) // true
console.log(ability.can('write')) // false
The only thing which needs to be changed is Typescript declarations and complementary packages
will be available in casl 4.x
Most helpful comment
will be available in casl 4.x