]> source.dussan.org Git - redmine.git/commitdiff
Merged r20693 from trunk to 4.0-stable (#34297).
authorGo MAEDA <maeda@farend.jp>
Tue, 29 Dec 2020 07:07:54 +0000 (07:07 +0000)
committerGo MAEDA <maeda@farend.jp>
Tue, 29 Dec 2020 07:07:54 +0000 (07:07 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/4.0-stable@20696 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/query.rb
test/functional/issues_controller_test.rb
test/unit/query_test.rb

index 03e2d363bcb8fa63aab1e5b38dfc0bb2b08420e4..796480f3a2518425d2b808d698eb16d8d3a6106b 100644 (file)
@@ -823,10 +823,10 @@ class Query < ActiveRecord::Base
 
   def project_statement
     project_clauses = []
-    active_subprojects_ids = []
+    subprojects_ids = []
 
-    active_subprojects_ids = project.descendants.active.map(&:id) if project
-    if active_subprojects_ids.any?
+    subprojects_ids = project.descendants.where.not(status: Project::STATUS_ARCHIVED).ids if project
+    if subprojects_ids.any?
       if has_filter?("subproject_id")
         case operator_for("subproject_id")
         when '='
@@ -835,7 +835,7 @@ class Query < ActiveRecord::Base
           project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',')
         when '!'
           # exclude the selected subprojects
-          ids = [project.id] + active_subprojects_ids - values_for("subproject_id").map(&:to_i)
+          ids = [project.id] + subprojects_ids - values_for("subproject_id").map(&:to_i)
           project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',')
         when '!*'
           # main project only
index 38bf87ce3d9e790d1bb294ce3c731e10e7154268..f39481e98c8320e53cddc184ab308eb0a56ff4c5 100644 (file)
@@ -122,6 +122,25 @@ class IssuesControllerTest < Redmine::ControllerTest
     assert_select 'a[href="/issues/6"]', 0
   end
 
+  def test_index_should_list_issues_of_closed_subprojects
+    @request.session[:user_id] = 1
+    project = Project.find(1)
+
+    with_settings :display_subprojects_issues => '1' do
+      # One of subprojects is closed
+      Project.find_by(:identifier => 'subproject1').close
+      get(:index, :params => {:project_id => project.id})
+      assert_response :success
+      assert_equal 10, issues_in_list.count
+
+      # All subprojects are closed
+      project.descendants.each(&:close)
+      get(:index, :params => {:project_id => project.id})
+      assert_response :success
+      assert_equal 10, issues_in_list.count
+    end
+  end
+
   def test_index_with_project_and_subprojects_should_show_private_subprojects_with_permission
     @request.session[:user_id] = 2
     Setting.display_subprojects_issues = 1
index 1894de14a768f0f57225a3b2376174ede9f605fe..597168fb8c2e5efac6db8ec8bc18385435fbfcb8 100644 (file)
@@ -2199,6 +2199,17 @@ class QueryTest < ActiveSupport::TestCase
     ActiveRecord::Base.default_timezone = :local # restore Redmine default
   end
 
+  def test_project_statement_with_closed_subprojects
+    project = Project.find(1)
+    project.descendants.each(&:close)
+
+    with_settings :display_subprojects_issues => '1' do
+      query = IssueQuery.new(:name => '_', :project => project)
+      statement = query.project_statement
+      assert_equal "projects.lft >= #{project.lft} AND projects.rgt <= #{project.rgt}", statement
+    end
+  end
+
   def test_filter_on_subprojects
     query = IssueQuery.new(:name => '_', :project => Project.find(1))
     filter_name = "subproject_id"