removing need to pass tableize option around for query conditions
This commit is contained in:
@@ -183,8 +183,8 @@ module CanCan
|
||||
end
|
||||
|
||||
# Returns a CanCan::Query instance to help generate database queries based on the ability.
|
||||
def query(action, subject, options = {})
|
||||
Query.new(relevant_can_definitions_without_block(action, subject), subject, options)
|
||||
def query(action, subject)
|
||||
Query.new(subject, relevant_can_definitions_without_block(action, subject))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -20,7 +20,7 @@ module CanCan
|
||||
# Here only the articles which the user can update are returned. This
|
||||
# internally uses Ability#conditions method, see that for more information.
|
||||
def accessible_by(ability, action = :read)
|
||||
query = ability.query(action, self, :tableize => true)
|
||||
query = ability.query(action, self)
|
||||
conditions = query.sql_conditions || {:id => nil}
|
||||
if respond_to? :where
|
||||
where(conditions).joins(query.association_joins)
|
||||
|
||||
@@ -4,7 +4,6 @@ module CanCan
|
||||
# helpful methods to determine permission checking and conditions hash generation.
|
||||
class CanDefinition # :nodoc:
|
||||
attr_reader :conditions, :block, :base_behavior
|
||||
include ActiveSupport::Inflector
|
||||
attr_reader :block
|
||||
attr_reader :actions
|
||||
attr_writer :expanded_actions
|
||||
@@ -37,17 +36,14 @@ module CanCan
|
||||
end
|
||||
end
|
||||
|
||||
# Returns a hash of conditions. If the ":tableize => true" option is passed
|
||||
# it will pluralize the association conditions to match the table name.
|
||||
def conditions(options = {})
|
||||
if options[:tableize] && @conditions.kind_of?(Hash)
|
||||
# Returns a hash of conditions, pluralizing the table names
|
||||
def tableized_conditions
|
||||
if @conditions
|
||||
@conditions.inject({}) do |tableized_conditions, (name, value)|
|
||||
name = tableize(name).to_sym if value.kind_of? Hash
|
||||
name = name.to_s.tableize.to_sym if value.kind_of? Hash
|
||||
tableized_conditions[name] = value
|
||||
tableized_conditions
|
||||
end
|
||||
else
|
||||
@conditions
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -3,10 +3,9 @@ module CanCan
|
||||
# Generates the sql conditions and association joins for use in ActiveRecord queries.
|
||||
# Normally you will not use this class directly, but instead through ActiveRecordAdditions#accessible_by.
|
||||
class Query
|
||||
def initialize(can_definitions, sanitizer, options)
|
||||
@can_definitions = can_definitions
|
||||
def initialize(sanitizer, can_definitions)
|
||||
@sanitizer = sanitizer
|
||||
@options = options
|
||||
@can_definitions = can_definitions
|
||||
end
|
||||
|
||||
# Returns an array of arrays composing from desired action and hash of conditions which match the given ability.
|
||||
@@ -27,7 +26,7 @@ module CanCan
|
||||
def conditions
|
||||
unless @can_definitions.empty?
|
||||
@can_definitions.map do |can_definition|
|
||||
[can_definition.base_behavior, can_definition.conditions(@options)]
|
||||
[can_definition.base_behavior, can_definition.tableized_conditions]
|
||||
end
|
||||
else
|
||||
false
|
||||
|
||||
Reference in New Issue
Block a user