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
def process_message(**kwargs)
strip_quick_actions(super(kwargs))
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
......
......@@ -79,10 +79,21 @@ describe Gitlab::Email::Handler::CreateNoteHandler do
end
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
note = noteable.notes.last
expect(note.note).to include(markdown)
end
......
......@@ -9,7 +9,7 @@ module Gitlab
@message = message
end
def execute(project)
def execute(upload_parent:, uploader_class:)
attachments = []
message.attachments.each do |attachment|
......@@ -23,7 +23,7 @@ module Gitlab
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
ensure
tmp.close!
......
......@@ -41,13 +41,20 @@ module Gitlab
end
def add_attachments(reply)
attachments = Email::AttachmentUploader.new(mail).execute(project)
attachments = Email::AttachmentUploader.new(mail).execute(upload_params)
reply + attachments.map do |link|
"\n\n#{link[:markdown]}"
end.join
end
def upload_params
{
upload_parent: project,
uploader_class: FileUploader
}
end
def validate_permission!(permission)
raise UserNotFoundError unless author
raise UserBlockedError if author.blocked?
......
......@@ -9,7 +9,7 @@ describe Gitlab::Email::AttachmentUploader do
let(:message) { Mail::Message.new(message_raw) }
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
expect(link).not_to be_nil
......
......@@ -181,10 +181,21 @@ describe Gitlab::Email::Handler::CreateNoteHandler do
it_behaves_like 'a reply to existing comment'
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
note = noteable.notes.last
expect(note.note).to include(markdown)
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