-
-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conditional rules & forbidden reasons #45
Comments
It’s much easier to implement The pros of first one:
Cons:
The pros of 2nd:
Cons:
|
After thinking a bit it becomes clear that combination of rules using So, the only benefit is that conditions will be evaluated lazily. This is better for performance but introduces few challenges: async |
From one point of view, lazy evaluation looks cool but that also means, each time you call In that case I don’t see the reason why should we complicate things. The That means |
Requirements:
|
Now, it's possible to specify reason of why rule was added Relates to #45
relevantRuleFor(action, subject, field)
reason
field to rulesreason
topack/unpackRules
functionsthrowUnlessCan
should now throw exception with message of failed rule and use default in other casesbecause
toRuleBuilder
Sometimes you may want to define rules with possibility to specify when they should be applied and return more clear error message when
ability.can
fails. To do that we need to introduce a concept of conditional rule (rule with dynamicinverted
property).Lets consider example:
This example returns
false
butAbility
doesn't know why (it just doesn't have defined rules) because it relates to business logic. But for the end user we would like to return something likeYou don't have a valid subscription
orYou exceeded your limits
. To do so, ability explicitly should know why and what is going on.To help ability to understand we could extend
AbilityBuilder
interface in 2 ways:cannot
rulescan
rules:So, need to decided on the best approach which can be used here, receive feedback and implement this functionality
The text was updated successfully, but these errors were encountered: