diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb old mode 100644 new mode 100755 index 4b35cd8..263bcd7 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -49,9 +49,11 @@ class SearchController < ApplicationController when 'my_projects' User.current.projects when 'subprojects' - @project ? (@project.self_and_descendants.active.to_a) : nil - else + include_subprojects + when 'project' @project + else + Setting.display_subprojects_issues? ? include_subprojects : @project end @object_types = Redmine::Search.available_search_types.dup @@ -89,6 +91,10 @@ class SearchController < ApplicationController end private + def include_subprojects + @project ? (@project.self_and_descendants.active.to_a) : nil + end + def find_optional_project return true unless params[:id] @project = Project.find(params[:id]) diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb old mode 100644 new mode 100755 index 2554cf9..c0344a2 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -44,12 +44,18 @@ module SearchHelper end def project_select_tag + if params[:scope].present? + scope = params[:scope].to_s + else + scope = Setting.display_subprojects_issues? ? 'subprojects' : 'project' + end + options = [[l(:label_project_all), 'all']] options << [l(:label_my_projects), 'my_projects'] unless User.current.memberships.empty? options << [l(:label_and_its_subprojects, @project.name), 'subprojects'] unless @project.nil? || @project.descendants.active.empty? - options << [@project.name, ''] unless @project.nil? + options << [@project.name, 'project'] unless @project.nil? label_tag("scope", l(:description_project_scope), :class => "hidden-for-sighted") + - select_tag('scope', options_for_select(options, params[:scope].to_s)) if options.size > 1 + select_tag('scope', options_for_select(options, scope)) if options.size > 1 end def render_results_by_type(results_by_type) @@ -63,7 +69,7 @@ module SearchHelper :all_words => params[:all_words], :scope => params[:scope], t => 1) end (''.html_safe) unless links.empty? end end diff --git a/config/locales/en.yml b/config/locales/en.yml old mode 100644 new mode 100755 index a8eca2d..4129da0 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -411,7 +411,7 @@ en: setting_per_page_options: Objects per page options setting_user_format: Users display format setting_activity_days_default: Days displayed on project activity - setting_display_subprojects_issues: Display subprojects issues on main projects by default + setting_display_subprojects_issues: Include subprojects issues on main projects by default setting_enabled_scm: Enabled SCM setting_mail_handler_body_delimiters: "Truncate emails after one of these lines" setting_mail_handler_enable_regex_delimiters: "Enable regular expressions" diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb old mode 100644 new mode 100755 index 720d62d..e0dc1a4 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -169,14 +169,42 @@ class SearchControllerTest < Redmine::ControllerTest end end - def test_search_project_and_subprojects + def test_search_scope_subprojects_should_search_in_project_and_subprojects get :index, :params => {:id => 1, :q => 'recipe subproject', :scope => 'subprojects', :all_words => ''} + assert_response :success + + assert_select '#search-results' do + assert_select 'dt.issue', :text => /Bug #1/ + assert_select 'dt.issue', :text => /Bug #5/ + end + end + + def test_search_scope_project_should_search_only_in_project + get :index, :params => {:id => 1, :q => 'recipe subproject', :scope => 'project', :all_words => ''} assert_response :success assert_select '#search-results' do assert_select 'dt.issue', :text => /Bug #1/ - assert_select 'dt.issue', :text => /Bug #5/ + assert_select 'dt.issue a[href="/issues/5"]', 0 + end + end + + def test_search_scope_with_setting_display_subprojects_issues_on_should_set_scope_to_subprojects + with_settings :display_subprojects_issues => '1' do + get :index, :params => {:id => 1, :q => 'recipe subproject', :all_words => ''} + end + assert_response :success + + assert_select '#scope option[selected=selected][value=?]', 'subprojects', :text => 'eCookbook and its subprojects' + end + + def test_search_with_setting_display_subprojects_issues_off_should_set_scope_to_project + with_settings :display_subprojects_issues => '0' do + get :index, :params => {:id => 1, :q => 'recipe subproject', :all_words => ''} end + assert_response :success + + assert_select '#scope option[selected=selected][value=?]', 'project', :text => 'eCookbook' end def test_search_without_searchable_custom_fields @@ -270,7 +298,7 @@ class SearchControllerTest < Redmine::ControllerTest assert_select 'input[name=all_words]:not([checked])' assert_select '#search-results' do assert_select 'dt.issue', :text => / #3 / - assert_select 'dt', 3 + assert_select 'dt', 4 end end