diff --git a/lib/redmine/wiki_formatting/macros.rb b/lib/redmine/wiki_formatting/macros.rb index 0727d6e265..5d39ab7baa 100644 --- a/lib/redmine/wiki_formatting/macros.rb +++ b/lib/redmine/wiki_formatting/macros.rb @@ -278,8 +278,10 @@ module Redmine size = size.to_i size = 200 unless size > 0 - if obj && obj.respond_to?(:attachments) && - attachment = Attachment.latest_attach(obj.attachments, filename) + + attachments = obj.attachments if obj && obj.respond_to?(:attachments) + attachments = (attachments.to_a + @attachments).compact if (controller_name == 'previews' || action_name == 'preview') && @attachments.present? + if attachments.present? && (attachment = Attachment.latest_attach(attachments, filename)) title = options[:title] || attachment.title thumbnail_url = url_for(:controller => 'attachments', :action => 'thumbnail', diff --git a/test/functional/previews_controller_test.rb b/test/functional/previews_controller_test.rb index aa282f3645..c869af57b3 100644 --- a/test/functional/previews_controller_test.rb +++ b/test/functional/previews_controller_test.rb @@ -88,6 +88,25 @@ class PreviewsControllerTest < Redmine::ControllerTest assert_select 'a.attachment', :text => 'foo.bar' end + def test_preview_issue_notes_should_view_thumbnail_of_the_file_after_attachment + attachment = Attachment.generate!(filename: 'foo.bar', digest: 'd') + attachment.update(container: nil) + + @request.session[:user_id] = 2 + post( + :issue, + params: { + project_id: '1', + issue_id: 1, + field: 'notes', + text: '{{thumbnail(foo.bar)}}', + attachments: {'1': { token: attachment.token }} + } + ) + assert_response :success + assert_select 'a.thumbnail[title=?]', 'foo.bar' + end + def test_preview_new_news get( :news,