From 12b37ae754b76bdf88f9a3ac134f7072c6987bf9 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Mon, 9 Jul 2018 14:29:38 +0000 Subject: Remove filename from attachment preview links (#27822). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch by Felix Schäfer and Gregor Schmidt. git-svn-id: http://svn.redmine.org/redmine/trunk@17440 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/application_helper.rb | 18 ++++++++++++------ test/functional/issues_controller_test.rb | 2 +- test/helpers/application_helper_test.rb | 18 +++++++++--------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 576b996..b7d8380 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -98,10 +98,17 @@ module ApplicationHelper # * :download - Force download (default: false) def link_to_attachment(attachment, options={}) text = options.delete(:text) || attachment.filename - route_method = options.delete(:download) ? :download_named_attachment_url : :named_attachment_url - html_options = options.slice!(:only_path) + if options.delete(:download) + 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) - url = send(route_method, attachment, attachment.filename, options) + url = send(route_method, attachment, options) link_to text, url, html_options end @@ -263,9 +270,8 @@ module ApplicationHelper :srcset => "#{thumbnail_path(attachment, :size => thumbnail_size * 2)} 2x", :style => "max-width: #{thumbnail_size}px; max-height: #{thumbnail_size}px;" ), - named_attachment_path( - attachment, - attachment.filename + attachment_path( + attachment ), :title => attachment.filename ) diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 61b2ded..35c5053 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -2081,7 +2081,7 @@ class IssuesControllerTest < Redmine::ControllerTest end 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"]' end end diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index e28a567..aa403be 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -677,7 +677,7 @@ RAW def test_attachment_links text = 'attachment:error281.txt' - result = link_to("error281.txt", "/attachments/1/error281.txt", + result = link_to("error281.txt", "/attachments/1", :class => "attachment") assert_equal "

#{result}

", textilizable(text, @@ -689,7 +689,7 @@ RAW set_tmp_attachments_directory a1 = Attachment.generate!(:filename => "test.txt", :created_on => 1.hour.ago) 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") assert_equal "

#{result}

", textilizable('attachment:test.txt', :attachments => [a1, a2]) @@ -700,13 +700,13 @@ RAW with_settings :text_formatting => 'textile' do raw = "attachment:image@2x.png should not be parsed in image@2x.png" - assert_match %r{

image@2x.png should not be parsed in image@2x.png

}, + assert_match %r{

image@2x.png should not be parsed in image@2x.png

}, textilizable(raw, :attachments => [attachment]) end with_settings :text_formatting => 'markdown' do raw = "attachment:image@2x.png should not be parsed in image@2x.png" - assert_match %r{

image@2x.png should not be parsed in image@2x.png

} , + assert_match %r{

image@2x.png should not be parsed in image@2x.png

} , textilizable(raw, :attachments => [attachment]) end end @@ -1445,16 +1445,16 @@ RAW def test_link_to_attachment a = Attachment.find(3) - assert_equal 'logo.gif', + assert_equal 'logo.gif', link_to_attachment(a) - assert_equal 'Text', + assert_equal '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, link_to_attachment(a, :class => 'foo') assert_equal 'logo.gif', link_to_attachment(a, :download => true) - assert_equal 'logo.gif', + assert_equal 'logo.gif', link_to_attachment(a, :only_path => false) end @@ -1462,7 +1462,7 @@ RAW a = Attachment.find(3) assert_select_in thumbnail_tag(a), 'a[href=?][title=?] img[src=?]', - "/attachments/3/logo.gif", "logo.gif", "/attachments/thumbnail/3" + "/attachments/3", "logo.gif", "/attachments/thumbnail/3" end def test_link_to_project -- 2.7.4 From d6c72d2a15c4e5cd0195abbfa29e9dcc19918cba Mon Sep 17 00:00:00 2001 From: Ed Tan Date: Mon, 9 Jul 2018 23:15:26 -0400 Subject: =?UTF-8?q?Load=20versions=20fixture=20in=20test/system/issues=5Ft?= =?UTF-8?q?est.rb=20in=20order=20to=20fix=0Atest=5Fcreate=5Fissue=5Fwith?= =?UTF-8?q?=5Fnew=5Ftarget=5Fversion=20after=20a=20db:reset?= --- test/system/issues_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/system/issues_test.rb b/test/system/issues_test.rb index 944640c..0ffc1c2 100644 --- a/test/system/issues_test.rb +++ b/test/system/issues_test.rb @@ -21,7 +21,7 @@ class IssuesTest < ApplicationSystemTestCase fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, :trackers, :projects_trackers, :enabled_modules, :issue_statuses, :issues, :enumerations, :custom_fields, :custom_values, :custom_fields_trackers, - :watchers, :journals, :journal_details + :watchers, :journals, :journal_details, :versions def test_create_issue log_user('jsmith', 'jsmith') -- 2.7.4