summaryrefslogtreecommitdiff
path: root/app/mailers/emails
diff options
context:
space:
mode:
Diffstat (limited to 'app/mailers/emails')
-rw-r--r--app/mailers/emails/merge_requests.rb7
-rw-r--r--app/mailers/emails/service_desk.rb92
2 files changed, 99 insertions, 0 deletions
diff --git a/app/mailers/emails/merge_requests.rb b/app/mailers/emails/merge_requests.rb
index 76b1c2d234c..c709c2950d6 100644
--- a/app/mailers/emails/merge_requests.rb
+++ b/app/mailers/emails/merge_requests.rb
@@ -92,6 +92,13 @@ module Emails
mail_answer_thread(@merge_request, merge_request_thread_options(resolved_by_user_id, recipient_id, reason))
end
+ def merge_when_pipeline_succeeds_email(recipient_id, merge_request_id, mwps_set_by_user_id, reason = nil)
+ setup_merge_request_mail(merge_request_id, recipient_id)
+
+ @mwps_set_by = ::User.find(mwps_set_by_user_id)
+ mail_answer_thread(@merge_request, merge_request_thread_options(mwps_set_by_user_id, recipient_id, reason))
+ end
+
private
def setup_merge_request_mail(merge_request_id, recipient_id, present: false)
diff --git a/app/mailers/emails/service_desk.rb b/app/mailers/emails/service_desk.rb
new file mode 100644
index 00000000000..29fe608472d
--- /dev/null
+++ b/app/mailers/emails/service_desk.rb
@@ -0,0 +1,92 @@
+# frozen_string_literal: true
+
+module Emails
+ module ServiceDesk
+ extend ActiveSupport::Concern
+ include MarkupHelper
+
+ included do
+ layout 'service_desk', only: [:service_desk_thank_you_email, :service_desk_new_note_email]
+ end
+
+ def service_desk_thank_you_email(issue_id)
+ setup_service_desk_mail(issue_id)
+
+ email_sender = sender(
+ @support_bot.id,
+ send_from_user_email: false,
+ sender_name: @project.service_desk_setting&.outgoing_name
+ )
+ options = service_desk_options(email_sender, 'thank_you')
+ .merge(subject: "Re: #{subject_base}")
+
+ mail_new_thread(@issue, options)
+ end
+
+ def service_desk_new_note_email(issue_id, note_id)
+ @note = Note.find(note_id)
+ setup_service_desk_mail(issue_id)
+
+ email_sender = sender(@note.author_id)
+ options = service_desk_options(email_sender, 'new_note')
+ .merge(subject: subject_base)
+
+ mail_answer_thread(@issue, options)
+ end
+
+ private
+
+ def setup_service_desk_mail(issue_id)
+ @issue = Issue.find(issue_id)
+ @project = @issue.project
+ @support_bot = User.support_bot
+
+ @sent_notification = SentNotification.record(@issue, @support_bot.id, reply_key)
+ end
+
+ def service_desk_options(email_sender, email_type)
+ {
+ from: email_sender,
+ to: @issue.service_desk_reply_to
+ }.tap do |options|
+ next unless template_body = template_content(email_type)
+
+ options[:body] = template_body
+ options[:content_type] = 'text/html'
+ end
+ end
+
+ def template_content(email_type)
+ template = Gitlab::Template::ServiceDeskTemplate.find(email_type, @project)
+
+ text = substitute_template_replacements(template.content)
+
+ markdown(text, project: @project)
+ rescue Gitlab::Template::Finders::RepoTemplateFinder::FileNotFoundError
+ nil
+ end
+
+ def substitute_template_replacements(template_body)
+ template_body
+ .gsub(/%\{\s*ISSUE_ID\s*\}/, issue_id)
+ .gsub(/%\{\s*ISSUE_PATH\s*\}/, issue_path)
+ .gsub(/%\{\s*NOTE_TEXT\s*\}/, note_text)
+ end
+
+ def issue_id
+ "#{Issue.reference_prefix}#{@issue.iid}"
+ end
+
+ def issue_path
+ @issue.to_reference(full: true)
+ end
+
+ def note_text
+ @note&.note.to_s
+ end
+
+ def subject_base
+ "#{@issue.title} (##{@issue.iid})"
+ end
+ end
+end