Commit e51bc96a authored by Felipe Artur's avatar Felipe Artur Committed by Thong Kuah

Fix reply emails with attachments for epics

Fix emails with attachments not creating notes on epics
parent 0e8d7147
---
title: Fix reply emails with attachments for epics
merge_request: 22547
author:
type: fixed
...@@ -24,6 +24,16 @@ module EE ...@@ -24,6 +24,16 @@ module EE
def process_message(**kwargs) def process_message(**kwargs)
strip_quick_actions(super(kwargs)) strip_quick_actions(super(kwargs))
end end
override :upload_params
def upload_params
return super unless try(:noteable)&.is_a?(Epic)
{
upload_parent: noteable.group,
uploader_class: NamespaceFileUploader
}
end
end end
end end
end end
......
...@@ -79,10 +79,21 @@ describe Gitlab::Email::Handler::CreateNoteHandler do ...@@ -79,10 +79,21 @@ describe Gitlab::Email::Handler::CreateNoteHandler do
end end
it "adds all attachments" do it "adds all attachments" do
expect_next_instance_of(Gitlab::Email::AttachmentUploader) do |uploader|
expect(uploader).to receive(:execute).with(upload_parent: group, uploader_class: NamespaceFileUploader).and_return(
[
{
url: "uploads/image.png",
alt: "image",
markdown: markdown
}
]
)
end
receiver.execute receiver.execute
note = noteable.notes.last note = noteable.notes.last
expect(note.note).to include(markdown) expect(note.note).to include(markdown)
end end
......
...@@ -9,7 +9,7 @@ module Gitlab ...@@ -9,7 +9,7 @@ module Gitlab
@message = message @message = message
end end
def execute(project) def execute(upload_parent:, uploader_class:)
attachments = [] attachments = []
message.attachments.each do |attachment| message.attachments.each do |attachment|
...@@ -23,7 +23,7 @@ module Gitlab ...@@ -23,7 +23,7 @@ module Gitlab
content_type: attachment.content_type content_type: attachment.content_type
} }
uploader = UploadService.new(project, file).execute uploader = UploadService.new(upload_parent, file, uploader_class).execute
attachments << uploader.to_h if uploader attachments << uploader.to_h if uploader
ensure ensure
tmp.close! tmp.close!
......
...@@ -41,13 +41,20 @@ module Gitlab ...@@ -41,13 +41,20 @@ module Gitlab
end end
def add_attachments(reply) def add_attachments(reply)
attachments = Email::AttachmentUploader.new(mail).execute(project) attachments = Email::AttachmentUploader.new(mail).execute(upload_params)
reply + attachments.map do |link| reply + attachments.map do |link|
"\n\n#{link[:markdown]}" "\n\n#{link[:markdown]}"
end.join end.join
end end
def upload_params
{
upload_parent: project,
uploader_class: FileUploader
}
end
def validate_permission!(permission) def validate_permission!(permission)
raise UserNotFoundError unless author raise UserNotFoundError unless author
raise UserBlockedError if author.blocked? raise UserBlockedError if author.blocked?
......
...@@ -9,7 +9,7 @@ describe Gitlab::Email::AttachmentUploader do ...@@ -9,7 +9,7 @@ describe Gitlab::Email::AttachmentUploader do
let(:message) { Mail::Message.new(message_raw) } let(:message) { Mail::Message.new(message_raw) }
it "uploads all attachments and returns their links" do it "uploads all attachments and returns their links" do
links = described_class.new(message).execute(project) links = described_class.new(message).execute(upload_parent: project, uploader_class: FileUploader)
link = links.first link = links.first
expect(link).not_to be_nil expect(link).not_to be_nil
......
...@@ -181,10 +181,21 @@ describe Gitlab::Email::Handler::CreateNoteHandler do ...@@ -181,10 +181,21 @@ describe Gitlab::Email::Handler::CreateNoteHandler do
it_behaves_like 'a reply to existing comment' it_behaves_like 'a reply to existing comment'
it "adds all attachments" do it "adds all attachments" do
expect_next_instance_of(Gitlab::Email::AttachmentUploader) do |uploader|
expect(uploader).to receive(:execute).with(upload_parent: project, uploader_class: FileUploader).and_return(
[
{
url: "uploads/image.png",
alt: "image",
markdown: markdown
}
]
)
end
receiver.execute receiver.execute
note = noteable.notes.last note = noteable.notes.last
expect(note.note).to include(markdown) expect(note.note).to include(markdown)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment