]> source.dussan.org Git - redmine.git/commitdiff
Add support for "start with" and "end with" operators to "Files" filter (#31879).
authorGo MAEDA <maeda@farend.jp>
Mon, 30 Sep 2019 13:15:45 +0000 (13:15 +0000)
committerGo MAEDA <maeda@farend.jp>
Mon, 30 Sep 2019 13:15:45 +0000 (13:15 +0000)
Patch by Yuichi HARADA.

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

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

index 7701cbfe22ba340d43b35eed75025a01bb410d3d..155462c64cb967247bf1188b4a8f2c2513e6766f 100644 (file)
@@ -526,6 +526,9 @@ class IssueQuery < Query
       c = sql_contains("a.filename", value.first)
       e = (operator == "~" ? "EXISTS" : "NOT EXISTS")
       "#{e} (SELECT 1 FROM #{Attachment.table_name} a WHERE a.container_type = 'Issue' AND a.container_id = #{Issue.table_name}.id AND #{c})"
+    when "^", "$"
+      c = sql_contains("a.filename", value.first, (operator == "^" ? :starts_with : :ends_with) => true)
+      "EXISTS (SELECT 1 FROM #{Attachment.table_name} a WHERE a.container_type = 'Issue' AND a.container_id = #{Issue.table_name}.id AND #{c})"
     end
   end
 
index 84bb1e93933f9466600a38c13d8eb05af87a4093..9a8bb3c84ddfdfc98dac4157aeedbc87ef42583f 100644 (file)
@@ -1353,6 +1353,20 @@ class QueryTest < ActiveSupport::TestCase
     assert_nil issues.detect {|issue| issue.attachments.any? {|attachment| attachment.filename.include?('error281')}}
   end
 
+  def test_filter_on_attachment_when_starts_with
+    query = IssueQuery.new(:name => '_')
+    query.filters = {"attachment" => {:operator => '^', :values =>  ['testfile']}}
+    issues = find_issues_with_query(query)
+    assert_equal [14], issues.collect(&:id).sort
+  end
+
+  def test_filter_on_attachment_when_ends_with
+    query = IssueQuery.new(:name => '_')
+    query.filters = {"attachment" => {:operator => '$', :values =>  ['zip']}}
+    issues = find_issues_with_query(query)
+    assert_equal [3, 4], issues.collect(&:id).sort
+  end
+
   def test_filter_on_subject_when_starts_with
     query = IssueQuery.new(:name => '_')
     query.filters = {'subject' => {:operator => '^', :values => ['issue']}}