34297-v2.patch

Go MAEDA, 2020-12-23 12:31

Download (3.15 KB)

View differences:

app/models/query.rb
898 898

  
899 899
  def project_statement
900 900
    project_clauses = []
901
    active_subprojects_ids = []
901
    subprojects_ids = []
902 902

  
903
    active_subprojects_ids = project.descendants.active.map(&:id) if project
904
    if active_subprojects_ids.any?
903
    subprojects_ids = project.descendants.where.not(status: Project::STATUS_ARCHIVED).ids if project
904
    if subprojects_ids.any?
905 905
      if has_filter?("subproject_id")
906 906
        case operator_for("subproject_id")
907 907
        when '='
......
910 910
          project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',')
911 911
        when '!'
912 912
          # exclude the selected subprojects
913
          ids = [project.id] + active_subprojects_ids - values_for("subproject_id").map(&:to_i)
913
          ids = [project.id] + subprojects_ids - values_for("subproject_id").map(&:to_i)
914 914
          project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',')
915 915
        when '!*'
916 916
          # main project only
test/functional/issues_controller_test.rb
119 119
    end
120 120
  end
121 121

  
122
  def test_index_should_list_issues_of_closed_subprojects
123
    Project.update_all(:is_public => true)
124
    project = Project.find(1)
125
    project.descendants.each(&:close)
126

  
127
    with_settings :display_subprojects_issues => '1' do
128
      get(:index, :params => {:project_id => project.id})
129
      assert_response :success
130

  
131
      assert_select 'td.id' do
132
        assert_select 'a[href="/issues/5"]', 1
133
        assert_select 'a[href="/issues/6"]', 1
134
        assert_select 'a[href="/issues/9"]', 1
135
        assert_select 'a[href="/issues/10"]', 1
136
        assert_select 'a[href="/issues/13"]', 1
137
        assert_select 'a[href="/issues/14"]', 0 # private issue
138
      end
139
    end
140
  end
141

  
122 142
  def test_index_with_project_and_subprojects_should_show_private_subprojects_with_permission
123 143
    @request.session[:user_id] = 2
124 144
    with_settings :display_subprojects_issues => '1' do
test/unit/query_test.rb
2503 2503
    ActiveRecord::Base.default_timezone = :local # restore Redmine default
2504 2504
  end
2505 2505

  
2506
  def test_project_statement_with_closed_subprojects
2507
    project = Project.find(1)
2508
    project.descendants.each(&:close)
2509

  
2510
    with_settings :display_subprojects_issues => '1' do
2511
      query = IssueQuery.new(:name => '_', :project => project)
2512
      statement = query.project_statement
2513
      assert_equal "projects.lft >= #{project.lft} AND projects.rgt <= #{project.rgt}", statement
2514
    end
2515
  end
2516

  
2506 2517
  def test_filter_on_subprojects
2507 2518
    query = IssueQuery.new(:name => '_', :project => Project.find(1))
2508 2519
    filter_name = "subproject_id"