]> source.dussan.org Git - redmine.git/commitdiff
Make the "Any searchable text" filter search only open issues when the status filter...
authorGo MAEDA <maeda@farend.jp>
Mon, 1 May 2023 14:33:22 +0000 (14:33 +0000)
committerGo MAEDA <maeda@farend.jp>
Mon, 1 May 2023 14:33:22 +0000 (14:33 +0000)
git-svn-id: https://svn.redmine.org/redmine/trunk@22221 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index 94d753603ca9cf3f309e16c2ad135725fb60f12b..e573f8782b40db722a82d8bc7814b51eac536d6a 100644 (file)
@@ -805,8 +805,11 @@ class IssueQuery < Query
       when '*~', '!~' then false
       end
 
+    is_open_issues = has_filter?('status_id') && operator_for('status_id') == 'o'
+
     fetcher = Redmine::Search::Fetcher.new(
-      question, User.current, ['issue'], projects, all_words: is_all_words, attachments: '0'
+      question, User.current, ['issue'], projects,
+      all_words: is_all_words, open_issues: is_open_issues, attachments: '0'
     )
     ids = fetcher.result_ids.map(&:last)
     if ids.present?
index 283bb2e16c7145e409fb158dc0aa3a3bbe7af581..6087616b0de5c911e7d730737ae07f84cff4b980 100644 (file)
@@ -1071,6 +1071,21 @@ class QueryTest < ActiveSupport::TestCase
     result.each {|issue| assert_includes [1, 5], issue.project_id}
   end
 
+  def test_filter_any_searchable_with_open_issues_should_search_only_open_issues
+    User.current = User.find(1)
+    query = IssueQuery.new(
+      :name => '_',
+      :filters => {
+        'status_id' => {:operator => 'o'}
+      }
+    )
+
+    result = query.sql_for_any_searchable_field(nil, '~', ['issue'])
+    assert_match /issues.id  IN \([\d,]+\)/, result
+    ids = result.scan(/\d+/).map(&:to_i).sort
+    assert_equal [4, 5, 6, 7, 9, 10, 13, 14], ids
+  end
+
   def test_filter_updated_by
     user = User.generate!
     Journal.create!(:user_id => user.id, :journalized => Issue.find(2), :notes => 'Notes')