Project

General

Profile

Defect #33419 » subtasks_project_on_new_issue_form.patch

Dmitry Makurin , 2020-05-08 13:00

View differences:

app/models/issue.rb (revision fca4c59cad3a71a1eef2653f433bf6d5f01ec56a)
1552 1552
  # Returns a scope of projects that user can assign the issue to
1553 1553
  def allowed_target_projects(user=User.current, context=nil)
1554 1554
    if new_record? && context.is_a?(Project) && !copy?
1555
      current_project = context.self_and_descendants
1555
      if parent_issue_id.present? # returns available projects for subtasks
1556
        case Setting.cross_project_subtasks
1557
        when 'system'
1558
          current_project = Project.visible(user)
1559
        when 'tree'
1560
          current_project = Project.visible(user).where("(#{Project.table_name}.lft >= :lft AND #{Project.table_name}.rgt <= :rgt)",
1561
                                                        :lft => context.root.lft, :rgt => context.root.rgt)
1562
        when 'hierarchy'
1563
          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)",
1564
                                                        :lft => context.lft, :rgt => context.rgt)
1565
        when 'descendants'
1566
          current_project = context.self_and_descendants
1567
        else
1568
          current_project = Project.where(:id => context.id)
1569
        end
1570
      else
1571
        current_project = context.self_and_descendants
1572
      end
1556 1573
    elsif new_record?
1557 1574
      current_project = nil
1558 1575
    else
......
1569 1586
    if current_project.is_a?(Project)
1570 1587
      condition = ["(#{condition}) OR #{Project.table_name}.id = ?", current_project.id]
1571 1588
    elsif current_project
1572
      condition = ["(#{condition}) AND #{Project.table_name}.id IN (?)", current_project.map(&:id)]
1589
      condition = ["(#{condition}) AND #{Project.table_name}.id IN (?)", current_project.ids]
1573 1590
    end
1574 1591
    Project.where(condition).having_trackers
1575 1592
  end
test/functional/issues_controller_test.rb (revision fca4c59cad3a71a1eef2653f433bf6d5f01ec56a)
2822 2822
    assert_select 'select[name="issue[project_id]"]', 0
2823 2823
  end
2824 2824

  
2825
  def test_get_new_should_respect_cross_project_subtasks_setting
2826
    # # disabled
2827
    with_settings :cross_project_subtasks  => "" do
2828
      @request.session[:user_id] = 2
2829
      get :new, :params => {
2830
          :project_id => 1,
2831
          :tracker_id => 1,
2832
          :issue => {
2833
              :parent_issue_id => 7
2834
          }
2835
      }
2836
      assert_response :success
2837
      assert_select 'select[name=?]', 'issue[project_id]', 0
2838
    end
2839

  
2840
    # all projects
2841
    with_settings :cross_project_subtasks  => "system" do
2842
      @request.session[:user_id] = 2
2843
      get :new, :params => {
2844
          :project_id => 1,
2845
          :tracker_id => 1,
2846
          :issue => {
2847
              :parent_issue_id => 7
2848
          }
2849
      }
2850
      assert_response :success
2851
      assert_select 'select[name="issue[project_id]"]' do
2852
        assert_select 'option', 4
2853
        assert_select 'option[selected=selected]', :text => 'eCookbook'
2854
        assert_select 'option[value=?]', '5', :text => '  » Private child of eCookbook'
2855
        assert_select 'option[value=?]', '3', :text => '  » eCookbook Subproject 1'
2856
        assert_select 'option[value=?]', '2', :text => 'OnlineStore'
2857
      end
2858
    end
2859

  
2860
    # project tree
2861
    with_settings :cross_project_subtasks  => "tree" do
2862
      @request.session[:user_id] = 2
2863
      get :new, :params => {
2864
          :project_id => 1,
2865
          :tracker_id => 1,
2866
          :issue => {
2867
              :parent_issue_id => 7
2868
          }
2869
      }
2870
      assert_response :success
2871
      assert_select 'select[name="issue[project_id]"]' do
2872
        assert_select 'option', 3
2873
        assert_select 'option[selected=selected]', :text => 'eCookbook'
2874
        assert_select 'option[value=?]', '5', :text => '  » Private child of eCookbook'
2875
        assert_select 'option[value=?]', '3', :text => '  » eCookbook Subproject 1'
2876
      end
2877
    end
2878

  
2879
    # project hierarchy
2880
    with_settings :cross_project_subtasks  => "hierarchy" do
2881
      @request.session[:user_id] = 2
2882
      get :new, :params => {
2883
          :project_id => 1,
2884
          :tracker_id => 1,
2885
          :issue => {
2886
              :parent_issue_id => 7
2887
          }
2888
      }
2889
      assert_response :success
2890
      assert_select 'select[name="issue[project_id]"]' do
2891
        assert_select 'option', 3
2892
        assert_select 'option[selected=selected]', :text => 'eCookbook'
2893
        assert_select 'option[value=?]', '5', :text => '  » Private child of eCookbook'
2894
        assert_select 'option[value=?]', '3', :text => '  » eCookbook Subproject 1'
2895
      end
2896
    end
2897

  
2898
    # subprojects
2899
    with_settings :cross_project_subtasks  => "descendants" do
2900
      @request.session[:user_id] = 2
2901
      get :new, :params => {
2902
          :project_id => 1,
2903
          :tracker_id => 1,
2904
          :issue => {
2905
              :parent_issue_id => 7
2906
          }
2907
      }
2908
      assert_response :success
2909
      assert_select 'select[name="issue[project_id]"]' do
2910
        assert_select 'option', 3
2911
        assert_select 'option[selected=selected]', :text => 'eCookbook'
2912
        assert_select 'option[value=?]', '5', :text => '  » Private child of eCookbook'
2913
        assert_select 'option[value=?]', '3', :text => '  » eCookbook Subproject 1'
2914
      end
2915
    end
2916
  end
2917

  
2825 2918
  def test_get_new_with_minimal_permissions
2826 2919
    Role.find(1).update_attribute :permissions, [:add_issues]
2827 2920
    WorkflowTransition.where(:role_id => 1).delete_all
(1-1/4)