mirror of
https://github.com/meineerde/redmine.git
synced 2026-01-02 05:39:40 +00:00
Adds a filter on issue attachments (#2783).
git-svn-id: http://svn.redmine.org/redmine/trunk@16344 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
2b33756e9a
commit
2b0e910cd5
@ -140,6 +140,9 @@ class IssueQuery < Query
|
||||
:values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]]
|
||||
end
|
||||
|
||||
add_available_filter "attachment",
|
||||
:type => :text, :name => l(:label_attachment)
|
||||
|
||||
if User.current.logged?
|
||||
add_available_filter "watcher_id",
|
||||
:type => :list, :values => [["<< #{l(:label_me)} >>", "me"]]
|
||||
@ -437,6 +440,18 @@ class IssueQuery < Query
|
||||
"#{Issue.table_name}.is_private #{op} (#{va})"
|
||||
end
|
||||
|
||||
def sql_for_attachment_field(field, operator, value)
|
||||
case operator
|
||||
when "*", "!*"
|
||||
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)"
|
||||
when "~", "!~"
|
||||
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})"
|
||||
end
|
||||
end
|
||||
|
||||
def sql_for_parent_id_field(field, operator, value)
|
||||
case operator
|
||||
when "="
|
||||
|
||||
@ -29,7 +29,8 @@ class QueryTest < ActiveSupport::TestCase
|
||||
:queries,
|
||||
:projects_trackers,
|
||||
:custom_fields_trackers,
|
||||
:workflows
|
||||
:workflows,
|
||||
:attachments
|
||||
|
||||
def setup
|
||||
User.current = nil
|
||||
@ -1194,6 +1195,38 @@ class QueryTest < ActiveSupport::TestCase
|
||||
assert_equal [].map(&:id).sort, find_issues_with_query(query)
|
||||
end
|
||||
|
||||
def test_filter_on_attachment_any
|
||||
query = IssueQuery.new(:name => '_')
|
||||
query.filters = {"attachment" => {:operator => '*', :values => ['']}}
|
||||
issues = find_issues_with_query(query)
|
||||
assert issues.any?
|
||||
assert_nil issues.detect {|issue| issue.attachments.empty?}
|
||||
end
|
||||
|
||||
def test_filter_on_attachment_none
|
||||
query = IssueQuery.new(:name => '_')
|
||||
query.filters = {"attachment" => {:operator => '!*', :values => ['']}}
|
||||
issues = find_issues_with_query(query)
|
||||
assert issues.any?
|
||||
assert_nil issues.detect {|issue| issue.attachments.any?}
|
||||
end
|
||||
|
||||
def test_filter_on_attachment_contains
|
||||
query = IssueQuery.new(:name => '_')
|
||||
query.filters = {"attachment" => {:operator => '~', :values => ['error281']}}
|
||||
issues = find_issues_with_query(query)
|
||||
assert issues.any?
|
||||
assert_nil issues.detect {|issue| ! issue.attachments.any? {|attachment| attachment.filename.include?('error281')}}
|
||||
end
|
||||
|
||||
def test_filter_on_attachment_not_contains
|
||||
query = IssueQuery.new(:name => '_')
|
||||
query.filters = {"attachment" => {:operator => '!~', :values => ['error281']}}
|
||||
issues = find_issues_with_query(query)
|
||||
assert issues.any?
|
||||
assert_nil issues.detect {|issue| issue.attachments.any? {|attachment| attachment.filename.include?('error281')}}
|
||||
end
|
||||
|
||||
def test_statement_should_be_nil_with_no_filters
|
||||
q = IssueQuery.new(:name => '_')
|
||||
q.filters = {}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user