diff options
Diffstat (limited to 'app/mailers')
-rw-r--r-- | app/mailers/abuse_report_mailer.rb | 2 | ||||
-rw-r--r-- | app/mailers/application_mailer.rb | 19 | ||||
-rw-r--r-- | app/mailers/email_rejection_mailer.rb | 2 | ||||
-rw-r--r-- | app/mailers/emails/admin_notification.rb | 4 | ||||
-rw-r--r-- | app/mailers/emails/groups.rb | 2 | ||||
-rw-r--r-- | app/mailers/emails/identity_verification.rb | 2 | ||||
-rw-r--r-- | app/mailers/emails/in_product_marketing.rb | 2 | ||||
-rw-r--r-- | app/mailers/emails/members.rb | 2 | ||||
-rw-r--r-- | app/mailers/emails/pages_domains.rb | 10 | ||||
-rw-r--r-- | app/mailers/emails/profile.rb | 20 | ||||
-rw-r--r-- | app/mailers/emails/projects.rb | 25 | ||||
-rw-r--r-- | app/mailers/emails/releases.rb | 2 | ||||
-rw-r--r-- | app/mailers/emails/remote_mirrors.rb | 2 | ||||
-rw-r--r-- | app/mailers/notify.rb | 14 | ||||
-rw-r--r-- | app/mailers/previews/notify_preview.rb | 18 | ||||
-rw-r--r-- | app/mailers/repository_check_mailer.rb | 2 |
16 files changed, 73 insertions, 55 deletions
diff --git a/app/mailers/abuse_report_mailer.rb b/app/mailers/abuse_report_mailer.rb index 1fa85064c57..1bf7deec542 100644 --- a/app/mailers/abuse_report_mailer.rb +++ b/app/mailers/abuse_report_mailer.rb @@ -10,7 +10,7 @@ class AbuseReportMailer < ApplicationMailer @abuse_report = AbuseReport.find(abuse_report_id) - mail( + mail_with_locale( to: Gitlab::CurrentSettings.abuse_notification_email, subject: "#{@abuse_report.user.name} (#{@abuse_report.user.username}) was reported for abuse" ) diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 94ed83a7d4a..bb8d20b8301 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -34,4 +34,23 @@ class ApplicationMailer < ActionMailer::Base address.display_name = Gitlab.config.gitlab.email_display_name address end + + def mail_with_locale(headers = {}, &block) + locale = recipient_locale headers + + Gitlab::I18n.with_locale(locale) do + mail(headers, &block) + end + end + + def recipient_locale(headers = {}) + to = Array(headers[:to]) + locale = I18n.locale + locale = preferred_language_by_email(to.first) if to.one? + locale + end + + def preferred_language_by_email(email) + User.find_by_any_email(email)&.preferred_language || I18n.locale + end end diff --git a/app/mailers/email_rejection_mailer.rb b/app/mailers/email_rejection_mailer.rb index 25721658285..f681aa67a77 100644 --- a/app/mailers/email_rejection_mailer.rb +++ b/app/mailers/email_rejection_mailer.rb @@ -22,6 +22,6 @@ class EmailRejectionMailer < ApplicationMailer headers['Reply-To'] = @original_message.to.first if can_retry - mail(headers) + mail_with_locale(headers) end end diff --git a/app/mailers/emails/admin_notification.rb b/app/mailers/emails/admin_notification.rb index 3766b4447d1..5c5497d8eb5 100644 --- a/app/mailers/emails/admin_notification.rb +++ b/app/mailers/emails/admin_notification.rb @@ -7,13 +7,13 @@ module Emails email = user.notification_email_or_default @unsubscribe_url = unsubscribe_url(email: Base64.urlsafe_encode64(email)) @body = body - mail to: email, subject: subject + mail_with_locale to: email, subject: subject end def send_unsubscribed_notification(user_id) user = User.find(user_id) email = user.notification_email_or_default - mail to: email, subject: "Unsubscribed from GitLab administrator notifications" + mail_with_locale to: email, subject: "Unsubscribed from GitLab administrator notifications" end end end diff --git a/app/mailers/emails/groups.rb b/app/mailers/emails/groups.rb index 07812a01202..3c9bf41c208 100644 --- a/app/mailers/emails/groups.rb +++ b/app/mailers/emails/groups.rb @@ -13,7 +13,7 @@ module Emails def group_email(current_user, group, subj, errors: nil) @group = group @errors = errors - mail(to: current_user.notification_email_for(@group), subject: subject(subj)) + mail_with_locale(to: current_user.notification_email_for(@group), subject: subject(subj)) end end end diff --git a/app/mailers/emails/identity_verification.rb b/app/mailers/emails/identity_verification.rb index 2fc8cae06fe..e3089fdef9b 100644 --- a/app/mailers/emails/identity_verification.rb +++ b/app/mailers/emails/identity_verification.rb @@ -13,3 +13,5 @@ module Emails end end end + +Emails::IdentityVerification.prepend_mod diff --git a/app/mailers/emails/in_product_marketing.rb b/app/mailers/emails/in_product_marketing.rb index 1b46d4841b0..972c1da065a 100644 --- a/app/mailers/emails/in_product_marketing.rb +++ b/app/mailers/emails/in_product_marketing.rb @@ -31,7 +31,7 @@ module Emails def mail_to(to:, subject:) custom_headers = Gitlab.com? ? CUSTOM_HEADERS : {} - mail(to: to, subject: subject, **custom_headers) do |format| + mail_with_locale(to: to, subject: subject, **custom_headers) do |format| format.html do @message.format = :html diff --git a/app/mailers/emails/members.rb b/app/mailers/emails/members.rb index c885e41671c..33c955f94ee 100644 --- a/app/mailers/emails/members.rb +++ b/app/mailers/emails/members.rb @@ -61,7 +61,7 @@ module Emails Gitlab::Tracking.event(self.class.name, 'invite_email_sent', label: 'invite_email', property: member_id.to_s) - mail(to: member.invite_email, subject: invite_email_subject, **invite_email_headers) do |format| + mail_with_locale(to: member.invite_email, subject: invite_email_subject, **invite_email_headers) do |format| format.html { render layout: 'unknown_user_mailer' } format.text { render layout: 'unknown_user_mailer' } end diff --git a/app/mailers/emails/pages_domains.rb b/app/mailers/emails/pages_domains.rb index 6c3dcf8746b..a6e9da18689 100644 --- a/app/mailers/emails/pages_domains.rb +++ b/app/mailers/emails/pages_domains.rb @@ -6,7 +6,7 @@ module Emails @domain = domain @project = domain.project - mail( + mail_with_locale( to: recipient.notification_email_for(@project.group), subject: subject("GitLab Pages domain '#{domain.domain}' has been enabled") ) @@ -16,7 +16,7 @@ module Emails @domain = domain @project = domain.project - mail( + mail_with_locale( to: recipient.notification_email_for(@project.group), subject: subject("GitLab Pages domain '#{domain.domain}' has been disabled") ) @@ -26,7 +26,7 @@ module Emails @domain = domain @project = domain.project - mail( + mail_with_locale( to: recipient.notification_email_for(@project.group), subject: subject("Verification succeeded for GitLab Pages domain '#{domain.domain}'") ) @@ -36,7 +36,7 @@ module Emails @domain = domain @project = domain.project - mail( + mail_with_locale( to: recipient.notification_email_for(@project.group), subject: subject("ACTION REQUIRED: Verification failed for GitLab Pages domain '#{domain.domain}'") ) @@ -47,7 +47,7 @@ module Emails @project = domain.project subject_text = _("ACTION REQUIRED: Something went wrong while obtaining the Let's Encrypt certificate for GitLab Pages domain '%{domain}'") % { domain: domain.domain } - mail( + mail_with_locale( to: recipient.notification_email_for(@project.group), subject: subject(subject_text) ) diff --git a/app/mailers/emails/profile.rb b/app/mailers/emails/profile.rb index 81f082b9680..8fe471a48f2 100644 --- a/app/mailers/emails/profile.rb +++ b/app/mailers/emails/profile.rb @@ -6,7 +6,7 @@ module Emails @current_user = @user = User.find(user_id) @target_url = user_url(@user) @token = token - mail(to: @user.notification_email_or_default, subject: subject("Account was created for you")) + mail_with_locale(to: @user.notification_email_or_default, subject: subject("Account was created for you")) end def instance_access_request_email(user, recipient) @@ -42,7 +42,7 @@ module Emails @current_user = @user = @key.user @target_url = user_url(@user) - mail(to: @user.notification_email_or_default, subject: subject("SSH key was added to your account")) + mail_with_locale(to: @user.notification_email_or_default, subject: subject("SSH key was added to your account")) end # rubocop: enable CodeReuse/ActiveRecord @@ -54,7 +54,7 @@ module Emails @current_user = @user = @gpg_key.user @target_url = user_url(@user) - mail(to: @user.notification_email_or_default, subject: subject("GPG key was added to your account")) + mail_with_locale(to: @user.notification_email_or_default, subject: subject("GPG key was added to your account")) end # rubocop: enable CodeReuse/ActiveRecord @@ -66,7 +66,7 @@ module Emails @token_name = token_name Gitlab::I18n.with_locale(@user.preferred_language) do - mail(to: @user.notification_email_or_default, subject: subject(_("A new personal access token has been created"))) + mail_with_locale(to: @user.notification_email_or_default, subject: subject(_("A new personal access token has been created"))) end end @@ -79,7 +79,7 @@ module Emails @days_to_expire = PersonalAccessToken::DAYS_TO_EXPIRE Gitlab::I18n.with_locale(@user.preferred_language) do - mail(to: @user.notification_email_or_default, subject: subject(_("Your personal access tokens will expire in %{days_to_expire} days or less") % { days_to_expire: @days_to_expire })) + mail_with_locale(to: @user.notification_email_or_default, subject: subject(_("Your personal access tokens will expire in %{days_to_expire} days or less") % { days_to_expire: @days_to_expire })) end end @@ -90,7 +90,7 @@ module Emails @target_url = profile_personal_access_tokens_url Gitlab::I18n.with_locale(@user.preferred_language) do - mail(to: @user.notification_email_or_default, subject: subject(_("Your personal access token has expired"))) + mail_with_locale(to: @user.notification_email_or_default, subject: subject(_("Your personal access token has expired"))) end end @@ -102,7 +102,7 @@ module Emails @target_url = profile_keys_url Gitlab::I18n.with_locale(@user.preferred_language) do - mail(to: @user.notification_email_or_default, subject: subject(_("Your SSH key has expired"))) + mail_with_locale(to: @user.notification_email_or_default, subject: subject(_("Your SSH key has expired"))) end end @@ -114,7 +114,7 @@ module Emails @target_url = profile_keys_url Gitlab::I18n.with_locale(@user.preferred_language) do - mail(to: @user.notification_email_or_default, subject: subject(_("Your SSH key is expiring soon."))) + mail_with_locale(to: @user.notification_email_or_default, subject: subject(_("Your SSH key is expiring soon."))) end end @@ -137,7 +137,7 @@ module Emails @user = user Gitlab::I18n.with_locale(@user.preferred_language) do - mail(to: @user.notification_email_or_default, subject: subject(_("Two-factor authentication disabled"))) + mail_with_locale(to: @user.notification_email_or_default, subject: subject(_("Two-factor authentication disabled"))) end end @@ -148,7 +148,7 @@ module Emails @email = email Gitlab::I18n.with_locale(@user.preferred_language) do - mail(to: @user.notification_email_or_default, subject: subject(_("New email address added"))) + mail_with_locale(to: @user.notification_email_or_default, subject: subject(_("New email address added"))) end end end diff --git a/app/mailers/emails/projects.rb b/app/mailers/emails/projects.rb index 5b8471abb0f..4bb624c27e9 100644 --- a/app/mailers/emails/projects.rb +++ b/app/mailers/emails/projects.rb @@ -7,28 +7,29 @@ module Emails @project = Project.find project_id @target_url = project_url(@project) @old_path_with_namespace = old_path_with_namespace - mail(to: @user.notification_email_for(@project.group), - subject: subject("Project was moved")) + mail_with_locale(to: @user.notification_email_for(@project.group), + subject: subject("Project was moved")) end def project_was_exported_email(current_user, project) @project = project - mail(to: current_user.notification_email_for(project.group), - subject: subject("Project was exported")) + mail_with_locale(to: current_user.notification_email_for(project.group), + subject: subject("Project was exported")) end def project_was_not_exported_email(current_user, project, errors) @project = project @errors = errors - mail(to: current_user.notification_email_for(@project.group), - subject: subject("Project export error")) + mail_with_locale(to: current_user.notification_email_for(@project.group), + subject: subject("Project export error")) end def repository_cleanup_success_email(project, user) @project = project @user = user - mail(to: user.notification_email_for(project.group), subject: subject("Project cleanup has completed")) + mail_with_locale(to: user.notification_email_for(project.group), + subject: subject("Project cleanup has completed")) end def repository_cleanup_failure_email(project, user, error) @@ -36,7 +37,7 @@ module Emails @user = user @error = error - mail(to: user.notification_email_for(project.group), subject: subject("Project cleanup failure")) + mail_with_locale(to: user.notification_email_for(project.group), subject: subject("Project cleanup failure")) end def repository_push_email(project_id, opts = {}) @@ -51,9 +52,9 @@ module Emails add_project_headers headers['X-GitLab-Author'] = @message.author_username - mail(from: sender(@message.author_id, send_from_user_email: @message.send_from_committer_email?), - reply_to: @message.reply_to, - subject: @message.subject) + mail_with_locale(from: sender(@message.author_id, send_from_user_email: @message.send_from_committer_email?), + reply_to: @message.reply_to, + subject: @message.subject) end def prometheus_alert_fired_email(project, user, alert) @@ -65,7 +66,7 @@ module Emails add_alert_headers subject_text = "Alert: #{@alert.email_title}" - mail(to: user.notification_email_for(@project.group), subject: subject(subject_text)) + mail_with_locale(to: user.notification_email_for(@project.group), subject: subject(subject_text)) end def inactive_project_deletion_warning_email(project, user, deletion_date) diff --git a/app/mailers/emails/releases.rb b/app/mailers/emails/releases.rb index 4875abafe8d..8fe93f59662 100644 --- a/app/mailers/emails/releases.rb +++ b/app/mailers/emails/releases.rb @@ -11,7 +11,7 @@ module Emails ) @recipient = User.find(user_id) - mail( + mail_with_locale( to: @recipient.notification_email_for(@project.group), subject: subject(release_email_subject) ) diff --git a/app/mailers/emails/remote_mirrors.rb b/app/mailers/emails/remote_mirrors.rb index 9cde53918b9..791ab7103b4 100644 --- a/app/mailers/emails/remote_mirrors.rb +++ b/app/mailers/emails/remote_mirrors.rb @@ -7,7 +7,7 @@ module Emails @project = @remote_mirror.project user = User.find(recipient_id) - mail(to: user.notification_email_for(@project.group), subject: subject('Remote mirror update failed')) + mail_with_locale(to: user.notification_email_for(@project.group), subject: subject('Remote mirror update failed')) end end end diff --git a/app/mailers/notify.rb b/app/mailers/notify.rb index ed7681e595f..5a3fc70832c 100644 --- a/app/mailers/notify.rb +++ b/app/mailers/notify.rb @@ -38,11 +38,11 @@ class Notify < ApplicationMailer helper InProductMarketingHelper def test_email(recipient_email, subject, body) - mail(to: recipient_email, - subject: subject, - body: body.html_safe, - content_type: 'text/html' - ) + mail_with_locale(to: recipient_email, + subject: subject, + body: body.html_safe, + content_type: 'text/html' + ) end # Splits "gitlab.corp.company.com" up into "gitlab.corp.company.com", @@ -139,7 +139,7 @@ class Notify < ApplicationMailer @reply_by_email = true end - mail(headers) + mail_with_locale(headers) end # `model` is used on EE code @@ -225,7 +225,7 @@ class Notify < ApplicationMailer end def email_with_layout(to:, subject:, layout: 'mailer') - mail(to: to, subject: subject) do |format| + mail_with_locale(to: to, subject: subject) do |format| format.html { render layout: layout } format.text { render layout: layout } end diff --git a/app/mailers/previews/notify_preview.rb b/app/mailers/previews/notify_preview.rb index be8d96012cc..15b6fec3548 100644 --- a/app/mailers/previews/notify_preview.rb +++ b/app/mailers/previews/notify_preview.rb @@ -60,8 +60,12 @@ class NotifyPreview < ActionMailer::Preview end end + def user_cap_reached + Notify.user_cap_reached(user.id).message + end + def new_mention_in_merge_request_email - Notify.new_mention_in_merge_request_email(user.id, issue.id, user.id).message + Notify.new_mention_in_merge_request_email(user.id, merge_request.id, user.id).message end def closed_issue_email @@ -97,7 +101,7 @@ class NotifyPreview < ActionMailer::Preview end def closed_merge_request_email - Notify.closed_merge_request_email(user.id, issue.id, user.id).message + Notify.closed_merge_request_email(user.id, merge_request.id, user.id).message end def merge_request_status_email @@ -205,14 +209,6 @@ class NotifyPreview < ActionMailer::Preview Notify.inactive_project_deletion_warning_email(project, user, '2022-04-22').message end - def user_auto_banned_instance_email - ::Notify.user_auto_banned_email(user.id, user.id, max_project_downloads: 5, within_seconds: 600).message - end - - def user_auto_banned_namespace_email - ::Notify.user_auto_banned_email(user.id, user.id, max_project_downloads: 5, within_seconds: 600, group: group).message - end - def verification_instructions_email Notify.verification_instructions_email(user.id, token: '123456', expires_in: 60).message end @@ -220,7 +216,7 @@ class NotifyPreview < ActionMailer::Preview private def project - @project ||= Project.find_by_full_path('gitlab-org/gitlab-test') + @project ||= Project.first end def issue diff --git a/app/mailers/repository_check_mailer.rb b/app/mailers/repository_check_mailer.rb index b8f990f26c8..17c36c19955 100644 --- a/app/mailers/repository_check_mailer.rb +++ b/app/mailers/repository_check_mailer.rb @@ -14,7 +14,7 @@ class RepositoryCheckMailer < ApplicationMailer "#{failed_count} projects failed their last repository check" end - mail( + mail_with_locale( to: User.admins.active.pluck(:email), subject: "GitLab Admin | #{@message}" ) |