Project

General

Profile

Defect #34297 » fixed-34297.patch

Yuichi HARADA, 2020-12-03 09:19

View differences:

app/models/query.rb
897 897
  end
898 898

  
899 899
  def project_statement
900
    return nil unless project
901

  
900 902
    project_clauses = []
901
    active_subprojects_ids = []
902

  
903
    active_subprojects_ids = project.descendants.active.map(&:id) if project
904
    if active_subprojects_ids.any?
905
      if has_filter?("subproject_id")
906
        case operator_for("subproject_id")
907
        when '='
908
          # include the selected subprojects
909
          ids = [project.id] + values_for("subproject_id").map(&:to_i)
910
          project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',')
911
        when '!'
912
          # exclude the selected subprojects
913
          ids = [project.id] + active_subprojects_ids - values_for("subproject_id").map(&:to_i)
914
          project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',')
915
        when '!*'
916
          # main project only
917
          project_clauses << "#{Project.table_name}.id = %d" % project.id
918
        else
919
          # all subprojects
920
          project_clauses << "#{Project.table_name}.lft >= #{project.lft} AND #{Project.table_name}.rgt <= #{project.rgt}"
921
        end
922
      elsif Setting.display_subprojects_issues?
923
        project_clauses << "#{Project.table_name}.lft >= #{project.lft} AND #{Project.table_name}.rgt <= #{project.rgt}"
924
      else
903
    if has_filter?("subproject_id")
904
      case operator_for("subproject_id")
905
      when '='
906
        # include the selected subprojects
907
        ids = [project.id] + values_for("subproject_id").map(&:to_i)
908
        project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',')
909
      when '!'
910
        # exclude the selected subprojects
911
        active_subprojects_ids = project.descendants.active.map(&:id)
912
        ids = [project.id] + active_subprojects_ids - values_for("subproject_id").map(&:to_i)
913
        project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',')
914
      when '!*'
915
        # main project only
925 916
        project_clauses << "#{Project.table_name}.id = %d" % project.id
917
      else
918
        # all subprojects
919
        project_clauses << "#{Project.table_name}.lft >= #{project.lft} AND #{Project.table_name}.rgt <= #{project.rgt}"
926 920
      end
927
    elsif project
921
    elsif Setting.display_subprojects_issues?
922
      project_clauses << "#{Project.table_name}.lft >= #{project.lft} AND #{Project.table_name}.rgt <= #{project.rgt}"
923
    else
928 924
      project_clauses << "#{Project.table_name}.id = %d" % project.id
929 925
    end
930 926
    project_clauses.any? ? project_clauses.join(' AND ') : nil
test/functional/issues_controller_test.rb
119 119
    end
120 120
  end
121 121

  
122
  def test_index_with_project_and_closed_subprojects_should_show_issues_for_closed_projects
123
    Project.update_all(:is_public => true)
124
    project = Project.find(1)
125
    assert_equal [3, 4, 5, 6], project.descendants.collect(&:id).sort
126

  
127
    with_settings :display_subprojects_issues => '1' do
128
      [
129
        nil,
130
        [3],
131
        [3, 4, 5, 6]
132
      ].each do |subproject_ids|
133
        project.reopen
134
        (subproject_ids || []).each do |subproject_id|
135
          Project.find(subproject_id).close
136
        end
137

  
138
        get(:index, :params => {:project_id => project.id})
139
        assert_response :success
140

  
141
        assert_select 'td.id' do
142
          assert_select 'a[href="/issues/5"]', 1
143
          assert_select 'a[href="/issues/6"]', 1
144
          assert_select 'a[href="/issues/9"]', 1
145
          assert_select 'a[href="/issues/10"]', 1
146
          assert_select 'a[href="/issues/13"]', 1
147
          assert_select 'a[href="/issues/14"]', 0 # private issue
148
        end
149
      end
150
    end
151
  end
152

  
122 153
  def test_index_with_project_and_subprojects_should_show_private_subprojects_with_permission
123 154
    @request.session[:user_id] = 2
124 155
    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
    assert_equal [3, 4, 5, 6], project.descendants.collect(&:id).sort
2509

  
2510
    with_settings :display_subprojects_issues => '1' do
2511
      [
2512
        nil,
2513
        [3],
2514
        [3, 4, 5, 6]
2515
      ].each do |subproject_ids|
2516
        project.reopen
2517
        (subproject_ids || []).each do |subproject_id|
2518
          Project.find(subproject_id).close
2519
        end
2520

  
2521
        query = IssueQuery.new(:name => '_', :project => project)
2522
        statement = query.project_statement
2523
        assert_equal "projects.lft >= #{project.lft} AND projects.rgt <= #{project.rgt}", statement
2524
      end
2525
    end
2526
  end
2527

  
2506 2528
  def test_filter_on_subprojects
2507 2529
    query = IssueQuery.new(:name => '_', :project => Project.find(1))
2508 2530
    filter_name = "subproject_id"
(1-1/2)