Patch #821 » search_all_projects.diff
| test/functional/search_controller_test.rb (working copy) | ||
|---|---|---|
|
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}"
|
||
|
|
||
| test/fixtures/issues.yml (working copy) | ||
|---|---|---|
|
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
|
||
| app/controllers/search_controller.rb (working copy) | ||
|---|---|---|
|
@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
|
||
| ... | ... | |
|
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
|
||
| ... | ... | |
|
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]
|
||
| ... | ... | |
|
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
|
||
| app/views/search/index.rhtml (working copy) | ||
|---|---|---|
|
<br />
|
||
|
<label><%= check_box_tag 'all_words', 1, @all_words %> <%= l(:label_all_words) %></label>
|
||
|
<label><%= check_box_tag 'titles_only', 1, @titles_only %> <%= l(:label_search_titles_only) %></label>
|
||
|
<% if @project %>
|
||
|
<label><%= check_box_tag 'all_projects', 1, @all_projects %> <%= l(:label_project_all) %></label>
|
||
|
<% end %>
|
||
|
</p>
|
||
|
<%= submit_tag l(:button_submit), :name => 'submit' %>
|
||
|
<% end %>
|
||