From b03216f31a1804d2841ff213dc624710b1e4b376 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Wed, 4 Mar 2020 09:35:14 +0000 Subject: [PATCH] Merged r19559 from trunk to 4.1-stable (#33083). git-svn-id: http://svn.redmine.org/redmine/branches/4.1-stable@19560 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/query.rb | 2 +- test/unit/query_test.rb | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/models/query.rb b/app/models/query.rb index f583f6ba7..a3061e2de 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -914,7 +914,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 diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index 9e97a4744..c7d805571 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -943,6 +943,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']}}) -- 2.39.5