AbilityBuilder class
Collects rules in the order they are written, then builds an ability.
final builder = AbilityBuilder()
..can('read', 'Article')
..can(['update', 'delete'], 'Article', conditions: {'authorId': userId})
..cannot('delete', 'Article', conditions: {'published': true})
.because('a published article cannot be deleted');
final ability = builder.build();
Order is meaning. Rules are checked last-first, so each line overrides the ones above it. Write the broad grant first and narrow it afterwards, the way the example above does — that is the shape that reads correctly.
Constructors
- AbilityBuilder()
- Starts an empty builder.
Properties
Methods
-
build<
T extends Ability> ({T create(List< RawRule> rules)?}) → T - Builds an ability over everything collected.
-
can(
Object action, [Object? subject, Map< String, Object?> ? conditions, Object? fields]) → RuleRef -
Permits
actiononsubject. -
cannot(
Object action, [Object? subject, Map< String, Object?> ? conditions, Object? fields]) → RuleRef -
Forbids
actiononsubject. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited