Project

General

Profile

Patch #4800 ยป acts_as_searchable_registration_and_search_by_global_modules.patch

Andrew Chaika, 2010-02-11 09:19

View differences:

app/controllers/search_controller.rb (working copy)
48 48
      return
49 49
    end
50 50
    
51
    @object_types = %w(issues news documents changesets wiki_pages messages projects)
51
    @object_types = Redmine::Acts::Searchable.available_search_types
52 52
    if projects_to_search.is_a? Project
53 53
      # don't search projects
54 54
      @object_types.delete('projects')
vendor/plugins/acts_as_searchable/lib/acts_as_searchable.rb (working copy)
18 18
module Redmine
19 19
  module Acts
20 20
    module Searchable
21

  
22
      mattr_accessor :available_search_types
23
      @@available_search_types = []
24
      class << self
25
        # Registers a search type
26
        def register(search_type)
27
          search_type = search_type.to_s
28
          @@available_search_types << search_type.pluralize.underscore unless @@available_search_types.include?(search_type)
29
        end
30
      end
31

  
21 32
      def self.included(base) 
22 33
        base.extend ClassMethods
23 34
      end 
......
52 63
          searchable_options[:search_custom_fields] = !reflect_on_association(:custom_values).nil?
53 64
          
54 65
          send :include, Redmine::Acts::Searchable::InstanceMethods
66
          Redmine::Acts::Searchable.register(self)
55 67
        end
56 68
      end
57 69

  
......
100 112
            find_options[:conditions] = [sql, * (tokens * token_clauses.size).sort]
101 113
            
102 114
            project_conditions = []
103
            project_conditions << (searchable_options[:permission].nil? ? Project.visible_by(User.current) :
115
            if searchable_options[:project_key] != ""
116
              project_conditions << (searchable_options[:permission].nil? ? Project.visible_by(User.current) :
104 117
                                                 Project.allowed_to_condition(User.current, searchable_options[:permission]))
105
            project_conditions << "#{searchable_options[:project_key]} IN (#{projects.collect(&:id).join(',')})" unless projects.nil?
118
              project_conditions << "#{searchable_options[:project_key]} IN (#{projects.collect(&:id).join(',')})" unless projects.nil?
119
            end
106 120
            
107 121
            results = []
108 122
            results_count = 0
    (1-1/1)