All files / lib/utils hasRestrictingConditions.ts

100% Statements 6/6
100% Branches 4/4
100% Functions 2/2
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10      1x 79x 79x 79x     1x
import { AnyAbility, Abilities } from "@casl/ability";
import { Rule } from "@casl/ability/dist/types/Rule";
 
const hasRestrictingConditions = (ability: AnyAbility, action: string, modelName: string): Rule<Abilities, unknown>[]|false => {
  const rules = ability.possibleRulesFor(action, modelName);
  const hasConditions = rules.length === 0 || rules.some(x => !!x.conditions);
  return (hasConditions) ? rules : false;
};
 
export default hasRestrictingConditions;