]> source.dussan.org Git - redmine.git/commitdiff
Include attachments in forum post notifications (#16006).
authorGo MAEDA <maeda@farend.jp>
Tue, 11 Feb 2020 02:34:25 +0000 (02:34 +0000)
committerGo MAEDA <maeda@farend.jp>
Tue, 11 Feb 2020 02:34:25 +0000 (02:34 +0000)
Patch by Yuichi HARADA.

git-svn-id: http://svn.redmine.org/redmine/trunk@19506 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/messages_controller.rb
app/views/mailer/message_posted.html.erb
app/views/mailer/message_posted.text.erb
test/unit/mailer_test.rb

index bbc6a35d4ded8700b7b8948eaf71eae71c6c0b90..2a0e341b6dd072965dba24bcea73811f5ebb8bd1 100644 (file)
@@ -77,10 +77,10 @@ class MessagesController < ApplicationController
     @reply.author = User.current
     @reply.board = @board
     @reply.safe_attributes = params[:reply]
+    @reply.save_attachments(params[:attachments])
     @topic.children << @reply
     if !@reply.new_record?
       call_hook(:controller_messages_reply_after_save, { :params => params, :message => @reply})
-      attachments = Attachment.attach_files(@reply, params[:attachments])
       render_attachment_warning_if_needed(@reply)
     end
     flash[:notice] = l(:notice_successful_update)
@@ -91,12 +91,14 @@ class MessagesController < ApplicationController
   def edit
     (render_403; return false) unless @message.editable_by?(User.current)
     @message.safe_attributes = params[:message]
-    if request.post? && @message.save
-      attachments = Attachment.attach_files(@message, params[:attachments])
-      render_attachment_warning_if_needed(@message)
-      flash[:notice] = l(:notice_successful_update)
-      @message.reload
-      redirect_to board_message_path(@message.board, @message.root, :r => (@message.parent_id && @message.id))
+    if request.post?
+      @message.save_attachments(params[:attachments])
+      if @message.save
+        render_attachment_warning_if_needed(@message)
+        flash[:notice] = l(:notice_successful_update)
+        @message.reload
+        redirect_to board_message_path(@message.board, @message.root, :r => (@message.parent_id && @message.id))
+      end
     end
   end
 
index 3401b181636e6575421bd04aa2e4bec1d9b2d241..2bd4ae0eae591e93082b34be2049dd32fecc8eb6 100644 (file)
@@ -2,3 +2,11 @@
 <em><%= @message.author %></em>
 
 <%= textilizable(@message, :content, :only_path => false) %>
+
+<% if @message.attachments.any? -%>
+<fieldset class="attachments"><legend><%= l(:label_attachment_plural) %></legend>
+<% @message.attachments.each do |attachment| -%>
+  <%= link_to_attachment attachment, :download => true, :only_path => false %> (<%= number_to_human_size(attachment.filesize) %>)<br />
+<% end -%>
+</fieldset>
+<% end -%>
index ef6a3b3aef358c1141f8a83b8374b77bdb8db9bc..9396caa6f2faeda0a9f3a202cc4a821adc369697 100644 (file)
@@ -2,3 +2,10 @@
 <%= @message.author %>
 
 <%= @message.content %>
+
+<% if @message.attachments.any? -%>
+---<%= l(:label_attachment_plural).ljust(37, '-') %>
+<% @message.attachments.each do |attachment| -%>
+<%= attachment.filename %> (<%= number_to_human_size(attachment.filesize) %>)
+<% end -%>
+<% end -%>
index 82ca6cc5f8798c3e92dcbb2b83f6da91333562c6..6e7fc84a7fad406c68621dd18f8a87e7ba51f22d 100644 (file)
@@ -334,6 +334,7 @@ class MailerTest < ActiveSupport::TestCase
 
   def test_message_posted_message_id
     message = Message.find(1)
+    attachment = message.attachments.first
     Mailer.deliver_message_posted(message)
     mail = last_email
     uid = destination_user(mail).id
@@ -344,11 +345,22 @@ class MailerTest < ActiveSupport::TestCase
       assert_select "a[href=?]",
                     "http://localhost:3000/boards/#{message.board.id}/topics/#{message.id}",
                     :text => message.subject
+      # link to the attachments download
+      assert_select 'fieldset.attachments' do
+        assert_select 'a[href=?]',
+                      "http://localhost:3000/attachments/download/#{attachment.id}/#{attachment.filename}",
+                      :text => attachment.filename
+      end
     end
   end
 
   def test_reply_posted_message_id
+    set_tmp_attachments_directory
     message = Message.find(3)
+    attachment = Attachment.generate!(
+      :container => message,
+      :file => uploaded_test_file('testfile.txt', 'text/plain')
+    )
     Mailer.deliver_message_posted(message)
     mail = last_email
     uid = destination_user(mail).id
@@ -359,6 +371,12 @@ class MailerTest < ActiveSupport::TestCase
       assert_select "a[href=?]",
                     "http://localhost:3000/boards/#{message.board.id}/topics/#{message.root.id}?r=#{message.id}#message-#{message.id}",
                     :text => message.subject
+      # link to the attachments download
+      assert_select 'fieldset.attachments' do
+        assert_select 'a[href=?]',
+                      "http://localhost:3000/attachments/download/#{attachment.id}/testfile.txt",
+                      :text => 'testfile.txt'
+      end
     end
   end