]> source.dussan.org Git - redmine.git/commitdiff
Merged r16196 to 3.3-stable (#15773).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 16 Nov 2019 09:43:42 +0000 (09:43 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 16 Nov 2019 09:43:42 +0000 (09:43 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/3.3-stable@19074 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index a6d32f102c1df9bd7d76a5c6649e14a7e5e51a79..5a47f125b0475b0ee158f6f1a4a9dfa89361ef4d 100644 (file)
@@ -213,7 +213,7 @@ class Query < ActiveRecord::Base
     :list => [ "=", "!" ],
     :list_status => [ "o", "=", "!", "c", "*" ],
     :list_optional => [ "=", "!", "!*", "*" ],
-    :list_subprojects => [ "*", "!*", "=" ],
+    :list_subprojects => [ "*", "!*", "=", "!" ],
     :date => [ "=", ">=", "<=", "><", "<t+", ">t+", "><t+", "t+", "t", "ld", "w", "lw", "l2w", "m", "lm", "y", ">t-", "<t-", "><t-", "t-", "!*", "*" ],
     :date_past => [ "=", ">=", "<=", "><", ">t-", "<t-", "><t-", "t-", "t", "ld", "w", "lw", "l2w", "m", "lm", "y", "!*", "*" ],
     :string => [ "=", "~", "!", "!~", "!*", "*" ],
@@ -573,12 +573,19 @@ class Query < ActiveRecord::Base
 
   def project_statement
     project_clauses = []
-    if project && !project.descendants.active.empty?
+    active_subprojects_ids = []
+
+    active_subprojects_ids = project.descendants.active.map(&:id) if project
+    if active_subprojects_ids.any?
       if has_filter?("subproject_id")
         case operator_for("subproject_id")
         when '='
           # include the selected subprojects
-          ids = [project.id] + values_for("subproject_id").each(&:to_i)
+          ids = [project.id] + values_for("subproject_id").map(&:to_i)
+          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)
           project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',')
         when '!*'
           # main project only
index 54b96ea400228ac17e338973e7cf5ef80a1eba0e..a4dd961ec49e4e305887f6ad84485ef6bc32b8ad 100644 (file)
@@ -1820,4 +1820,21 @@ class QueryTest < ActiveSupport::TestCase
     ActiveRecord::Base.default_timezone = :local # restore Redmine default
   end
 
+  def test_filter_on_subprojects
+    query = IssueQuery.new(:name => '_', :project => Project.find(1))
+    filter_name = "subproject_id"
+    assert_include filter_name, query.available_filters.keys
+
+    # "is" operator should include issues of parent project + issues of the selected subproject
+    query.filters = {filter_name => {:operator => '=', :values => ['3']}}
+    issues = find_issues_with_query(query)
+    assert_equal [1, 2, 3, 5, 7, 8, 11, 12, 13, 14], issues.map(&:id).sort
+
+    # "is not" operator should include issues of parent project + issues of all active subprojects - issues of the selected subprojects
+    query = IssueQuery.new(:name => '_', :project => Project.find(1))
+    query.filters = {filter_name => {:operator => '!', :values => ['3']}}
+    issues = find_issues_with_query(query)
+    assert_equal [1, 2, 3, 6, 7, 8, 9, 10, 11, 12], issues.map(&:id).sort
+  end
+
 end