Forum post notification does not include attachments
|Target version:||Candidate for next major release|
The send_notification is called on message creation, before attachments are added. In my case, I need links to attachments to be sent in the notification email.
My app/views/mailer/message_posted.text.erb do do this is:
<%= @message.content %> <% if @message.attachments.any? -%> ---<%= l(:label_attachment_plural).ljust(37, '-') %> <% @message.attachments.each do |attachment| -%> <%=attachment.filename%>: <%=send(:named_attachment_path, attachment, attachment.filename,:only_path=>false) %> (<%= number_to_human_size(attachment.filesize) %>) <% end -%> <% end -%> <%= @author.firstname + " " + @author.lastname + " - "+ @author.mail %>
If the forum message is created by an incoming email (with attachments) then no attachements are shown in outgoing notifications. If the forum message is created via the web form, the attachments are shown.
I fixed this by changing the send_notification trigger to after_commit. Patch attached.
#5 Updated by Yuichi HARADA 3 months ago
- File forum_notification_include_attachments.png added
- File 16006_forum_notification_include_attachments.patch added
T. Hauptman wrote:
I fixed this by changing the send_notification trigger to after_commit.
Already improved by source:trunk/app/models/message.rb@17588#L48 . However, the attachments are not included in forum post notification.
I created a patch to include attachments in forum post notification.
#8 Updated by Yuichi HARADA 27 days ago
- File attachment-in-reply.png added
Go MAEDA wrote:
Thank you for posting the patch. I tried out the patch but I am experiencing a problem that attachments are included only when a topic is created. No attachments information is in a notification when a reply is added.
It cannot be reproduced. Attachments information is in a notification when a reply is added.
I still see the problem when adding a reply.
I found that container_type and container_id have not been set to the attachment when sending notifications. Those values are set after the delivery is finished. So,
app/views/mailer/message_posted.html.erb returns false when generating notification emails.
[ActiveJob] Enqueued ActionMailer::DeliveryJob (Job ID: ce613aa3-4241-4bc4-b59d-009475839967) to Inline(mailers) with arguments: "Mailer", "message_posted", "deliver_now", #<GlobalID:0x00007ff1b32ac090 @uri=#<URI::GID gid://redmine-app/User/1>>, #<GlobalID:0x00007ff1b0f1b680 @uri=#<URI::GID gid://redmine-app/Message/9>> Attachment Load (0.3ms) SELECT "attachments".* FROM "attachments" WHERE "attachments"."id" = ? AND "attachments"."digest" = ? LIMIT ? [["id", 29], ["digest", "632a392af1de2e3de4d8b5ad62da7275550ee0004cdf9f54fa3de05cd28d0aac"], ["LIMIT", 1]] (1.0ms) begin transaction CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."type" IN ('User', 'AnonymousUser') AND "users"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]] Attachment Update (1.1ms) UPDATE "attachments" SET "container_id" = ?, "description" = ?, "container_type" = ? WHERE "attachments"."id" = ? [["container_id", 9], ["description", ""], ["container_type", "Message"], ["id", 29]] (1.2ms) commit transaction