From 25297399600c9fefe08a4552ce5f17eaf1ae67e1 Mon Sep 17 00:00:00 2001 From: eugielimpin <elimpin@gitlab.com> Date: Tue, 7 Dec 2021 16:59:40 +0800 Subject: [PATCH] Move account validation email under EE Account validation email will only be sent in EE. --- app/mailers/emails/in_product_marketing.rb | 8 +--- .../mailers/ee/emails/in_product_marketing.rb | 13 ++++++ ee/app/mailers/ee/notify.rb | 1 + .../email/message/account_validation.rb | 0 .../email/message/account_validation_spec.rb | 0 .../emails/in_product_marketing_spec.rb | 40 +++++++++++++++++++ .../emails/in_product_marketing_spec.rb | 31 -------------- 7 files changed, 56 insertions(+), 37 deletions(-) create mode 100644 ee/app/mailers/ee/emails/in_product_marketing.rb rename {lib => ee/lib}/gitlab/email/message/account_validation.rb (100%) rename {spec => ee/spec}/lib/gitlab/email/message/account_validation_spec.rb (100%) create mode 100644 ee/spec/mailers/emails/in_product_marketing_spec.rb diff --git a/app/mailers/emails/in_product_marketing.rb b/app/mailers/emails/in_product_marketing.rb index ba94c0c8cacdd..317e154535018 100644 --- a/app/mailers/emails/in_product_marketing.rb +++ b/app/mailers/emails/in_product_marketing.rb @@ -21,12 +21,6 @@ def in_product_marketing_email(recipient_id, group_id, track, series) mail_to(to: email, subject: @message.subject_line) end - def account_validation_email(pipeline, recipient_email) - @message = Gitlab::Email::Message::AccountValidation.new(pipeline) - - mail_to(to: recipient_email, subject: @message.subject_line) - end - private def mail_to(to:, subject:) @@ -47,3 +41,5 @@ def mail_to(to:, subject:) end end end + +Emails::InProductMarketing.prepend_mod diff --git a/ee/app/mailers/ee/emails/in_product_marketing.rb b/ee/app/mailers/ee/emails/in_product_marketing.rb new file mode 100644 index 0000000000000..08f6076954a6e --- /dev/null +++ b/ee/app/mailers/ee/emails/in_product_marketing.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module EE + module Emails + module InProductMarketing + def account_validation_email(pipeline, recipient_email) + @message = ::Gitlab::Email::Message::AccountValidation.new(pipeline) + + mail_to(to: recipient_email, subject: @message.subject_line) + end + end + end +end diff --git a/ee/app/mailers/ee/notify.rb b/ee/app/mailers/ee/notify.rb index 7556285c53739..95059a83bcb52 100644 --- a/ee/app/mailers/ee/notify.rb +++ b/ee/app/mailers/ee/notify.rb @@ -14,6 +14,7 @@ module Notify include ::Emails::UserCap include ::Emails::OncallRotation include ::Emails::GroupMemberships + include ::Emails::InProductMarketing end attr_reader :group diff --git a/lib/gitlab/email/message/account_validation.rb b/ee/lib/gitlab/email/message/account_validation.rb similarity index 100% rename from lib/gitlab/email/message/account_validation.rb rename to ee/lib/gitlab/email/message/account_validation.rb diff --git a/spec/lib/gitlab/email/message/account_validation_spec.rb b/ee/spec/lib/gitlab/email/message/account_validation_spec.rb similarity index 100% rename from spec/lib/gitlab/email/message/account_validation_spec.rb rename to ee/spec/lib/gitlab/email/message/account_validation_spec.rb diff --git a/ee/spec/mailers/emails/in_product_marketing_spec.rb b/ee/spec/mailers/emails/in_product_marketing_spec.rb new file mode 100644 index 0000000000000..8f9db47122339 --- /dev/null +++ b/ee/spec/mailers/emails/in_product_marketing_spec.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +require 'spec_helper' +require 'email_spec' + +RSpec.describe Emails::InProductMarketing do + include EmailSpec::Matchers + include Gitlab::Routing.url_helpers + + let_it_be(:user) { create(:user) } + + describe '#account_validation_email' do + let_it_be(:namespace) { create(:namespace) } + let_it_be(:project) { create(:project, :repository, namespace: namespace) } + let_it_be(:pipeline) { create(:ci_pipeline, project: project) } + + subject { Notify.account_validation_email(pipeline, user.notification_email_or_default) } + + it 'sends to the right user with a link to unsubscribe' do + expect(subject).to deliver_to(user.notification_email_or_default) + end + + it 'has the correct subject and content' do + message = Gitlab::Email::Message::AccountValidation.new(pipeline) + cta_url = project_pipeline_url(pipeline.project, pipeline) + cta2_url = 'https://docs.gitlab.com/runner/install/' + + aggregate_failures do + is_expected.to have_subject(message.subject_line) + is_expected.to have_body_text(message.title) + is_expected.to have_body_text(message.body_line1) + is_expected.to have_body_text(CGI.unescapeHTML(message.body_line2)) + is_expected.to have_body_text(CGI.unescapeHTML(message.cta_link)) + is_expected.to have_body_text(CGI.unescapeHTML(message.cta2_link)) + is_expected.to have_body_text(cta_url) + is_expected.to have_body_text(cta2_url) + end + end + end +end diff --git a/spec/mailers/emails/in_product_marketing_spec.rb b/spec/mailers/emails/in_product_marketing_spec.rb index f6f8c187e80da..720e6f101a8e2 100644 --- a/spec/mailers/emails/in_product_marketing_spec.rb +++ b/spec/mailers/emails/in_product_marketing_spec.rb @@ -108,35 +108,4 @@ end end end - - describe '#account_validation_email' do - let_it_be(:namespace) { create(:namespace) } - let_it_be(:project) { create(:project, :repository, namespace: namespace) } - let_it_be(:pipeline) { create(:ci_pipeline, project: project) } - - subject { Notify.account_validation_email(pipeline, user.notification_email_or_default) } - - it 'sends to the right user with a link to unsubscribe' do - expect(subject).to deliver_to(user.notification_email_or_default) - end - - it_behaves_like 'has custom headers when on gitlab.com' - - it 'has the correct subject and content' do - message = Gitlab::Email::Message::AccountValidation.new(pipeline) - cta_url = project_pipeline_url(pipeline.project, pipeline) - cta2_url = 'https://docs.gitlab.com/runner/install/' - - aggregate_failures do - is_expected.to have_subject(message.subject_line) - is_expected.to have_body_text(message.title) - is_expected.to have_body_text(message.body_line1) - is_expected.to have_body_text(CGI.unescapeHTML(message.body_line2)) - is_expected.to have_body_text(CGI.unescapeHTML(message.cta_link)) - is_expected.to have_body_text(CGI.unescapeHTML(message.cta2_link)) - is_expected.to have_body_text(cta_url) - is_expected.to have_body_text(cta2_url) - end - end - end end -- GitLab