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.
This commit is contained in:
evazion
2021-03-20 02:14:23 -05:00
parent 92225177a8
commit fd09cc5e96
3 changed files with 15 additions and 3 deletions

View File

@@ -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

View File

@@ -17,7 +17,7 @@
</li>
<% if policy(post).visible? %>
<li id="post-option-download">
<%= 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) %>
</li>
<% end %>

View File

@@ -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