Feature #34715 » 34715.patch
app/models/issue_query.rb | ||
---|---|---|
201 | 201 |
"attachment", |
202 | 202 |
:type => :text, :name => l(:label_attachment) |
203 | 203 |
) |
204 |
add_available_filter( |
|
205 |
"attachment_description", |
|
206 |
:type => :text, :name => l(:label_attachment_description) |
|
207 |
) |
|
204 | 208 |
if User.current.logged? |
205 | 209 |
add_available_filter( |
206 | 210 |
"watcher_id", |
... | ... | |
588 | 592 |
end |
589 | 593 |
end |
590 | 594 | |
595 |
def sql_for_attachment_description_field(field, operator, value) |
|
596 |
cond_description = "a.description IS NOT NULL AND a.description <> ''" |
|
597 |
c = |
|
598 |
case operator |
|
599 |
when '*', '!*' |
|
600 |
(operator == '*' ? cond_description : "NOT (#{cond_description})") |
|
601 |
when '~', '!~' |
|
602 |
(operator == '~' ? '' : "#{cond_description} AND ") + |
|
603 |
sql_contains('a.description', value.first, :match => (operator == '~')) |
|
604 |
when '^', '$' |
|
605 |
sql_contains('a.description', value.first, (operator == '^' ? :starts_with : :ends_with) => true) |
|
606 |
else |
|
607 |
'1=0' |
|
608 |
end |
|
609 |
"EXISTS (SELECT 1 FROM #{Attachment.table_name} a WHERE a.container_type = 'Issue' AND a.container_id = #{Issue.table_name}.id AND #{c})" |
|
610 |
end |
|
611 | ||
591 | 612 |
def sql_for_parent_id_field(field, operator, value) |
592 | 613 |
case operator |
593 | 614 |
when "=" |
config/locales/en.yml | ||
---|---|---|
698 | 698 |
label_attachment_delete: Delete file |
699 | 699 |
label_attachment_plural: Files |
700 | 700 |
label_file_added: File added |
701 |
label_attachment_description: File description |
|
701 | 702 |
label_report: Report |
702 | 703 |
label_report_plural: Reports |
703 | 704 |
label_news: News |
test/fixtures/attachments.yml | ||
---|---|---|
197 | 197 |
filename: private.diff |
198 | 198 |
author_id: 2 |
199 | 199 |
content_type: text/x-diff |
200 |
description: attachement of a private issue
|
|
200 |
description: attachment of a private issue |
|
201 | 201 |
attachments_016: |
202 | 202 |
content_type: image/png |
203 | 203 |
downloads: 0 |
test/unit/query_test.rb | ||
---|---|---|
1486 | 1486 |
assert_equal [3, 4], issues.collect(&:id).sort |
1487 | 1487 |
end |
1488 | 1488 | |
1489 |
def test_filter_on_attachment_description_when_any |
|
1490 |
query = IssueQuery.new(:name => '_') |
|
1491 |
query.filters = {"attachment_description" => {:operator => '*', :values => ['']}} |
|
1492 |
issues = find_issues_with_query(query) |
|
1493 |
assert_equal [2, 3, 14], issues.collect(&:id).sort |
|
1494 |
end |
|
1495 | ||
1496 |
def test_filter_on_attachment_description_when_none |
|
1497 |
query = IssueQuery.new(:name => '_') |
|
1498 |
query.filters = {"attachment_description" => {:operator => '!*', :values => ['']}} |
|
1499 |
issues = find_issues_with_query(query) |
|
1500 |
assert_equal [2, 3, 4, 14], issues.collect(&:id).sort |
|
1501 |
end |
|
1502 | ||
1503 |
def test_filter_on_attachment_description_when_contains |
|
1504 |
query = IssueQuery.new(:name => '_') |
|
1505 |
query.filters = {"attachment_description" => {:operator => '~', :values => ['attachment']}} |
|
1506 |
issues = find_issues_with_query(query) |
|
1507 |
assert_equal [3, 14], issues.collect(&:id).sort |
|
1508 |
end |
|
1509 | ||
1510 |
def test_filter_on_attachment_description_when_does_not_contain |
|
1511 |
query = IssueQuery.new(:name => '_') |
|
1512 |
query.filters = {"attachment_description" => {:operator => '!~', :values => ['attachment']}} |
|
1513 |
issues = find_issues_with_query(query) |
|
1514 |
assert_equal [2], issues.collect(&:id).sort |
|
1515 |
end |
|
1516 | ||
1517 |
def test_filter_on_attachment_description_when_starts_with |
|
1518 |
query = IssueQuery.new(:name => '_') |
|
1519 |
query.filters = {"attachment_description" => {:operator => '^', :values => ['attachment']}} |
|
1520 |
issues = find_issues_with_query(query) |
|
1521 |
assert_equal [14], issues.collect(&:id).sort |
|
1522 |
end |
|
1523 | ||
1524 |
def test_filter_on_attachment_description_when_ends_with |
|
1525 |
query = IssueQuery.new(:name => '_') |
|
1526 |
query.filters = {"attachment_description" => {:operator => '$', :values => ['attachment']}} |
|
1527 |
issues = find_issues_with_query(query) |
|
1528 |
assert_equal [3], issues.collect(&:id).sort |
|
1529 |
end |
|
1530 | ||
1489 | 1531 |
def test_filter_on_subject_when_starts_with |
1490 | 1532 |
query = IssueQuery.new(:name => '_') |
1491 | 1533 |
query.filters = {'subject' => {:operator => '^', :values => ['issue']}} |