MongoAbility is "turned back"(?) to a PureAbility ?/Refuses to take conditions as 3rd argument #984
-
Hello there, First of all, great work on casl, it is an amazing system, wanted to use it for a while but never got the chance. I don't know if I am asking in the right place, sorry in advance. I am having trouble using the ability created through either AbilityBuilder or createMongoAbility regarding their mongodb queries:
When i use ability with 2 arguments, meaning that i only check action and subject without a condition, the ability works fine when i call it in my components through a custom Hook. However, when i try to use a condition(where there is an else for the But when i try to use it with a 3rd argument in my components to do the actual checking like so( I am not using Can components from
I have the following error thrown in my React component that says:
The link redirects to v5, even though i am using 6.7.1, which leads to the following section: can of PureAbilityChecks that the provided action and subject satisfy permissions. Depending on Abilities generic parameter this function accepts either single action argument (when Abilities is a string) or 3 arguments (when Abilities is a tuple).
I even tried to use the With a few console logs of the built abilites their signature is always PureAbility even though I solely createMongoAbility and MongoAbilty so I don't understand why it fallsback to PureAbility's signature when trying to use the 3rd argument of Am i doing something wrong ? I might have skiped an important part on the docs but can't seem to find it. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Any thoughts on this ? |
Beta Was this translation helpful? Give feedback.
-
Hi, you are in trap of common misconception. Builder method accepts conditions but ability check method accepts action and entity. Based on entity type (this is called subject type in casl), ability understands what to permissions to use. createMongoAbility creates an instance of PureAbility with preconfigured options. So it’s the same result as using The plan is to rename PureAbility to Ability and use functions to preconfigure Ability |
Beta Was this translation helpful? Give feedback.
-
Okay thanks for your suggestions, I had not understood that abilities do not need conditions, etc... after they have been built. I have managed to make it work, although my POJOs are not extensible for some reason , might be transformed in react-redux as i am using it to retrieve my items from store state with useSelector and render these in my components. I have found a way arround it by doing :
|
Beta Was this translation helpful? Give feedback.
Yes, make sure that CASL can detect type of your entities. If your entities are POJO then you have 2 options either enhance its type after fetching from API on service layer (adding additional hidden property) or by using
subject
helper.I guess it should be explained in the guide