Index: test/functional/search_controller_test.rb =================================================================== --- test/functional/search_controller_test.rb (revision 1212) +++ test/functional/search_controller_test.rb (working copy) @@ -25,6 +25,14 @@ assert assigns(:results).include?(Project.find(1)) end + def test_search_all_projects + @request.session[:user_id] = 1 # admin + get :index, :id => 1, :q => 'Error 281', :all_projects => '1', :submit => 'Search' + results = assigns(:results) + assert_not_nil results + assert_equal 2, results.size + end + def test_search_without_searchable_custom_fields CustomField.update_all "searchable = #{ActiveRecord::Base.connection.quoted_false}" Index: test/fixtures/issues.yml =================================================================== --- test/fixtures/issues.yml (revision 1212) +++ test/fixtures/issues.yml (working copy) @@ -52,7 +52,7 @@ id: 4 fixed_version_id: category_id: - description: Issue on project 2 + description: Issue on project 2. Error 281 was encountered. tracker_id: 1 assigned_to_id: author_id: 2 Index: app/controllers/search_controller.rb =================================================================== --- app/controllers/search_controller.rb (revision 1212) +++ app/controllers/search_controller.rb (working copy) @@ -26,6 +26,7 @@ @question.strip! @all_words = params[:all_words] || (params[:submit] ? false : true) @titles_only = !params[:titles_only].nil? + @all_projects = !params[:all_projects].nil? offset = nil begin; offset = params[:offset].to_time if params[:offset]; rescue; end @@ -35,19 +36,19 @@ redirect_to :controller => "issues", :action => "show", :id => $1 return end - + if params[:id] find_project return unless check_project_privacy end - + if @project - # only show what the user is allowed to view - @object_types = %w(issues news documents changesets wiki_pages messages) - @object_types = @object_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)} - - @scope = @object_types.select {|t| params[t]} - @scope = @object_types if @scope.empty? + object_types_and_scope(@project) + if @all_projects + @projects = Project.find(:all, :conditions => Project.visible_by(User.current)) + else + @projects = [@project] + end else @object_types = @scope = %w(projects) end @@ -65,15 +66,19 @@ like_tokens = @tokens.collect {|w| "%#{w.downcase}%"} @results = [] limit = 10 - if @project - @scope.each do |s| - @results += s.singularize.camelcase.constantize.search(like_tokens, @project, - :all_words => @all_words, - :titles_only => @titles_only, - :limit => (limit+1), - :offset => offset, - :before => params[:previous].nil?) + if @projects + @projects.each do |project| + object_types_and_scope(project) + @scope.each do |s| + @results += s.singularize.camelcase.constantize.search(like_tokens, project, + :all_words => @all_words, + :titles_only => @titles_only, + :limit => (limit+1), + :offset => offset, + :before => params[:previous].nil?) + end end + object_types_and_scope(@project) if @project #make sure object types and scope match current project last @results = @results.sort {|a,b| b.event_datetime <=> a.event_datetime} if params[:previous].nil? @pagination_previous_date = @results[0].event_datetime if offset && @results[0] @@ -109,4 +114,12 @@ rescue ActiveRecord::RecordNotFound render_404 end + + # only show what the user is allowed to view + def object_types_and_scope(project) + @object_types = %w(issues news documents changesets wiki_pages messages) + @object_types = @object_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)} + @scope = @object_types.select {|t| params[t]} + @scope = @object_types if @scope.empty? + end end Index: app/views/search/index.rhtml =================================================================== --- app/views/search/index.rhtml (revision 1212) +++ app/views/search/index.rhtml (working copy) @@ -11,6 +11,9 @@
+<% if @project %> + +<% end %>

<%= submit_tag l(:button_submit), :name => 'submit' %> <% end %>