]> source.dussan.org Git - redmine.git/commitdiff
Merged r21716 and r21719 from trunk to 4.2-stable (#37379).
authorGo MAEDA <maeda@farend.jp>
Thu, 21 Jul 2022 14:52:14 +0000 (14:52 +0000)
committerGo MAEDA <maeda@farend.jp>
Thu, 21 Jul 2022 14:52:14 +0000 (14:52 +0000)
git-svn-id: https://svn.redmine.org/redmine/branches/4.2-stable@21736 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/wiki_formatting/macros.rb
test/functional/previews_controller_test.rb

index f0ac94e20782d3648096e0a724f298d883aff2f4..c62eaba13766d2c51f3ee423d3268396abe63854 100644 (file)
@@ -278,8 +278,12 @@ 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.respond_to?(:attachments)
+        if (controller_name == 'previews' || action_name == 'preview') && @attachments.present?
+          attachments = (attachments.to_a + @attachments).compact
+        end
+        if attachments.present? && (attachment = Attachment.latest_attach(attachments, filename))
           title = options[:title] || attachment.title
           thumbnail_url =
             url_for(:controller => 'attachments', :action => 'thumbnail',
index a8c1e8585f2bb8b4c57030e0907a5cb77bccb52d..ccda609231b933f1b8328a3fb166a1772c04aad6 100644 (file)
@@ -88,6 +88,25 @@ class PreviewsControllerTest < Redmine::ControllerTest
     assert_select 'a.attachment', :text => 'foo.bar'
   end
 
+  def test_preview_issue_notes_should_show_thumbnail_of_file_immidiately_after_attachment
+    attachment = Attachment.generate!(filename: 'foo.png', digest: Redmine::Utils.random_hex(32))
+    attachment.update(container: nil)
+
+    @request.session[:user_id] = 2
+    post(
+      :issue,
+      params: {
+        project_id: '1',
+        issue_id: 1,
+        field: 'notes',
+        text: '{{thumbnail(foo.png)}}',
+        attachments: {'1': { token: attachment.token }}
+      }
+    )
+    assert_response :success
+    assert_select 'a.thumbnail[title=?]', 'foo.png'
+  end
+
   def test_preview_new_news
     get(
       :news,