Index: app/models/issue.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- app/models/issue.rb (revision 7558df09e92995965e436603045474c0e3952007) +++ app/models/issue.rb (revision fca4c59cad3a71a1eef2653f433bf6d5f01ec56a) @@ -1552,7 +1552,24 @@ # Returns a scope of projects that user can assign the issue to def allowed_target_projects(user=User.current, context=nil) if new_record? && context.is_a?(Project) && !copy? - current_project = context.self_and_descendants + if parent_issue_id.present? # returns available projects for subtasks + case Setting.cross_project_subtasks + when 'system' + current_project = Project.visible(user) + when 'tree' + current_project = Project.visible(user).where("(#{Project.table_name}.lft >= :lft AND #{Project.table_name}.rgt <= :rgt)", + :lft => context.root.lft, :rgt => context.root.rgt) + when 'hierarchy' + current_project = Project.visible(user).where("(#{Project.table_name}.lft >= :lft AND #{Project.table_name}.rgt <= :rgt) OR (#{Project.table_name}.lft < :lft AND #{Project.table_name}.rgt > :rgt)", + :lft => context.lft, :rgt => context.rgt) + when 'descendants' + current_project = context.self_and_descendants + else + current_project = Project.where(:id => context.id) + end + else + current_project = context.self_and_descendants + end elsif new_record? current_project = nil else @@ -1569,7 +1586,7 @@ if current_project.is_a?(Project) condition = ["(#{condition}) OR #{Project.table_name}.id = ?", current_project.id] elsif current_project - condition = ["(#{condition}) AND #{Project.table_name}.id IN (?)", current_project.map(&:id)] + condition = ["(#{condition}) AND #{Project.table_name}.id IN (?)", current_project.ids] end Project.where(condition).having_trackers end Index: test/functional/issues_controller_test.rb IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- test/functional/issues_controller_test.rb (revision 7558df09e92995965e436603045474c0e3952007) +++ test/functional/issues_controller_test.rb (revision fca4c59cad3a71a1eef2653f433bf6d5f01ec56a) @@ -2822,6 +2822,99 @@ assert_select 'select[name="issue[project_id]"]', 0 end + def test_get_new_should_respect_cross_project_subtasks_setting + # # disabled + with_settings :cross_project_subtasks => "" do + @request.session[:user_id] = 2 + get :new, :params => { + :project_id => 1, + :tracker_id => 1, + :issue => { + :parent_issue_id => 7 + } + } + assert_response :success + assert_select 'select[name=?]', 'issue[project_id]', 0 + end + + # all projects + with_settings :cross_project_subtasks => "system" do + @request.session[:user_id] = 2 + get :new, :params => { + :project_id => 1, + :tracker_id => 1, + :issue => { + :parent_issue_id => 7 + } + } + assert_response :success + assert_select 'select[name="issue[project_id]"]' do + assert_select 'option', 4 + assert_select 'option[selected=selected]', :text => 'eCookbook' + assert_select 'option[value=?]', '5', :text => '  » Private child of eCookbook' + assert_select 'option[value=?]', '3', :text => '  » eCookbook Subproject 1' + assert_select 'option[value=?]', '2', :text => 'OnlineStore' + end + end + + # project tree + with_settings :cross_project_subtasks => "tree" do + @request.session[:user_id] = 2 + get :new, :params => { + :project_id => 1, + :tracker_id => 1, + :issue => { + :parent_issue_id => 7 + } + } + assert_response :success + assert_select 'select[name="issue[project_id]"]' do + assert_select 'option', 3 + assert_select 'option[selected=selected]', :text => 'eCookbook' + assert_select 'option[value=?]', '5', :text => '  » Private child of eCookbook' + assert_select 'option[value=?]', '3', :text => '  » eCookbook Subproject 1' + end + end + + # project hierarchy + with_settings :cross_project_subtasks => "hierarchy" do + @request.session[:user_id] = 2 + get :new, :params => { + :project_id => 1, + :tracker_id => 1, + :issue => { + :parent_issue_id => 7 + } + } + assert_response :success + assert_select 'select[name="issue[project_id]"]' do + assert_select 'option', 3 + assert_select 'option[selected=selected]', :text => 'eCookbook' + assert_select 'option[value=?]', '5', :text => '  » Private child of eCookbook' + assert_select 'option[value=?]', '3', :text => '  » eCookbook Subproject 1' + end + end + + # subprojects + with_settings :cross_project_subtasks => "descendants" do + @request.session[:user_id] = 2 + get :new, :params => { + :project_id => 1, + :tracker_id => 1, + :issue => { + :parent_issue_id => 7 + } + } + assert_response :success + assert_select 'select[name="issue[project_id]"]' do + assert_select 'option', 3 + assert_select 'option[selected=selected]', :text => 'eCookbook' + assert_select 'option[value=?]', '5', :text => '  » Private child of eCookbook' + assert_select 'option[value=?]', '3', :text => '  » eCookbook Subproject 1' + end + end + end + def test_get_new_with_minimal_permissions Role.find(1).update_attribute :permissions, [:add_issues] WorkflowTransition.where(:role_id => 1).delete_all