Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-02-20 16:49:51 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-02-20 16:49:51 +0300
commit71786ddc8e28fbd3cb3fcc4b3ff15e5962a1c82e (patch)
tree6a2d93ef3fb2d353bb7739e4b57e6541f51cdd71 /app/mailers
parenta7253423e3403b8c08f8a161e5937e1488f5f407 (diff)
Add latest changes from gitlab-org/gitlab@15-9-stable-eev15.9.0-rc42
Diffstat (limited to 'app/mailers')
-rw-r--r--app/mailers/emails/issues.rb2
-rw-r--r--app/mailers/emails/merge_requests.rb2
-rw-r--r--app/mailers/emails/service_desk.rb38
-rw-r--r--app/mailers/notify.rb8
4 files changed, 40 insertions, 10 deletions
diff --git a/app/mailers/emails/issues.rb b/app/mailers/emails/issues.rb
index 6a5680c080b..58843435fa0 100644
--- a/app/mailers/emails/issues.rb
+++ b/app/mailers/emails/issues.rb
@@ -105,7 +105,7 @@ module Emails
@written_count = export_status.fetch(:rows_written)
@truncated = export_status.fetch(:truncated)
@size_limit = ActiveSupport::NumberHelper
- .number_to_human_size(Issuable::ExportCsv::BaseService::TARGET_FILESIZE)
+ .number_to_human_size(ExportCsv::BaseService::TARGET_FILESIZE)
filename = "#{project.full_path.parameterize}_issues_#{Date.today.iso8601}.csv"
attachments[filename] = { content: csv_data, mime_type: 'text/csv' }
diff --git a/app/mailers/emails/merge_requests.rb b/app/mailers/emails/merge_requests.rb
index fc944c34166..6678bb563ed 100644
--- a/app/mailers/emails/merge_requests.rb
+++ b/app/mailers/emails/merge_requests.rb
@@ -138,7 +138,7 @@ module Emails
@written_count = export_status.fetch(:rows_written)
@truncated = export_status.fetch(:truncated)
@size_limit = ActiveSupport::NumberHelper
- .number_to_human_size(Issuable::ExportCsv::BaseService::TARGET_FILESIZE)
+ .number_to_human_size(ExportCsv::BaseService::TARGET_FILESIZE)
filename = "#{project.full_path.parameterize}_merge_requests_#{Date.current.iso8601}.csv"
attachments[filename] = { content: csv_data, mime_type: 'text/csv' }
diff --git a/app/mailers/emails/service_desk.rb b/app/mailers/emails/service_desk.rb
index 2953ec6cbe5..1295f978049 100644
--- a/app/mailers/emails/service_desk.rb
+++ b/app/mailers/emails/service_desk.rb
@@ -17,24 +17,30 @@ module Emails
email_sender = sender(
@support_bot.id,
send_from_user_email: false,
- sender_name: @project.service_desk_setting&.outgoing_name
+ sender_name: @service_desk_setting&.outgoing_name,
+ sender_email: service_desk_sender_email_address
)
options = service_desk_options(email_sender, 'thank_you', @issue.external_author)
.merge(subject: "Re: #{subject_base}")
- mail_new_thread(@issue, options)
+ inject_service_desk_custom_email(mail_new_thread(@issue, options))
end
def service_desk_new_note_email(issue_id, note_id, recipient)
@note = Note.find(note_id)
setup_service_desk_mail(issue_id)
- email_sender = sender(@note.author_id)
+ email_sender = sender(
+ @note.author_id,
+ send_from_user_email: false,
+ sender_email: service_desk_sender_email_address
+ )
+
add_uploads_as_attachments if Feature.enabled?(:service_desk_new_note_email_native_attachments, @note.project)
options = service_desk_options(email_sender, 'new_note', recipient)
.merge(subject: subject_base)
- mail_answer_thread(@issue, options)
+ inject_service_desk_custom_email(mail_answer_thread(@issue, options))
end
private
@@ -44,6 +50,8 @@ module Emails
@project = @issue.project
@support_bot = User.support_bot
+ @service_desk_setting = @project.service_desk_setting
+
@sent_notification = SentNotification.record(@issue, @support_bot.id, reply_key)
end
@@ -55,10 +63,26 @@ module Emails
next unless template_body = template_content(email_type)
options[:body] = template_body
- options[:content_type] = 'text/html'
+ options[:content_type] = 'text/html' unless attachments.present?
end
end
+ def inject_service_desk_custom_email(mail)
+ return mail unless service_desk_custom_email_enabled?
+
+ mail.delivery_method(::Mail::SMTP, @service_desk_setting.custom_email_delivery_options)
+ end
+
+ def service_desk_custom_email_enabled?
+ Feature.enabled?(:service_desk_custom_email, @project) && @service_desk_setting&.custom_email_enabled?
+ end
+
+ def service_desk_sender_email_address
+ return unless service_desk_custom_email_enabled?
+
+ @service_desk_setting.custom_email
+ end
+
def template_content(email_type)
template = Gitlab::Template::ServiceDeskTemplate.find(email_type, @project)
text = substitute_template_replacements(template.content)
@@ -77,6 +101,10 @@ module Emails
.gsub(/%\{\s*ISSUE_ID\s*\}/, issue_id)
.gsub(/%\{\s*ISSUE_PATH\s*\}/, issue_path)
.gsub(/%\{\s*NOTE_TEXT\s*\}/, note_text)
+ .gsub(/%\{\s*SYSTEM_HEADER\s*\}/, text_header_message.to_s)
+ .gsub(/%\{\s*SYSTEM_FOOTER\s*\}/, text_footer_message.to_s)
+ .gsub(/%\{\s*UNSUBSCRIBE_URL\s*\}/, unsubscribe_sent_notification_url(@sent_notification))
+ .gsub(/%\{\s*ADDITIONAL_TEXT\s*\}/, service_desk_email_additional_text.to_s)
end
def issue_id
diff --git a/app/mailers/notify.rb b/app/mailers/notify.rb
index 31726563662..28ef6d8d6c6 100644
--- a/app/mailers/notify.rb
+++ b/app/mailers/notify.rb
@@ -68,14 +68,16 @@ class Notify < ApplicationMailer
private
# Return an email address that displays the name of the sender.
- # Only the displayed name changes; the actual email address is always the same.
- def sender(sender_id, send_from_user_email: false, sender_name: nil)
+ # Override sender_email if you want to hard replace the sender address (e.g. custom email for Service Desk)
+ def sender(sender_id, send_from_user_email: false, sender_name: nil, sender_email: nil)
return unless sender = User.find(sender_id)
address = default_sender_address
address.display_name = sender_name.presence || "#{sender.name} (#{sender.to_reference})"
- if send_from_user_email && can_send_from_user_email?(sender)
+ if sender_email
+ address.address = sender_email
+ elsif send_from_user_email && can_send_from_user_email?(sender)
address.address = sender.email
end