|
@@ -202,10 +202,7 @@ def clear_aliased_actions |
|
|
def conditions(action, subject, options = {})
|
|
|
matched = matching_can_definition(action, subject)
|
|
|
unless matched.empty?
|
|
|
- if matched.any?{|can_definition|
|
|
|
- cond = can_definition.conditions
|
|
|
- (cond.nil? || cond.empty?) && can_definition.block
|
|
|
- }
|
|
|
+ if matched.any?{|can_definition| can_definition.conditions_empty? && can_definition.block }
|
|
|
raise Error, "Cannot determine ability conditions from block for #{action.inspect} #{subject.inspect}"
|
|
|
end
|
|
|
matched.map{|can_definition|
|
|
@@ -239,20 +236,19 @@ def sql_conditions(action, subject, options = {}) |
|
|
false_cond = subject.send(:sanitize_sql, ['?=?', true, false])
|
|
|
conds.reverse.inject(nil) do |sql, action|
|
|
|
behavior, condition = action
|
|
|
- if condition && !condition.empty?
|
|
|
+ if condition && condition != {}
|
|
|
condition = "#{subject.send(:sanitize_sql, condition)}"
|
|
|
- condition = "not (#{condition})" if behavior == false
|
|
|
+ case sql
|
|
|
+ when nil then condition
|
|
|
+ when true_cond
|
|
|
+ behavior ? true_cond : "not (#{condition})"
|
|
|
+ when false_cond
|
|
|
+ behavior ? condition : false_cond
|
|
|
+ else
|
|
|
+ behavior ? "(#{condition}) OR (#{sql})" : "not (#{condition}) AND (#{sql})"
|
|
|
+ end
|
|
|
else
|
|
|
- condition = behavior ? true_cond : false_cond
|
|
|
- end
|
|
|
- case sql
|
|
|
- when nil then condition
|
|
|
- when true_cond
|
|
|
- behavior ? true_cond : condition
|
|
|
- when false_cond
|
|
|
- behavior ? condition : false_cond
|
|
|
- else
|
|
|
- behavior ? "(#{condition}) OR (#{sql})" : "#{condition} AND (#{sql})"
|
|
|
+ behavior ? true_cond : false_cond
|
|
|
end
|
|
|
end
|
|
|
end
|
|
@@ -262,7 +258,7 @@ def sql_conditions(action, subject, options = {}) |
|
|
def association_joins(action, subject)
|
|
|
can_definitions = matching_can_definition(action, subject)
|
|
|
unless can_definitions.empty?
|
|
|
- if can_definitions.any?{|can_definition| can_definition.conditions.nil? && can_definition.block }
|
|
|
+ if can_definitions.any?{|can_definition| can_definition.conditions_empty? && can_definition.block }
|
|
|
raise Error, "Cannot determine association joins from block for #{action.inspect} #{subject.inspect}"
|
|
|
end
|
|
|
collect_association_joins(can_definitions)
|
|
@@ -283,7 +279,7 @@ def matching_can_definition(action, subject) |
|
|
can_definition.expand_actions(aliased_actions)
|
|
|
if can_definition.matches? action, subject
|
|
|
yield can_definition
|
|
|
- break if can_definition.conditions.nil? && can_definition.block.nil?
|
|
|
+ break if can_definition.definitive?
|
|
|
end
|
|
|
end
|
|
|
else
|
|
|
0 comments on commit
dbc1538