]> source.dussan.org Git - redmine.git/commitdiff
Fix "Any searchable text" filter doesn't support the project filter with the value...
authorGo MAEDA <maeda@farend.jp>
Tue, 18 Apr 2023 12:05:49 +0000 (12:05 +0000)
committerGo MAEDA <maeda@farend.jp>
Tue, 18 Apr 2023 12:05:49 +0000 (12:05 +0000)
git-svn-id: https://svn.redmine.org/redmine/trunk@22203 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index 5c66800f9a325390b4034616f03a492dca551715..94d753603ca9cf3f309e16c2ad135725fb60f12b 100644 (file)
@@ -784,8 +784,16 @@ class IssueQuery < Query
     if project
       projects = project_scope.where(project_statement)
     elsif has_filter?('project_id')
+      case values_for('project_id').first
+      when 'mine'
+        project_ids = User.current.projects.ids
+      when 'bookmarks'
+        project_ids = User.current.bookmarked_project_ids
+      else
+        project_ids = values_for('project_id')
+      end
       projects = project_scope.where(
-        sql_for_field('project_id', operator_for('project_id'), values_for('project_id'), Project.table_name, 'id')
+        sql_for_field('project_id', operator_for('project_id'), project_ids, Project.table_name, 'id')
       )
     else
       projects = nil
index 638ab5b175ea29d325192014553c310c688b8abe..283bb2e16c7145e409fb158dc0aa3a3bbe7af581 100644 (file)
@@ -1041,6 +1041,36 @@ class QueryTest < ActiveSupport::TestCase
     assert_equal [1, 3], result.map(&:id).sort
   end
 
+  def test_filter_any_searchable_with_my_projects
+    # This user's project is ecookbook only
+    User.current = User.find_by(login: 'dlopper')
+    query = IssueQuery.new(
+      :name => '_',
+      :filters => {
+        'any_searchable' => {:operator => '~', :values => ['issue']},
+        'project_id' => {:operator => '=', :values => ['mine']}
+      }
+    )
+    result = find_issues_with_query(query)
+    assert_equal [7, 8, 11, 12], result.map(&:id).sort
+    result.each {|issue| assert_equal 1, issue.project_id}
+  end
+
+  def test_filter_any_searchable_with_my_bookmarks
+    # This user bookmarks two projects, ecookbook and private-child
+    User.current = User.find(1)
+    query = IssueQuery.new(
+      :name => '_',
+      :filters => {
+        'any_searchable' => {:operator => '~', :values => ['issue']},
+        'project_id' => {:operator => '=', :values => ['bookmarks']}
+      }
+    )
+    result = find_issues_with_query(query)
+    assert_equal [6, 7, 8, 9, 10, 11, 12], result.map(&:id).sort
+    result.each {|issue| assert_includes [1, 5], issue.project_id}
+  end
+
   def test_filter_updated_by
     user = User.generate!
     Journal.create!(:user_id => user.id, :journalized => Issue.find(2), :notes => 'Notes')