Commit 28dea01b authored by Jan Provaznik's avatar Jan Provaznik

Fix rendering of service desk notes

When custom template is used, then default mailer views are not used
for rendering the email, but `markdown` for rendering the email is
called directly. We should make sure that proper banzain pipeline is
set for rendering and also note's author is set.
parent ada28f94
...@@ -58,10 +58,12 @@ module Emails ...@@ -58,10 +58,12 @@ module Emails
def template_content(email_type) def template_content(email_type)
template = Gitlab::Template::ServiceDeskTemplate.find(email_type, @project) template = Gitlab::Template::ServiceDeskTemplate.find(email_type, @project)
text = substitute_template_replacements(template.content) text = substitute_template_replacements(template.content)
markdown(text, project: @project) context = { project: @project, pipeline: :email }
context[:author] = @note.author if email_type == 'new_note'
markdown(text, context)
rescue Gitlab::Template::Finders::RepoTemplateFinder::FileNotFoundError rescue Gitlab::Template::Finders::RepoTemplateFinder::FileNotFoundError
nil nil
end end
......
---
title: Render correct URLs for uploads in service desk issues when custom template
is used.
merge_request: 45772
author:
type: fixed
...@@ -183,6 +183,25 @@ RSpec.describe Emails::ServiceDesk do ...@@ -183,6 +183,25 @@ RSpec.describe Emails::ServiceDesk do
it_behaves_like 'handle template content', 'new_note' it_behaves_like 'handle template content', 'new_note'
end end
context 'with upload link in the note' do
let_it_be(:upload_path) { '/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg' }
let_it_be(:note) { create(:note_on_issue, noteable: issue, project: project, note: "a new comment with [file](#{upload_path})") }
let(:template_content) { 'some text %{ NOTE_TEXT }' }
let(:expected_body) { %Q(some text a new comment with <a href="#{project.web_url}#{upload_path}" data-link="true" class="gfm">file</a>) }
it_behaves_like 'handle template content', 'new_note'
end
context 'with all-user reference in a an external author comment' do
let_it_be(:note) { create(:note_on_issue, noteable: issue, project: project, note: "Hey @all, just a ping", author: User.support_bot) }
let(:template_content) { 'some text %{ NOTE_TEXT }' }
let(:expected_body) { 'Hey , just a ping' }
it_behaves_like 'handle template content', 'new_note'
end
end end
end end
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