diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
commit | b76ae638462ab0f673e5915986070518dd3f9ad3 (patch) | |
tree | bdab0533383b52873be0ec0eb4d3c66598ff8b91 /lib/gitlab/email | |
parent | 434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff) |
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'lib/gitlab/email')
12 files changed, 221 insertions, 21 deletions
diff --git a/lib/gitlab/email/handler/create_note_handler.rb b/lib/gitlab/email/handler/create_note_handler.rb index 28200643296..4fa2fe1724e 100644 --- a/lib/gitlab/email/handler/create_note_handler.rb +++ b/lib/gitlab/email/handler/create_note_handler.rb @@ -5,6 +5,7 @@ require 'gitlab/email/handler/reply_processing' # handles note/reply creation emails with these formats: # incoming+1234567890abcdef1234567890abcdef@incoming.gitlab.com +# Quoted material is _not_ stripped but appended as a `details` section module Gitlab module Email module Handler @@ -24,7 +25,7 @@ module Gitlab validate_permission!(:create_note) raise NoteableNotFoundError unless noteable - raise EmptyEmailError if message.blank? + raise EmptyEmailError if note_message.blank? verify_record!( record: create_note, @@ -47,7 +48,13 @@ module Gitlab end def create_note - sent_notification.create_reply(message) + sent_notification.create_reply(note_message) + end + + def note_message + return message unless sent_notification.noteable_type == "Issue" + + message_with_appended_reply end end end diff --git a/lib/gitlab/email/handler/reply_processing.rb b/lib/gitlab/email/handler/reply_processing.rb index d508cf9360e..a717509e24d 100644 --- a/lib/gitlab/email/handler/reply_processing.rb +++ b/lib/gitlab/email/handler/reply_processing.rb @@ -35,13 +35,20 @@ module Gitlab @message_with_reply ||= process_message(trim_reply: false) end + def message_with_appended_reply + @message_with_appended_reply ||= process_message(append_reply: true) + end + def process_message(**kwargs) - message = ReplyParser.new(mail, **kwargs).execute.strip + message, stripped_text = ReplyParser.new(mail, **kwargs).execute + message = message.strip + message_with_attachments = add_attachments(message) + # Support bot is specifically forbidden from using slash commands. + message = strip_quick_actions(message_with_attachments) + return message unless kwargs[:append_reply] - # Support bot is specifically forbidden - # from using slash commands. - strip_quick_actions(message_with_attachments) + append_reply(message, stripped_text) end def add_attachments(reply) @@ -92,10 +99,22 @@ module Gitlab def strip_quick_actions(content) return content unless author.support_bot? + quick_actions_extractor.redact_commands(content) + end + + def quick_actions_extractor command_definitions = ::QuickActions::InterpretService.command_definitions - extractor = ::Gitlab::QuickActions::Extractor.new(command_definitions) + ::Gitlab::QuickActions::Extractor.new(command_definitions) + end + + def append_reply(message, reply) + return message if message.blank? || reply.blank? + + # Do not append if message only contains slash commands + body, _commands = quick_actions_extractor.extract_commands(message) + return message if body.empty? - extractor.redact_commands(content) + message + "\n\n<details><summary>...</summary>\n\n#{reply}\n\n</details>" end end end diff --git a/lib/gitlab/email/message/in_product_marketing/admin_verify.rb b/lib/gitlab/email/message/in_product_marketing/admin_verify.rb new file mode 100644 index 00000000000..234b93594b5 --- /dev/null +++ b/lib/gitlab/email/message/in_product_marketing/admin_verify.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +module Gitlab + module Email + module Message + module InProductMarketing + class AdminVerify < Base + def subject_line + s_('InProductMarketing|Create a custom CI runner with just a few clicks') + end + + def tagline + nil + end + + def title + s_('InProductMarketing|Spin up an autoscaling runner in GitLab') + end + + def subtitle + s_('InProductMarketing|Use our AWS cloudformation template to spin up your runners in just a few clicks!') + end + + def body_line1 + '' + end + + def body_line2 + '' + end + + def cta_text + s_('InProductMarketing|Create a custom runner') + end + + def progress + super(track_name: 'Admin') + end + end + end + end + end +end diff --git a/lib/gitlab/email/message/in_product_marketing/base.rb b/lib/gitlab/email/message/in_product_marketing/base.rb index 89acc058a46..96551c89837 100644 --- a/lib/gitlab/email/message/in_product_marketing/base.rb +++ b/lib/gitlab/email/message/in_product_marketing/base.rb @@ -67,11 +67,11 @@ module Gitlab end end - def progress + def progress(current: series + 1, total: total_series, track_name: track.to_s.humanize) if Gitlab.com? - s_('InProductMarketing|This is email %{current_series} of %{total_series} in the %{track} series.') % { current_series: series + 1, total_series: total_series, track: track.to_s.humanize } + s_('InProductMarketing|This is email %{current_series} of %{total_series} in the %{track} series.') % { current_series: current, total_series: total, track: track_name } else - s_('InProductMarketing|This is email %{current_series} of %{total_series} in the %{track} series. To disable notification emails sent by your local GitLab instance, either contact your administrator or %{unsubscribe_link}.') % { current_series: series + 1, total_series: total_series, track: track.to_s.humanize, unsubscribe_link: unsubscribe_link } + s_('InProductMarketing|This is email %{current_series} of %{total_series} in the %{track} series. To disable notification emails sent by your local GitLab instance, either contact your administrator or %{unsubscribe_link}.') % { current_series: current, total_series: total, track: track_name, unsubscribe_link: unsubscribe_link } end end @@ -109,7 +109,7 @@ module Gitlab private def track - self.class.name.demodulize.downcase.to_sym + self.class.name.demodulize.underscore.to_sym end def total_series diff --git a/lib/gitlab/email/message/in_product_marketing/create.rb b/lib/gitlab/email/message/in_product_marketing/create.rb index 5d3cac0a121..4b0c4af4911 100644 --- a/lib/gitlab/email/message/in_product_marketing/create.rb +++ b/lib/gitlab/email/message/in_product_marketing/create.rb @@ -84,7 +84,7 @@ module Gitlab end def basics_link - link(s_('InProductMarketing|Git basics'), help_page_url('gitlab-basics/README')) + link(s_('InProductMarketing|Git basics'), help_page_url('gitlab-basics/index')) end def import_link diff --git a/lib/gitlab/email/message/in_product_marketing/team.rb b/lib/gitlab/email/message/in_product_marketing/team.rb index 46c2797e534..cf723ad5efd 100644 --- a/lib/gitlab/email/message/in_product_marketing/team.rb +++ b/lib/gitlab/email/message/in_product_marketing/team.rb @@ -73,6 +73,10 @@ module Gitlab s_('InProductMarketing|Invite your team now') ][series] end + + def progress + super(current: series + 2, total: 4) + end end end end diff --git a/lib/gitlab/email/message/in_product_marketing/team_short.rb b/lib/gitlab/email/message/in_product_marketing/team_short.rb new file mode 100644 index 00000000000..1d60a5fe4e5 --- /dev/null +++ b/lib/gitlab/email/message/in_product_marketing/team_short.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +module Gitlab + module Email + module Message + module InProductMarketing + class TeamShort < Base + def subject_line + s_('InProductMarketing|Team up in GitLab for greater efficiency') + end + + def tagline + nil + end + + def title + s_('InProductMarketing|Turn coworkers into collaborators') + end + + def subtitle + s_('InProductMarketing|Invite your team today to build better code (and processes) together') + end + + def body_line1 + '' + end + + def body_line2 + '' + end + + def cta_text + s_('InProductMarketing|Invite your colleagues today') + end + + def progress + super(total: 4, track_name: 'Team') + end + + def logo_path + 'mailers/in_product_marketing/team-0.png' + end + end + end + end + end +end diff --git a/lib/gitlab/email/message/in_product_marketing/trial.rb b/lib/gitlab/email/message/in_product_marketing/trial.rb index d87dc5c1b81..222046a3966 100644 --- a/lib/gitlab/email/message/in_product_marketing/trial.rb +++ b/lib/gitlab/email/message/in_product_marketing/trial.rb @@ -68,6 +68,10 @@ module Gitlab s_('InProductMarketing|Start your trial now!') ][series] end + + def progress + super(current: series + 2, total: 4) + end end end end diff --git a/lib/gitlab/email/message/in_product_marketing/trial_short.rb b/lib/gitlab/email/message/in_product_marketing/trial_short.rb new file mode 100644 index 00000000000..0fcd3fde4a6 --- /dev/null +++ b/lib/gitlab/email/message/in_product_marketing/trial_short.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +module Gitlab + module Email + module Message + module InProductMarketing + class TrialShort < Base + def subject_line + s_('InProductMarketing|Be a DevOps hero') + end + + def tagline + nil + end + + def title + s_('InProductMarketing|Expand your DevOps journey with a free GitLab trial') + end + + def subtitle + s_('InProductMarketing|Start your trial today to experience single application success and discover all the features of GitLab Ultimate for free!') + end + + def body_line1 + '' + end + + def body_line2 + '' + end + + def cta_text + s_('InProductMarketing|Start a trial') + end + + def progress + super(total: 4, track_name: 'Trial') + end + + def logo_path + 'mailers/in_product_marketing/trial-0.png' + end + end + end + end + end +end diff --git a/lib/gitlab/email/message/in_product_marketing/verify.rb b/lib/gitlab/email/message/in_product_marketing/verify.rb index 88140c67804..e731c65121e 100644 --- a/lib/gitlab/email/message/in_product_marketing/verify.rb +++ b/lib/gitlab/email/message/in_product_marketing/verify.rb @@ -72,7 +72,7 @@ module Gitlab end def quick_start_link - link(s_('InProductMarketing|quick start guide'), help_page_url('ci/quick_start/README')) + link(s_('InProductMarketing|quick start guide'), help_page_url('ci/quick_start/index')) end def performance_link diff --git a/lib/gitlab/email/reply_parser.rb b/lib/gitlab/email/reply_parser.rb index 7579f3d8680..0f0f4800062 100644 --- a/lib/gitlab/email/reply_parser.rb +++ b/lib/gitlab/email/reply_parser.rb @@ -6,20 +6,17 @@ module Gitlab class ReplyParser attr_accessor :message - def initialize(message, trim_reply: true) + def initialize(message, trim_reply: true, append_reply: false) @message = message @trim_reply = trim_reply + @append_reply = append_reply end def execute body = select_body(message) encoding = body.encoding - - if @trim_reply - body = EmailReplyTrimmer.trim(body) - end - + body, stripped_text = EmailReplyTrimmer.trim(body, @append_reply) if @trim_reply return '' unless body # not using /\s+$/ here because that deletes empty lines @@ -30,7 +27,10 @@ module Gitlab # so we detect it manually here. return "" if body.lines.all? { |l| l.strip.empty? || l.start_with?('>') } - body.force_encoding(encoding).encode("UTF-8") + encoded_body = body.force_encoding(encoding).encode("UTF-8") + return encoded_body unless @append_reply + + [encoded_body, stripped_text.force_encoding(encoding).encode("UTF-8")] end private diff --git a/lib/gitlab/email/smtp_config.rb b/lib/gitlab/email/smtp_config.rb new file mode 100644 index 00000000000..c9deb3fe324 --- /dev/null +++ b/lib/gitlab/email/smtp_config.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module Gitlab + module Email + class SmtpConfig + def self.encrypted_secrets + Settings.encrypted(Gitlab.config.gitlab.email_smtp_secret_file) + end + + def self.secrets + self.new + end + + def initialize + @secrets ||= self.class.encrypted_secrets.config + rescue StandardError => e + Gitlab::AppLogger.error "SMTP encrypted secrets are invalid: #{e.inspect}" + end + + def username + @secrets&.fetch(:user_name, nil)&.chomp + end + + def password + @secrets&.fetch(:password, nil)&.chomp + end + end + end +end |