diff options
Diffstat (limited to 'app/mailers')
-rw-r--r-- | app/mailers/devise_mailer.rb | 4 | ||||
-rw-r--r-- | app/mailers/emails/members.rb | 51 | ||||
-rw-r--r-- | app/mailers/emails/profile.rb | 26 | ||||
-rw-r--r-- | app/mailers/emails/projects.rb | 9 | ||||
-rw-r--r-- | app/mailers/emails/service_desk.rb | 6 | ||||
-rw-r--r-- | app/mailers/previews/devise_mailer_preview.rb | 4 |
6 files changed, 51 insertions, 49 deletions
diff --git a/app/mailers/devise_mailer.rb b/app/mailers/devise_mailer.rb index a02670aed90..61a23520d54 100644 --- a/app/mailers/devise_mailer.rb +++ b/app/mailers/devise_mailer.rb @@ -13,6 +13,10 @@ class DeviseMailer < Devise::Mailer devise_mail(record, :password_change_by_admin, opts) end + def user_admin_approval(record, opts = {}) + devise_mail(record, :user_admin_approval, opts) + end + protected def subject_for(key) diff --git a/app/mailers/emails/members.rb b/app/mailers/emails/members.rb index 57e4c7df440..0b5a8dfdc24 100644 --- a/app/mailers/emails/members.rb +++ b/app/mailers/emails/members.rb @@ -51,34 +51,20 @@ module Emails return unless member_exists? - subject_line = subject("Invitation to join the #{member_source.human_name} #{member_source.model_name.singular}") - - if member.invite_to_unknown_user? && Feature.enabled?(:invite_email_experiment) - subject_line = subject("#{member.created_by.name} invited you to join GitLab") if member.created_by - @invite_url_params = { new_user_invite: 'experiment' } - - member_email_with_layout( - to: member.invite_email, - subject: subject_line, - template: 'member_invited_email_experiment', - layout: 'experiment_mailer' - ) - - Gitlab::Tracking.event(Gitlab::Experimentation::EXPERIMENTS[:invite_email][:tracking_category], 'sent', property: 'experiment_group') - else - @invite_url_params = member.invite_to_unknown_user? ? { new_user_invite: 'control' } : {} - - member_email_with_layout( - to: member.invite_email, - subject: subject_line - ) - - if member.invite_to_unknown_user? - Gitlab::Tracking.event(Gitlab::Experimentation::EXPERIMENTS[:invite_email][:tracking_category], 'sent', property: 'control_group') + subject_line = + if member.created_by + subject(s_("MemberInviteEmail|%{member_name} invited you to join GitLab") % { member_name: member.created_by.name }) + else + subject(s_("MemberInviteEmail|Invitation to join the %{project_or_group} %{project_or_group_name}") % { project_or_group: member_source.human_name, project_or_group_name: member_source.model_name.singular }) end - end - if member.invite_to_unknown_user? && Gitlab::Experimentation.enabled?(:invitation_reminders) + member_email_with_layout( + to: member.invite_email, + subject: subject_line, + layout: 'unknown_user_mailer' + ) + + if Gitlab::Experimentation.enabled?(:invitation_reminders) Gitlab::Tracking.event( Gitlab::Experimentation.experiment(:invitation_reminders).tracking_category, 'sent', @@ -105,7 +91,7 @@ module Emails subject_line = subjects[reminder_index] % { inviter: member.created_by.name } member_email_with_layout( - layout: 'experiment_mailer', + layout: 'unknown_user_mailer', to: member.invite_email, subject: subject(subject_line) ) @@ -162,15 +148,10 @@ module Emails @member_source_type.classify.constantize end - def member_email_with_layout(to:, subject:, template: nil, layout: 'mailer') + def member_email_with_layout(to:, subject:, layout: 'mailer') mail(to: to, subject: subject) do |format| - if template - format.html { render template, layout: layout } - format.text { render template, layout: layout } - else - format.html { render layout: layout } - format.text { render layout: layout } - end + format.html { render layout: layout } + format.text { render layout: layout } end end end diff --git a/app/mailers/emails/profile.rb b/app/mailers/emails/profile.rb index 96cf3571968..6f44b63f8d0 100644 --- a/app/mailers/emails/profile.rb +++ b/app/mailers/emails/profile.rb @@ -9,6 +9,15 @@ module Emails mail(to: @user.notification_email, subject: subject("Account was created for you")) end + def instance_access_request_email(user, recipient) + @user = user + @recipient = recipient + + profile_email_with_layout( + to: recipient.notification_email, + subject: subject(_("GitLab Account Request"))) + end + # rubocop: disable CodeReuse/ActiveRecord def new_ssh_key_email(key_id) @key = Key.find_by(id: key_id) @@ -63,13 +72,9 @@ module Emails @target_url = edit_profile_password_url Gitlab::I18n.with_locale(@user.preferred_language) do - mail( + profile_email_with_layout( to: @user.notification_email, - subject: subject(_("%{host} sign-in from new location") % { host: Gitlab.config.gitlab.host }) - ) do |format| - format.html { render layout: 'mailer' } - format.text { render layout: 'mailer' } - end + subject: subject(_("%{host} sign-in from new location") % { host: Gitlab.config.gitlab.host })) end end @@ -82,6 +87,15 @@ module Emails mail(to: @user.notification_email, subject: subject(_("Two-factor authentication disabled"))) end end + + private + + def profile_email_with_layout(to:, subject:, layout: 'mailer') + mail(to: to, subject: subject) do |format| + format.html { render layout: layout } + format.text { render layout: layout } + end + end end end diff --git a/app/mailers/emails/projects.rb b/app/mailers/emails/projects.rb index 17ef8b41e79..a4b7b140169 100644 --- a/app/mailers/emails/projects.rb +++ b/app/mailers/emails/projects.rb @@ -56,12 +56,9 @@ module Emails subject: @message.subject) end - def prometheus_alert_fired_email(project_id, user_id, alert_attributes) - @project = ::Project.find(project_id) - user = ::User.find(user_id) - - @alert = AlertManagement::Alert.new(alert_attributes.with_indifferent_access).present - return unless @alert.parsed_payload.has_required_attributes? + def prometheus_alert_fired_email(project, user, alert) + @project = project + @alert = alert.present subject_text = "Alert: #{@alert.email_title}" mail(to: user.notification_email_for(@project.group), subject: subject(subject_text)) diff --git a/app/mailers/emails/service_desk.rb b/app/mailers/emails/service_desk.rb index 29fe608472d..fa646487819 100644 --- a/app/mailers/emails/service_desk.rb +++ b/app/mailers/emails/service_desk.rb @@ -58,10 +58,12 @@ module Emails def template_content(email_type) template = Gitlab::Template::ServiceDeskTemplate.find(email_type, @project) - 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 nil end diff --git a/app/mailers/previews/devise_mailer_preview.rb b/app/mailers/previews/devise_mailer_preview.rb index 3b9ef0d3ac0..68f281f825e 100644 --- a/app/mailers/previews/devise_mailer_preview.rb +++ b/app/mailers/previews/devise_mailer_preview.rb @@ -24,6 +24,10 @@ class DeviseMailerPreview < ActionMailer::Preview DeviseMailer.password_change(unsaved_user, {}) end + def user_admin_approval + DeviseMailer.user_admin_approval(unsaved_user, {}) + end + private def unsaved_user |