Processes can rules only if no empty conditions rules are present
1) remove all empty conditions hashes from the rules, they are included in the records through `@model_class.all` 2) only process can rules if the new and old rules lists are the same length (meaning there were no empty conditions hashes) 3) always process cannot rules
This commit is contained in:
parent
ad62d60b20
commit
0882450232
|
@ -28,13 +28,17 @@ module CanCan
|
||||||
elsif @rules.size == 1 && @rules[0].conditions.is_a?(Mongoid::Criteria)
|
elsif @rules.size == 1 && @rules[0].conditions.is_a?(Mongoid::Criteria)
|
||||||
@rules[0].conditions
|
@rules[0].conditions
|
||||||
else
|
else
|
||||||
@rules.inject(@model_class.all) do |records, rule|
|
# we only need to process can rules if
|
||||||
if rule.conditions.empty?
|
# there are no rules with empty conditions
|
||||||
records.or(:_id => {'$exists' => true}) # match everything in Mongoid
|
rules = @rules.reject { |rule| rule.conditions.empty? }
|
||||||
elsif rule.base_behavior
|
process_can_rules = @rules.count == rules.count
|
||||||
records.or(rule.conditions)
|
rules.inject(@model_class.all) do |records, rule|
|
||||||
|
if process_can_rules && rule.base_behavior
|
||||||
|
records.or rule.conditions
|
||||||
|
elsif !rule.base_behavior
|
||||||
|
records.excludes rule.conditions
|
||||||
else
|
else
|
||||||
records.excludes(rule.conditions)
|
records
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user