mirror of
https://github.com/redmine/redmine.git
synced 2025-11-09 06:46:01 +01:00
Remove filename from attachment preview links (#27822).
Patch by Felix Schäfer and Gregor Schmidt. git-svn-id: http://svn.redmine.org/redmine/trunk@17440 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -98,10 +98,17 @@ module ApplicationHelper
|
|||||||
# * :download - Force download (default: false)
|
# * :download - Force download (default: false)
|
||||||
def link_to_attachment(attachment, options={})
|
def link_to_attachment(attachment, options={})
|
||||||
text = options.delete(:text) || attachment.filename
|
text = options.delete(:text) || attachment.filename
|
||||||
route_method = options.delete(:download) ? :download_named_attachment_url : :named_attachment_url
|
if options.delete(:download)
|
||||||
html_options = options.slice!(:only_path)
|
route_method = :download_named_attachment_url
|
||||||
|
options[:filename] = attachment.filename
|
||||||
|
else
|
||||||
|
route_method = :attachment_url
|
||||||
|
# make sure we don't have an extraneous :filename in the options
|
||||||
|
options.delete(:filename)
|
||||||
|
end
|
||||||
|
html_options = options.slice!(:only_path, :filename)
|
||||||
options[:only_path] = true unless options.key?(:only_path)
|
options[:only_path] = true unless options.key?(:only_path)
|
||||||
url = send(route_method, attachment, attachment.filename, options)
|
url = send(route_method, attachment, options)
|
||||||
link_to text, url, html_options
|
link_to text, url, html_options
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -263,9 +270,8 @@ module ApplicationHelper
|
|||||||
:srcset => "#{thumbnail_path(attachment, :size => thumbnail_size * 2)} 2x",
|
:srcset => "#{thumbnail_path(attachment, :size => thumbnail_size * 2)} 2x",
|
||||||
:style => "max-width: #{thumbnail_size}px; max-height: #{thumbnail_size}px;"
|
:style => "max-width: #{thumbnail_size}px; max-height: #{thumbnail_size}px;"
|
||||||
),
|
),
|
||||||
named_attachment_path(
|
attachment_path(
|
||||||
attachment,
|
attachment
|
||||||
attachment.filename
|
|
||||||
),
|
),
|
||||||
:title => attachment.filename
|
:title => attachment.filename
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2081,7 +2081,7 @@ class IssuesControllerTest < Redmine::ControllerTest
|
|||||||
end
|
end
|
||||||
|
|
||||||
assert_select 'div.thumbnails' do
|
assert_select 'div.thumbnails' do
|
||||||
assert_select 'a[href="/attachments/16/testfile.png"]' do
|
assert_select 'a[href="/attachments/16"]' do
|
||||||
assert_select 'img[src="/attachments/thumbnail/16"]'
|
assert_select 'img[src="/attachments/thumbnail/16"]'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -677,7 +677,7 @@ RAW
|
|||||||
|
|
||||||
def test_attachment_links
|
def test_attachment_links
|
||||||
text = 'attachment:error281.txt'
|
text = 'attachment:error281.txt'
|
||||||
result = link_to("error281.txt", "/attachments/1/error281.txt",
|
result = link_to("error281.txt", "/attachments/1",
|
||||||
:class => "attachment")
|
:class => "attachment")
|
||||||
assert_equal "<p>#{result}</p>",
|
assert_equal "<p>#{result}</p>",
|
||||||
textilizable(text,
|
textilizable(text,
|
||||||
@@ -689,7 +689,7 @@ RAW
|
|||||||
set_tmp_attachments_directory
|
set_tmp_attachments_directory
|
||||||
a1 = Attachment.generate!(:filename => "test.txt", :created_on => 1.hour.ago)
|
a1 = Attachment.generate!(:filename => "test.txt", :created_on => 1.hour.ago)
|
||||||
a2 = Attachment.generate!(:filename => "test.txt")
|
a2 = Attachment.generate!(:filename => "test.txt")
|
||||||
result = link_to("test.txt", "/attachments/#{a2.id}/test.txt",
|
result = link_to("test.txt", "/attachments/#{a2.id}",
|
||||||
:class => "attachment")
|
:class => "attachment")
|
||||||
assert_equal "<p>#{result}</p>",
|
assert_equal "<p>#{result}</p>",
|
||||||
textilizable('attachment:test.txt', :attachments => [a1, a2])
|
textilizable('attachment:test.txt', :attachments => [a1, a2])
|
||||||
@@ -700,13 +700,13 @@ RAW
|
|||||||
|
|
||||||
with_settings :text_formatting => 'textile' do
|
with_settings :text_formatting => 'textile' do
|
||||||
raw = "attachment:image@2x.png should not be parsed in image@2x.png"
|
raw = "attachment:image@2x.png should not be parsed in image@2x.png"
|
||||||
assert_match %r{<p><a class="attachment" href="/attachments/#{attachment.id}/image@2x.png">image@2x.png</a> should not be parsed in image@2x.png</p>},
|
assert_match %r{<p><a class="attachment" href="/attachments/#{attachment.id}">image@2x.png</a> should not be parsed in image@2x.png</p>},
|
||||||
textilizable(raw, :attachments => [attachment])
|
textilizable(raw, :attachments => [attachment])
|
||||||
end
|
end
|
||||||
|
|
||||||
with_settings :text_formatting => 'markdown' do
|
with_settings :text_formatting => 'markdown' do
|
||||||
raw = "attachment:image@2x.png should not be parsed in image@2x.png"
|
raw = "attachment:image@2x.png should not be parsed in image@2x.png"
|
||||||
assert_match %r{<p><a class="attachment" href="/attachments/#{attachment.id}/image@2x.png">image@2x.png</a> should not be parsed in image@2x.png</p>} ,
|
assert_match %r{<p><a class="attachment" href="/attachments/#{attachment.id}">image@2x.png</a> should not be parsed in image@2x.png</p>} ,
|
||||||
textilizable(raw, :attachments => [attachment])
|
textilizable(raw, :attachments => [attachment])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -1445,16 +1445,16 @@ RAW
|
|||||||
|
|
||||||
def test_link_to_attachment
|
def test_link_to_attachment
|
||||||
a = Attachment.find(3)
|
a = Attachment.find(3)
|
||||||
assert_equal '<a href="/attachments/3/logo.gif">logo.gif</a>',
|
assert_equal '<a href="/attachments/3">logo.gif</a>',
|
||||||
link_to_attachment(a)
|
link_to_attachment(a)
|
||||||
assert_equal '<a href="/attachments/3/logo.gif">Text</a>',
|
assert_equal '<a href="/attachments/3">Text</a>',
|
||||||
link_to_attachment(a, :text => 'Text')
|
link_to_attachment(a, :text => 'Text')
|
||||||
result = link_to("logo.gif", "/attachments/3/logo.gif", :class => "foo")
|
result = link_to("logo.gif", "/attachments/3", :class => "foo")
|
||||||
assert_equal result,
|
assert_equal result,
|
||||||
link_to_attachment(a, :class => 'foo')
|
link_to_attachment(a, :class => 'foo')
|
||||||
assert_equal '<a href="/attachments/download/3/logo.gif">logo.gif</a>',
|
assert_equal '<a href="/attachments/download/3/logo.gif">logo.gif</a>',
|
||||||
link_to_attachment(a, :download => true)
|
link_to_attachment(a, :download => true)
|
||||||
assert_equal '<a href="http://test.host/attachments/3/logo.gif">logo.gif</a>',
|
assert_equal '<a href="http://test.host/attachments/3">logo.gif</a>',
|
||||||
link_to_attachment(a, :only_path => false)
|
link_to_attachment(a, :only_path => false)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1462,7 +1462,7 @@ RAW
|
|||||||
a = Attachment.find(3)
|
a = Attachment.find(3)
|
||||||
assert_select_in thumbnail_tag(a),
|
assert_select_in thumbnail_tag(a),
|
||||||
'a[href=?][title=?] img[src=?]',
|
'a[href=?][title=?] img[src=?]',
|
||||||
"/attachments/3/logo.gif", "logo.gif", "/attachments/thumbnail/3"
|
"/attachments/3", "logo.gif", "/attachments/thumbnail/3"
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_link_to_project
|
def test_link_to_project
|
||||||
|
|||||||
Reference in New Issue
Block a user