summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/helpers/queries_helper.rb2
-rw-r--r--app/models/issue_query.rb21
-rw-r--r--config/locales/en.yml1
-rw-r--r--test/unit/query_test.rb42
4 files changed, 66 insertions, 0 deletions
diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb
index dccf35adc..408567377 100644
--- a/app/helpers/queries_helper.rb
+++ b/app/helpers/queries_helper.rb
@@ -41,6 +41,8 @@ module QueriesHelper
group = :label_date
elsif %w(estimated_hours spent_time).include?(field)
group = :label_time_tracking
+ elsif %w(attachment attachment_description).include?(field)
+ group = :label_attachment
end
if group
(grouped[group] ||= []) << [field_options[:name], field]
diff --git a/app/models/issue_query.rb b/app/models/issue_query.rb
index 1ed7056d2..b36cbc5b1 100644
--- a/app/models/issue_query.rb
+++ b/app/models/issue_query.rb
@@ -202,6 +202,10 @@ class IssueQuery < Query
"attachment",
:type => :text, :name => l(:label_attachment)
)
+ add_available_filter(
+ "attachment_description",
+ :type => :text, :name => l(:label_attachment_description)
+ )
if User.current.logged?
add_available_filter(
"watcher_id",
@@ -597,6 +601,23 @@ class IssueQuery < Query
end
end
+ def sql_for_attachment_description_field(field, operator, value)
+ cond_description = "a.description IS NOT NULL AND a.description <> ''"
+ c =
+ case operator
+ when '*', '!*'
+ (operator == '*' ? cond_description : "NOT (#{cond_description})")
+ when '~', '!~'
+ (operator == '~' ? '' : "#{cond_description} AND ") +
+ sql_contains('a.description', value.first, :match => (operator == '~'))
+ when '^', '$'
+ sql_contains('a.description', value.first, (operator == '^' ? :starts_with : :ends_with) => true)
+ else
+ '1=0'
+ end
+ "EXISTS (SELECT 1 FROM #{Attachment.table_name} a WHERE a.container_type = 'Issue' AND a.container_id = #{Issue.table_name}.id AND #{c})"
+ end
+
def sql_for_parent_id_field(field, operator, value)
case operator
when "="
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 2ac0affb8..d89d39ebc 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -701,6 +701,7 @@ en:
label_attachment_delete: Delete file
label_attachment_plural: Files
label_file_added: File added
+ label_attachment_description: File description
label_report: Report
label_report_plural: Reports
label_news: News
diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb
index d2159c84b..07921a951 100644
--- a/test/unit/query_test.rb
+++ b/test/unit/query_test.rb
@@ -1527,6 +1527,48 @@ class QueryTest < ActiveSupport::TestCase
assert_equal [3, 4], issues.collect(&:id).sort
end
+ def test_filter_on_attachment_description_when_any
+ query = IssueQuery.new(:name => '_')
+ query.filters = {"attachment_description" => {:operator => '*', :values => ['']}}
+ issues = find_issues_with_query(query)
+ assert_equal [2, 3, 14], issues.collect(&:id).sort
+ end
+
+ def test_filter_on_attachment_description_when_none
+ query = IssueQuery.new(:name => '_')
+ query.filters = {"attachment_description" => {:operator => '!*', :values => ['']}}
+ issues = find_issues_with_query(query)
+ assert_equal [2, 3, 4, 14], issues.collect(&:id).sort
+ end
+
+ def test_filter_on_attachment_description_when_contains
+ query = IssueQuery.new(:name => '_')
+ query.filters = {"attachment_description" => {:operator => '~', :values => ['attachment']}}
+ issues = find_issues_with_query(query)
+ assert_equal [3, 14], issues.collect(&:id).sort
+ end
+
+ def test_filter_on_attachment_description_when_does_not_contain
+ query = IssueQuery.new(:name => '_')
+ query.filters = {"attachment_description" => {:operator => '!~', :values => ['attachment']}}
+ issues = find_issues_with_query(query)
+ assert_equal [2], issues.collect(&:id).sort
+ end
+
+ def test_filter_on_attachment_description_when_starts_with
+ query = IssueQuery.new(:name => '_')
+ query.filters = {"attachment_description" => {:operator => '^', :values => ['attachment']}}
+ issues = find_issues_with_query(query)
+ assert_equal [14], issues.collect(&:id).sort
+ end
+
+ def test_filter_on_attachment_description_when_ends_with
+ query = IssueQuery.new(:name => '_')
+ query.filters = {"attachment_description" => {:operator => '$', :values => ['attachment']}}
+ issues = find_issues_with_query(query)
+ assert_equal [3], issues.collect(&:id).sort
+ end
+
def test_filter_on_subject_when_starts_with
query = IssueQuery.new(:name => '_')
query.filters = {'subject' => {:operator => '^', :values => ['issue']}}