summaryrefslogtreecommitdiffstats
path: root/vendor
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2011-04-05 12:55:19 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2011-04-05 12:55:19 +0000
commit2b8d32a30e3d4c8808d50f9ca66ca19a84e9f411 (patch)
tree35fc0d4ca4e75adf9a8f4ad960cd0a63d214b825 /vendor
parent8cf42fabf63277c157793576f8a70176cc65898d (diff)
downloadredmine-2b8d32a30e3d4c8808d50f9ca66ca19a84e9f411.tar.gz
redmine-2b8d32a30e3d4c8808d50f9ca66ca19a84e9f411.zip
Makes search providers use visible scopes.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5327 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'vendor')
-rw-r--r--vendor/plugins/acts_as_searchable/lib/acts_as_searchable.rb28
1 files changed, 18 insertions, 10 deletions
diff --git a/vendor/plugins/acts_as_searchable/lib/acts_as_searchable.rb b/vendor/plugins/acts_as_searchable/lib/acts_as_searchable.rb
index 9106d7bd7..ea29d3a1b 100644
--- a/vendor/plugins/acts_as_searchable/lib/acts_as_searchable.rb
+++ b/vendor/plugins/acts_as_searchable/lib/acts_as_searchable.rb
@@ -1,5 +1,5 @@
-# redMine - project management software
-# Copyright (C) 2006-2007 Jean-Philippe Lang
+# Redmine - project management software
+# Copyright (C) 2006-2011 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -45,9 +45,6 @@ module Redmine
searchable_options[:date_column] ||= "#{table_name}.created_on"
searchable_options[:order_column] ||= searchable_options[:date_column]
- # Permission needed to search this model
- searchable_options[:permission] = "view_#{self.name.underscore.pluralize}".to_sym unless searchable_options.has_key?(:permission)
-
# Should we search custom fields on this model ?
searchable_options[:search_custom_fields] = !reflect_on_association(:custom_values).nil?
@@ -65,6 +62,8 @@ module Redmine
# projects argument can be either nil (will search all projects), a project or an array of projects
# Returns the results and the results count
def search(tokens, projects=nil, options={})
+ # TODO: make user an argument
+ user = User.current
tokens = [] << tokens unless tokens.is_a?(Array)
projects = [] << projects unless projects.nil? || projects.is_a?(Array)
@@ -99,18 +98,27 @@ module Redmine
find_options[:conditions] = [sql, * (tokens.collect {|w| "%#{w.downcase}%"} * token_clauses.size).sort]
+ scope = self
project_conditions = []
- project_conditions << (searchable_options[:permission].nil? ? Project.visible_by(User.current) :
- Project.allowed_to_condition(User.current, searchable_options[:permission]))
+ if searchable_options.has_key?(:permission)
+ project_conditions << Project.allowed_to_condition(user, searchable_options[:permission] || :view_project)
+ elsif respond_to?(:visible)
+ scope = scope.visible(user)
+ else
+ ActiveSupport::Deprecation.warn "acts_as_searchable with implicit :permission option is deprecated. Add a visible scope to the #{self.name} model or use explicit :permission option."
+ project_conditions << Project.allowed_to_condition(user, "view_#{self.name.underscore.pluralize}".to_sym)
+ end
+ # TODO: use visible scope options instead
project_conditions << "#{searchable_options[:project_key]} IN (#{projects.collect(&:id).join(',')})" unless projects.nil?
+ project_conditions = project_conditions.empty? ? nil : project_conditions.join(' AND ')
results = []
results_count = 0
- with_scope(:find => {:conditions => project_conditions.join(' AND ')}) do
+ with_scope(:find => {:conditions => project_conditions}) do
with_scope(:find => find_options) do
- results_count = count(:all)
- results = find(:all, limit_options)
+ results_count = scope.count(:all)
+ results = scope.find(:all, limit_options)
end
end
[results, results_count]