]> source.dussan.org Git - redmine.git/commitdiff
Projects filter "Subproject of" does not work when the given value is "My projects...
authorGo MAEDA <maeda@farend.jp>
Wed, 4 Mar 2020 08:26:34 +0000 (08:26 +0000)
committerGo MAEDA <maeda@farend.jp>
Wed, 4 Mar 2020 08:26:34 +0000 (08:26 +0000)
Patch by Mizuki ISHIKAWA.

git-svn-id: http://svn.redmine.org/redmine/trunk@19559 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index 6cafda7805299562bc6fbb80b12b697b6ca3ec4f..9e85266451b5aadd7db3dacac95b1e11d6522d77 100644 (file)
@@ -924,7 +924,7 @@ class Query < ActiveRecord::Base
         end
       end
 
-      if field == 'project_id' || (self.type == 'ProjectQuery' && field == 'id')
+      if field == 'project_id' || (self.type == 'ProjectQuery' && (field == 'id' || field == 'parent_id'))
         if v.delete('mine')
           v += User.current.memberships.map(&:project_id).map(&:to_s)
         end
index 8099df3f8605ab8a56591e69a50e7624b1128ac8..d20fefce46499e7c8fb91f318999189030213273 100644 (file)
@@ -939,6 +939,34 @@ class QueryTest < ActiveSupport::TestCase
     assert_not_include 'bookmarks', filter[:values].map{|v| v[1]}
   end
 
+  def test_filter_project_parent_id_with_my_projects
+    User.current = User.find(1)
+    query = ProjectQuery.new(:name => '_')
+    filter = query.available_filters['parent_id']
+    assert_not_nil filter
+    assert_include 'mine', filter[:values].map{|v| v[1]}
+
+    query.filters = { 'parent_id' => {:operator => '=', :values => ['mine']}}
+    result = query.results_scope
+
+    my_projects = User.current.memberships.map(&:project_id)
+    assert_equal Project.where(parent_id: my_projects).ids, result.map(&:id).sort
+  end
+
+  def test_filter_project_parent_id_with_my_bookmarks
+    User.current = User.find(1)
+    query = ProjectQuery.new(:name => '_')
+    filter = query.available_filters['parent_id']
+    assert_not_nil filter
+    assert_include 'bookmarks', filter[:values].map{|v| v[1]}
+
+    query.filters = { 'parent_id' => {:operator => '=', :values => ['bookmarks']}}
+    result = query.results_scope
+
+    bookmarks = User.current.bookmarked_project_ids
+    assert_equal Project.where(parent_id: bookmarks).ids, result.map(&:id).sort
+  end
+
   def test_filter_watched_issues
     User.current = User.find(1)
     query = IssueQuery.new(:name => '_', :filters => { 'watcher_id' => {:operator => '=', :values => ['me']}})