Feature #34715 » 34715-v2.patch
| app/helpers/queries_helper.rb | ||
|---|---|---|
| 41 | 41 |
group = :label_date |
| 42 | 42 |
elsif %w(estimated_hours spent_time).include?(field) |
| 43 | 43 |
group = :label_time_tracking |
| 44 |
elsif %w(attachment attachment_description).include?(field) |
|
| 45 |
group = :label_attachment |
|
| 44 | 46 |
end |
| 45 | 47 |
if group |
| 46 | 48 |
(grouped[group] ||= []) << [field_options[:name], field] |
| app/models/issue_query.rb | ||
|---|---|---|
| 202 | 202 |
"attachment", |
| 203 | 203 |
:type => :text, :name => l(:label_attachment) |
| 204 | 204 |
) |
| 205 |
add_available_filter( |
|
| 206 |
"attachment_description", |
|
| 207 |
:type => :text, :name => l(:label_attachment_description) |
|
| 208 |
) |
|
| 205 | 209 |
if User.current.logged? |
| 206 | 210 |
add_available_filter( |
| 207 | 211 |
"watcher_id", |
| ... | ... | |
| 597 | 601 |
end |
| 598 | 602 |
end |
| 599 | 603 | |
| 604 |
def sql_for_attachment_description_field(field, operator, value) |
|
| 605 |
cond_description = "a.description IS NOT NULL AND a.description <> ''" |
|
| 606 |
c = |
|
| 607 |
case operator |
|
| 608 |
when '*', '!*' |
|
| 609 |
(operator == '*' ? cond_description : "NOT (#{cond_description})")
|
|
| 610 |
when '~', '!~' |
|
| 611 |
(operator == '~' ? '' : "#{cond_description} AND ") +
|
|
| 612 |
sql_contains('a.description', value.first, :match => (operator == '~'))
|
|
| 613 |
when '^', '$' |
|
| 614 |
sql_contains('a.description', value.first, (operator == '^' ? :starts_with : :ends_with) => true)
|
|
| 615 |
else |
|
| 616 |
'1=0' |
|
| 617 |
end |
|
| 618 |
"EXISTS (SELECT 1 FROM #{Attachment.table_name} a WHERE a.container_type = 'Issue' AND a.container_id = #{Issue.table_name}.id AND #{c})"
|
|
| 619 |
end |
|
| 620 | ||
| 600 | 621 |
def sql_for_parent_id_field(field, operator, value) |
| 601 | 622 |
case operator |
| 602 | 623 |
when "=" |
| config/locales/en.yml | ||
|---|---|---|
| 701 | 701 |
label_attachment_delete: Delete file |
| 702 | 702 |
label_attachment_plural: Files |
| 703 | 703 |
label_file_added: File added |
| 704 |
label_attachment_description: File description |
|
| 704 | 705 |
label_report: Report |
| 705 | 706 |
label_report_plural: Reports |
| 706 | 707 |
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 | ||
|---|---|---|
| 1527 | 1527 |
assert_equal [3, 4], issues.collect(&:id).sort |
| 1528 | 1528 |
end |
| 1529 | 1529 | |
| 1530 |
def test_filter_on_attachment_description_when_any |
|
| 1531 |
query = IssueQuery.new(:name => '_') |
|
| 1532 |
query.filters = {"attachment_description" => {:operator => '*', :values => ['']}}
|
|
| 1533 |
issues = find_issues_with_query(query) |
|
| 1534 |
assert_equal [2, 3, 14], issues.collect(&:id).sort |
|
| 1535 |
end |
|
| 1536 | ||
| 1537 |
def test_filter_on_attachment_description_when_none |
|
| 1538 |
query = IssueQuery.new(:name => '_') |
|
| 1539 |
query.filters = {"attachment_description" => {:operator => '!*', :values => ['']}}
|
|
| 1540 |
issues = find_issues_with_query(query) |
|
| 1541 |
assert_equal [2, 3, 4, 14], issues.collect(&:id).sort |
|
| 1542 |
end |
|
| 1543 | ||
| 1544 |
def test_filter_on_attachment_description_when_contains |
|
| 1545 |
query = IssueQuery.new(:name => '_') |
|
| 1546 |
query.filters = {"attachment_description" => {:operator => '~', :values => ['attachment']}}
|
|
| 1547 |
issues = find_issues_with_query(query) |
|
| 1548 |
assert_equal [3, 14], issues.collect(&:id).sort |
|
| 1549 |
end |
|
| 1550 | ||
| 1551 |
def test_filter_on_attachment_description_when_does_not_contain |
|
| 1552 |
query = IssueQuery.new(:name => '_') |
|
| 1553 |
query.filters = {"attachment_description" => {:operator => '!~', :values => ['attachment']}}
|
|
| 1554 |
issues = find_issues_with_query(query) |
|
| 1555 |
assert_equal [2], issues.collect(&:id).sort |
|
| 1556 |
end |
|
| 1557 | ||
| 1558 |
def test_filter_on_attachment_description_when_starts_with |
|
| 1559 |
query = IssueQuery.new(:name => '_') |
|
| 1560 |
query.filters = {"attachment_description" => {:operator => '^', :values => ['attachment']}}
|
|
| 1561 |
issues = find_issues_with_query(query) |
|
| 1562 |
assert_equal [14], issues.collect(&:id).sort |
|
| 1563 |
end |
|
| 1564 | ||
| 1565 |
def test_filter_on_attachment_description_when_ends_with |
|
| 1566 |
query = IssueQuery.new(:name => '_') |
|
| 1567 |
query.filters = {"attachment_description" => {:operator => '$', :values => ['attachment']}}
|
|
| 1568 |
issues = find_issues_with_query(query) |
|
| 1569 |
assert_equal [3], issues.collect(&:id).sort |
|
| 1570 |
end |
|
| 1571 | ||
| 1530 | 1572 |
def test_filter_on_subject_when_starts_with |
| 1531 | 1573 |
query = IssueQuery.new(:name => '_') |
| 1532 | 1574 |
query.filters = {'subject' => {:operator => '^', :values => ['issue']}}
|