From 573ca5a4b4d42c25af03c4da3e0b16f414fc4880 Mon Sep 17 00:00:00 2001 From: jimender2 <10927805-jimender2@users.noreply.gitlab.com> Date: Fri, 29 Nov 2024 15:25:55 +0000 Subject: [PATCH] Add gitlab standard layout to admin emails Changelog: changed --- app/mailers/emails/admin_notification.rb | 4 +-- app/mailers/emails/pages_domains.rb | 10 +++--- app/mailers/emails/profile.rb | 2 +- app/mailers/previews/notify_preview.rb | 40 +++++++++++++++++++---- spec/mailers/emails/pages_domains_spec.rb | 3 +- spec/mailers/emails/profile_spec.rb | 4 +++ spec/mailers/notify_spec.rb | 24 +++++++++++--- 7 files changed, 66 insertions(+), 21 deletions(-) diff --git a/app/mailers/emails/admin_notification.rb b/app/mailers/emails/admin_notification.rb index 35814eb5647b..44755e486acc 100644 --- a/app/mailers/emails/admin_notification.rb +++ b/app/mailers/emails/admin_notification.rb @@ -7,13 +7,13 @@ def send_admin_notification(user_id, subj, body) email = user.notification_email_or_default @unsubscribe_url = unsubscribe_url(email: Base64.urlsafe_encode64(email)) @body = body - mail_with_locale to: email, subject: subject(subj) + email_with_layout to: email, subject: subject(subj) end def send_unsubscribed_notification(user_id) user = User.find(user_id) email = user.notification_email_or_default - mail_with_locale to: email, subject: subject("Unsubscribed from GitLab administrator notifications") + email_with_layout to: email, subject: subject("Unsubscribed from GitLab administrator notifications") end end end diff --git a/app/mailers/emails/pages_domains.rb b/app/mailers/emails/pages_domains.rb index a0975952feec..7d0281b44b9a 100644 --- a/app/mailers/emails/pages_domains.rb +++ b/app/mailers/emails/pages_domains.rb @@ -6,7 +6,7 @@ def pages_domain_enabled_email(domain, recipient) @domain = domain @project = domain.project - mail_with_locale( + email_with_layout( to: recipient.notification_email_for(@project.group), subject: subject("GitLab Pages domain '#{domain.domain}' has been enabled") ) @@ -16,7 +16,7 @@ def pages_domain_disabled_email(domain, recipient) @domain = domain @project = domain.project - mail_with_locale( + email_with_layout( to: recipient.notification_email_for(@project.group), subject: subject("GitLab Pages domain '#{domain.domain}' has been disabled") ) @@ -26,7 +26,7 @@ def pages_domain_verification_succeeded_email(domain, recipient) @domain = domain @project = domain.project - mail_with_locale( + email_with_layout( to: recipient.notification_email_for(@project.group), subject: subject("Verification succeeded for GitLab Pages domain '#{domain.domain}'") ) @@ -36,7 +36,7 @@ def pages_domain_verification_failed_email(domain, recipient) @domain = domain @project = domain.project - mail_with_locale( + email_with_layout( to: recipient.notification_email_for(@project.group), subject: subject("ACTION REQUIRED: Verification failed for GitLab Pages domain '#{domain.domain}'") ) @@ -50,7 +50,7 @@ def pages_domain_auto_ssl_failed_email(domain, recipient) "ACTION REQUIRED: Something went wrong while obtaining the Let's Encrypt certificate for " \ "GitLab Pages domain '%{domain}'" ) % { domain: domain.domain } - mail_with_locale( + email_with_layout( 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 18ae1341bea6..8352a382f8c6 100644 --- a/app/mailers/emails/profile.rb +++ b/app/mailers/emails/profile.rb @@ -75,7 +75,7 @@ def bot_resource_access_token_about_to_expire_email(recipient, resource, token_n @reason_text = _('You are receiving this email because you are either an Owner or Maintainer of the project.') end - mail_with_locale( + email_with_layout( to: recipient.notification_email_or_default, subject: subject( safe_format( diff --git a/app/mailers/previews/notify_preview.rb b/app/mailers/previews/notify_preview.rb index 6a3f0d95fa57..e108d13b6336 100644 --- a/app/mailers/previews/notify_preview.rb +++ b/app/mailers/previews/notify_preview.rb @@ -201,17 +201,34 @@ def member_about_to_expire_email def pages_domain_enabled_email cleanup do - pages_domain = PagesDomain.new( - domain: 'my.example.com', - project: project, - verified_at: Time.now, - enabled_until: 1.week.from_now - ) - Notify.pages_domain_enabled_email(pages_domain, user).message end end + def pages_domain_disabled_email + cleanup do + Notify.pages_domain_disabled_email(pages_domain, user).message + end + end + + def pages_domain_verification_succeeded_email + cleanup do + Notify.pages_domain_verification_succeeded_email(pages_domain, user).message + end + end + + def pages_domain_verification_failed_email + cleanup do + Notify.pages_domain_verification_failed_email(pages_domain, user).message + end + end + + def pages_domain_auto_ssl_failed_email + cleanup do + Notify.pages_domain_auto_ssl_failed_email(pages_domain, user).message + end + end + def pipeline_success_email Notify.pipeline_success_email(pipeline, pipeline.user.try(:email)) end @@ -544,6 +561,15 @@ def cleanup email end + + def pages_domain + @pages_domain ||= PagesDomain.new( + domain: 'my.example.com', + project: project, + verified_at: Time.now, + enabled_until: 1.week.from_now + ) + end end NotifyPreview.prepend_mod_with('Preview::NotifyPreview') diff --git a/spec/mailers/emails/pages_domains_spec.rb b/spec/mailers/emails/pages_domains_spec.rb index 480e89decf1b..08362319626e 100644 --- a/spec/mailers/emails/pages_domains_spec.rb +++ b/spec/mailers/emails/pages_domains_spec.rb @@ -17,6 +17,8 @@ it_behaves_like 'an email sent from GitLab' it_behaves_like 'it should not have Gmail Actions links' it_behaves_like 'a user cannot unsubscribe through footer link' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'has the expected content' do aggregate_failures do @@ -65,7 +67,6 @@ subject { Notify.pages_domain_enabled_email(domain, user) } it_behaves_like 'a pages domain verification email' - it { is_expected.to have_body_text 'has been enabled' } end diff --git a/spec/mailers/emails/profile_spec.rb b/spec/mailers/emails/profile_spec.rb index 87de8b59ad6e..02cf1c20dca3 100644 --- a/spec/mailers/emails/profile_spec.rb +++ b/spec/mailers/emails/profile_spec.rb @@ -217,6 +217,8 @@ it_behaves_like 'it should not have Gmail Actions links' it_behaves_like 'a user cannot unsubscribe through footer link' it_behaves_like 'resource about to expire email' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'includes the email reason' do is_expected.to have_body_text _('You are receiving this email because you are an Owner of the Group.') @@ -246,6 +248,8 @@ it_behaves_like 'it should not have Gmail Actions links' it_behaves_like 'a user cannot unsubscribe through footer link' it_behaves_like 'resource about to expire email' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'includes the email reason' do is_expected.to have_body_text _('You are receiving this email because you are either an Owner or Maintainer of the project.') diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb index 2afefdc9d04a..9dcb0cdf103e 100644 --- a/spec/mailers/notify_spec.rb +++ b/spec/mailers/notify_spec.rb @@ -1887,11 +1887,10 @@ def invite_to_group(group, inviter:, user: nil) subject { @email = described_class.send_admin_notification(user.id, 'Admin announcement', 'Text') } - it 'is sent as the author' do - sender = subject.header[:from].addrs[0] - expect(sender.display_name).to eq("GitLab") - expect(sender.address).to eq(gitlab_sender) - end + it_behaves_like 'an email sent from GitLab' + it_behaves_like 'it should not have Gmail Actions links' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' it 'is sent to recipient' do is_expected.to deliver_to user.email @@ -1908,6 +1907,21 @@ def invite_to_group(group, inviter:, user: nil) end end + describe 'admin unsubscribe notification' do + let(:user) { create(:user) } + + subject { @email = described_class.send_unsubscribed_notification(user.id) } + + it_behaves_like 'an email sent from GitLab' + it_behaves_like 'it should not have Gmail Actions links' + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' + + it 'is sent to recipient' do + is_expected.to deliver_to user.email + end + end + describe 'confirmation if email changed' do let(:example_site_path) { root_path } let(:user) { create(:user, email: 'old-email@mail.com') } -- GitLab