From fd09cc5e96939a558f7d417783deb5e4ea3c4065 Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 20 Mar 2021 02:14:23 -0500 Subject: [PATCH] posts: fix Download link not respecting tagged filenames option. Fix bug reported in forum #182766: The Download button on the posts page does not respect the Disable tagged filenames user setting. Tags are included in the filename when clicking the Download button even when the Disable tagged filenames setting is set to Yes. Right click -> Save As on the image still respects the setting. --- app/presenters/post_presenter.rb | 8 ++++++-- app/views/posts/partials/show/_options.html.erb | 2 +- test/functional/posts_controller_test.rb | 8 ++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index a0de157b5..14306a90d 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -14,7 +14,11 @@ class PostPresenter @humanized_essential_tag_string ||= tag_set_presenter.humanized_essential_tag_string.presence || "##{@post.id}" end - def filename_for_download - "#{humanized_essential_tag_string} - #{@post.md5}.#{@post.file_ext}" + def filename_for_download(current_user) + if current_user.disable_tagged_filenames? + "#{@post.md5}.#{@post.file_ext}" + else + "#{humanized_essential_tag_string} - #{@post.md5}.#{@post.file_ext}" + end end end diff --git a/app/views/posts/partials/show/_options.html.erb b/app/views/posts/partials/show/_options.html.erb index ae66430f2..ee7d21f58 100644 --- a/app/views/posts/partials/show/_options.html.erb +++ b/app/views/posts/partials/show/_options.html.erb @@ -17,7 +17,7 @@ <% if policy(post).visible? %>
  • - <%= link_to "Download", post.tagged_file_url + "?download=1", download: post.presenter.filename_for_download %> + <%= link_to "Download", post.tagged_file_url + "?download=1", download: post.presenter.filename_for_download(CurrentUser.user) %>
  • <% end %> diff --git a/test/functional/posts_controller_test.rb b/test/functional/posts_controller_test.rb index fc680e21a..1c694e83a 100644 --- a/test/functional/posts_controller_test.rb +++ b/test/functional/posts_controller_test.rb @@ -593,6 +593,14 @@ class PostsControllerTest < ActionDispatch::IntegrationTest assert_nil(response.parsed_body["file_url"]) end end + + should "respect the disable tagged filenames option in the Download link" do + @user.update!(disable_tagged_filenames: true) + get_auth post_path(@post), @user + + assert_response :success + assert_equal("#{@post.md5}.#{@post.file_ext}", response.parsed_body.css("#post-option-download a").attr("download").value) + end end context "update action" do