rulesToAst<A extends String, S extends String> function
Condition?
rulesToAst<A extends String, S extends String>(
- Ability<
A, S> ability, - A action,
- S subjectType
The Condition form of rulesToCondition — the one most callers want.
final where = rulesToAst(ability, 'read', 'Article');
Every rule involved must have parsed conditions, which the built-in Mongo matcher provides. A rule whose matcher cannot produce them throws here rather than being skipped: skipping a forbidding rule would widen the query, and a query that returns records the user may not see is the exact failure this function exists to prevent.
Implementation
Condition? rulesToAst<A extends String, S extends String>(
Ability<A, S> ability,
A action,
S subjectType,
) => rulesToCondition<Condition>(
ability.rulesFor(action, subjectType),
_ruleToCondition,
const QueryLanguage(
and: _and,
or: _or,
not: _not,
unrestricted: _unrestricted,
),
);