You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create possibility to concatenate 2 and more abilities together. Can be useful for cases when user want to define separate ability instances for different purposes (e.g., feature flags checks, hardware checks, user permission checks). The resulting Ability instance is composed of n Ability instances and its can method returns true only if all underlying abilities returns true.
Only Ability with the same options (i.e., subjectName) can be concatenated together, otherwise exception should be thrown
The main issue with the idea is that for some cases we would like to define not all actions or not all subjects.
Lets consider an example with hardware capabilities and user permissions. For example, there are devices which supports wifi and which not. So, we define ability like this:
Now when we do ability.can('read', 'Wifi') all works as expected but if we do ability.can('read', 'User') it will return false because hardware ability doesn't have rules for User (and shouldn't have them).
So, I decline this feature in favor of #45 . With conditional rules it may look like this:
constuserAbility=AbilityBuilder.define(can=>{if(user.is('admin')){can('manage','WiFi').onlyIf(()=>hardware.supportsWiFi,{error: 'This device does not have WiFi card'})can(['read','update'],'User',{id: user.id})}})
Create possibility to concatenate 2 and more abilities together. Can be useful for cases when user want to define separate ability instances for different purposes (e.g., feature flags checks, hardware checks, user permission checks). The resulting
Ability
instance is composed of nAbility
instances and itscan
method returnstrue
only if all underlying abilities returnstrue
.Only
Ability
with the same options (i.e.,subjectName
) can be concatenated together, otherwise exception should be thrownThe text was updated successfully, but these errors were encountered: