diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 19:05:49 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 19:05:49 +0300 |
commit | 43a25d93ebdabea52f99b05e15b06250cd8f07d7 (patch) | |
tree | dceebdc68925362117480a5d672bcff122fb625b /app/mailers | |
parent | 20c84b99005abd1c82101dfeff264ac50d2df211 (diff) |
Add latest changes from gitlab-org/gitlab@16-0-stable-eev16.0.0-rc42
Diffstat (limited to 'app/mailers')
-rw-r--r-- | app/mailers/emails/issues.rb | 113 | ||||
-rw-r--r-- | app/mailers/emails/profile.rb | 15 | ||||
-rw-r--r-- | app/mailers/emails/projects.rb | 32 | ||||
-rw-r--r-- | app/mailers/emails/service_desk.rb | 133 | ||||
-rw-r--r-- | app/mailers/emails/shared.rb | 20 | ||||
-rw-r--r-- | app/mailers/emails/work_items.rb | 19 | ||||
-rw-r--r-- | app/mailers/notify.rb | 21 | ||||
-rw-r--r-- | app/mailers/previews/notify_preview.rb | 105 |
8 files changed, 387 insertions, 71 deletions
diff --git a/app/mailers/emails/issues.rb b/app/mailers/emails/issues.rb index 58843435fa0..0328d262dc7 100644 --- a/app/mailers/emails/issues.rb +++ b/app/mailers/emails/issues.rb @@ -5,18 +5,32 @@ module Emails def new_issue_email(recipient_id, issue_id, reason = nil) setup_issue_mail(issue_id, recipient_id) - mail_new_thread(@issue, issue_thread_options(@issue.author_id, reason)) + mail_new_thread( + @issue, + issue_thread_options( + @issue.author_id, + reason, + confidentiality: @issue.confidential? + ) + ) end def issue_due_email(recipient_id, issue_id, reason = nil) setup_issue_mail(issue_id, recipient_id) - mail_answer_thread(@issue, issue_thread_options(@issue.author_id, reason)) + mail_answer_thread(@issue, issue_thread_options(@issue.author_id, reason, confidentiality: @issue.confidential?)) end def new_mention_in_issue_email(recipient_id, issue_id, updated_by_user_id, reason = nil) setup_issue_mail(issue_id, recipient_id) - mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, reason)) + mail_answer_thread( + @issue, + issue_thread_options( + updated_by_user_id, + reason, + confidentiality: @issue.confidential? + ) + ) end # rubocop: disable CodeReuse/ActiveRecord @@ -26,7 +40,14 @@ module Emails @previous_assignees = [] @previous_assignees = User.where(id: previous_assignee_ids) if previous_assignee_ids.any? - mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, reason)) + mail_answer_thread( + @issue, + issue_thread_options( + updated_by_user_id, + reason, + confidentiality: @issue.confidential? + ) + ) end # rubocop: enable CodeReuse/ActiveRecord @@ -35,7 +56,14 @@ module Emails @updated_by = User.find(updated_by_user_id) - mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, reason)) + mail_answer_thread( + @issue, + issue_thread_options( + updated_by_user_id, + reason, + confidentiality: @issue.confidential? + ) + ) end def relabeled_issue_email(recipient_id, issue_id, label_names, updated_by_user_id, reason = nil) @@ -43,13 +71,27 @@ module Emails @label_names = label_names @labels_url = project_labels_url(@project) - mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, reason)) + mail_answer_thread( + @issue, + issue_thread_options( + updated_by_user_id, + reason, + confidentiality: @issue.confidential? + ) + ) end def removed_milestone_issue_email(recipient_id, issue_id, updated_by_user_id, reason = nil) setup_issue_mail(issue_id, recipient_id) - mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, reason)) + mail_answer_thread( + @issue, + issue_thread_options( + updated_by_user_id, + reason, + confidentiality: @issue.confidential? + ) + ) end def changed_milestone_issue_email(recipient_id, issue_id, milestone, updated_by_user_id, reason = nil) @@ -57,9 +99,14 @@ module Emails @milestone = milestone @milestone_url = milestone_url(@milestone) - mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, reason).merge({ - template_name: 'changed_milestone_email' - })) + mail_answer_thread( + @issue, + issue_thread_options( + updated_by_user_id, + reason, + confidentiality: @issue.confidential? + ).merge({ template_name: 'changed_milestone_email' }) + ) end def issue_status_changed_email(recipient_id, issue_id, status, updated_by_user_id, reason = nil) @@ -67,7 +114,14 @@ module Emails @issue_status = status @updated_by = User.find(updated_by_user_id) - mail_answer_thread(@issue, issue_thread_options(updated_by_user_id, reason)) + mail_answer_thread( + @issue, + issue_thread_options( + updated_by_user_id, + reason, + confidentiality: @issue.confidential? + ) + ) end def issue_moved_email(recipient, issue, new_issue, updated_by_user, reason = nil) @@ -76,7 +130,14 @@ module Emails @new_issue = new_issue @new_project = new_issue.project @can_access_project = recipient.can?(:read_project, @new_project) - mail_answer_thread(issue, issue_thread_options(updated_by_user.id, reason)) + mail_answer_thread( + issue, + issue_thread_options( + updated_by_user.id, + reason, + confidentiality: @issue.confidential? + ) + ) end def issue_cloned_email(recipient, issue, new_issue, updated_by_user, reason = nil) @@ -86,7 +147,14 @@ module Emails @issue = issue @new_issue = new_issue @can_access_project = recipient.can?(:read_project, @new_issue.project) - mail_answer_thread(issue, issue_thread_options(updated_by_user.id, reason)) + mail_answer_thread( + issue, + issue_thread_options( + updated_by_user.id, + reason, + confidentiality: @issue.confidential? + ) + ) end def import_issues_csv_email(user_id, project_id, results) @@ -100,18 +168,7 @@ module Emails end def issues_csv_email(user, project, csv_data, export_status) - @project = project - @count = export_status.fetch(:rows_expected) - @written_count = export_status.fetch(:rows_written) - @truncated = export_status.fetch(:truncated) - @size_limit = ActiveSupport::NumberHelper - .number_to_human_size(ExportCsv::BaseService::TARGET_FILESIZE) - - filename = "#{project.full_path.parameterize}_issues_#{Date.today.iso8601}.csv" - attachments[filename] = { content: csv_data, mime_type: 'text/csv' } - email_with_layout( - to: user.notification_email_for(@project.group), - subject: subject("Exported issues")) + csv_email(user, project, csv_data, export_status, 'issues') end private @@ -126,12 +183,14 @@ module Emails @sent_notification = SentNotification.record(@issue, recipient_id, reply_key) end - def issue_thread_options(sender_id, reason) + def issue_thread_options(sender_id, reason, confidentiality: false) + confidentiality = false if confidentiality.nil? { from: sender(sender_id), to: @recipient.notification_email_for(@project.group), subject: subject("#{@issue.title} (##{@issue.iid})"), - 'X-GitLab-NotificationReason' => reason + 'X-GitLab-NotificationReason' => reason, + 'X-GitLab-ConfidentialIssue' => confidentiality } end end diff --git a/app/mailers/emails/profile.rb b/app/mailers/emails/profile.rb index 5b1750400d8..54a4c4be6a8 100644 --- a/app/mailers/emails/profile.rb +++ b/app/mailers/emails/profile.rb @@ -153,7 +153,7 @@ module Emails Gitlab::I18n.with_locale(@user.preferred_language) do email_with_layout( to: @user.notification_email_or_default, - subject: subject(_("Attempted sign in to %{host} using a wrong two-factor authentication code") % { host: Gitlab.config.gitlab.host })) + subject: subject(_("Attempted sign in to %{host} using an incorrect verification code") % { host: Gitlab.config.gitlab.host })) end end @@ -177,6 +177,19 @@ module Emails mail_with_locale(to: @user.notification_email_or_default, subject: subject(_("New email address added"))) end end + + def new_achievement_email(user, achievement) + return unless user&.active? + + @user = user + @achievement = achievement + + Gitlab::I18n.with_locale(@user.preferred_language) do + email_with_layout( + to: @user.notification_email_or_default, + subject: subject(s_("Achievements|%{namespace_full_path} awarded you the %{achievement_name} achievement") % { namespace_full_path: @achievement.namespace.full_path, achievement_name: @achievement.name })) + end + end end end diff --git a/app/mailers/emails/projects.rb b/app/mailers/emails/projects.rb index 4bb624c27e9..63eb4eb8fd8 100644 --- a/app/mailers/emails/projects.rb +++ b/app/mailers/emails/projects.rb @@ -7,29 +7,37 @@ module Emails @project = Project.find project_id @target_url = project_url(@project) @old_path_with_namespace = old_path_with_namespace - mail_with_locale(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_with_locale(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_with_locale(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_with_locale(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) @@ -52,9 +60,11 @@ module Emails add_project_headers headers['X-GitLab-Author'] = @message.author_username - 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) + 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) diff --git a/app/mailers/emails/service_desk.rb b/app/mailers/emails/service_desk.rb index 1295f978049..c627f4633e4 100644 --- a/app/mailers/emails/service_desk.rb +++ b/app/mailers/emails/service_desk.rb @@ -20,15 +20,24 @@ module Emails sender_name: @service_desk_setting&.outgoing_name, sender_email: service_desk_sender_email_address ) - options = service_desk_options(email_sender, 'thank_you', @issue.external_author) - .merge(subject: "Re: #{subject_base}") - inject_service_desk_custom_email(mail_new_thread(@issue, options)) + options = { + from: email_sender, + to: @issue.external_author, + subject: "Re: #{subject_base}", + **service_desk_template_content_options('thank_you') + } + + mail_new_thread(@issue, options) + inject_service_desk_custom_email end def service_desk_new_note_email(issue_id, note_id, recipient) @note = Note.find(note_id) + setup_service_desk_mail(issue_id) + # Prepare uploads for text replacement in markdown content + setup_service_desk_attachments email_sender = sender( @note.author_id, @@ -36,11 +45,74 @@ module Emails sender_email: service_desk_sender_email_address ) - add_uploads_as_attachments if Feature.enabled?(:service_desk_new_note_email_native_attachments, @note.project) - options = service_desk_options(email_sender, 'new_note', recipient) - .merge(subject: subject_base) + options = { + from: email_sender, + to: recipient, + subject: subject_base, + **service_desk_template_content_options('new_note') + } - inject_service_desk_custom_email(mail_answer_thread(@issue, options)) + mail_answer_thread(@issue, options) + # Add attachments after email init to guide ActiveMailer + # to choose the correct multipart content types + add_uploads_as_attachments + inject_service_desk_custom_email + end + + def service_desk_custom_email_verification_email(service_desk_setting) + @service_desk_setting = service_desk_setting + + email_sender = sender( + User.support_bot.id, + send_from_user_email: false, + sender_name: @service_desk_setting.outgoing_name, + sender_email: @service_desk_setting.custom_email + ) + + @verification_token = @service_desk_setting.custom_email_verification.token + + subject = format(s_("Notify|Verify custom email address %{email} for %{project_name}"), + email: @service_desk_setting.custom_email, + project_name: @service_desk_setting.project.name + ) + + options = { + from: email_sender, + to: @service_desk_setting.custom_email_address_for_verification, + subject: subject, + content_type: "text/plain; charset=UTF-8" + } + # Outgoing emails from GitLab usually have this set to true. + # Service Desk email ingestion ignores auto generated emails. + headers["Auto-Submitted"] = "no" + + mail_with_locale(options) + inject_service_desk_custom_email(force: true) + end + + def service_desk_verification_triggered_email(service_desk_setting, recipient) + @service_desk_setting = service_desk_setting + @triggerer = @service_desk_setting.custom_email_verification.triggerer + @smtp_address = @service_desk_setting.custom_email_credential.smtp_address + + subject = format(s_("Notify|Verification for custom email %{email} for %{project_name} triggered"), + email: @service_desk_setting.custom_email, + project_name: @service_desk_setting.project.name + ) + + email_with_layout(to: recipient, subject: subject) + end + + def service_desk_verification_result_email(service_desk_setting, recipient) + @service_desk_setting = service_desk_setting + @verification = @service_desk_setting.custom_email_verification + + subject = format(s_("Notify|Verification result for custom email %{email} for %{project_name}"), + email: @service_desk_setting.custom_email, + project_name: @service_desk_setting.project.name + ) + + email_with_layout(to: recipient, subject: subject) end private @@ -55,22 +127,20 @@ module Emails @sent_notification = SentNotification.record(@issue, @support_bot.id, reply_key) end - def service_desk_options(email_sender, email_type, recipient) - { - from: email_sender, - to: recipient - }.tap do |options| - next unless template_body = template_content(email_type) + def service_desk_template_content_options(email_type) + return {} unless template_body = template_content(email_type) - options[:body] = template_body - options[:content_type] = 'text/html' unless attachments.present? - end + { + body: template_body, + content_type: 'text/html; charset=UTF-8' + } end - def inject_service_desk_custom_email(mail) - return mail unless service_desk_custom_email_enabled? + def inject_service_desk_custom_email(force: false) + return mail if !service_desk_custom_email_enabled? && !force + return mail unless @service_desk_setting.custom_email_credential.present? - mail.delivery_method(::Mail::SMTP, @service_desk_setting.custom_email_delivery_options) + mail.delivery_method(::Mail::SMTP, @service_desk_setting.custom_email_credential.delivery_options) end def service_desk_custom_email_enabled? @@ -101,6 +171,7 @@ module Emails .gsub(/%\{\s*ISSUE_ID\s*\}/, issue_id) .gsub(/%\{\s*ISSUE_PATH\s*\}/, issue_path) .gsub(/%\{\s*NOTE_TEXT\s*\}/, note_text) + .gsub(/%\{\s*ISSUE_DESCRIPTION\s*\}/, issue_description) .gsub(/%\{\s*SYSTEM_HEADER\s*\}/, text_header_message.to_s) .gsub(/%\{\s*SYSTEM_FOOTER\s*\}/, text_footer_message.to_s) .gsub(/%\{\s*UNSUBSCRIBE_URL\s*\}/, unsubscribe_sent_notification_url(@sent_notification)) @@ -119,24 +190,40 @@ module Emails @note&.note.to_s end + def issue_description + @issue.description_html.to_s + end + def subject_base "#{@issue.title} (##{@issue.iid})" end - def add_uploads_as_attachments + def setup_service_desk_attachments + @uploads_to_attach = [] + # Filepaths we should replace in markdown content + @uploads_as_attachments = [] + + return unless Feature.enabled?(:service_desk_new_note_email_native_attachments, @note.project) + uploaders = find_uploaders_for(@note) - return unless uploaders.present? + return if uploaders.nil? return if uploaders.sum(&:size) > EMAIL_ATTACHMENTS_SIZE_LIMIT - @uploads_as_attachments = [] uploaders.each do |uploader| - attachments[uploader.filename] = uploader.read + @uploads_to_attach << { filename: uploader.filename, content: uploader.read } @uploads_as_attachments << "#{uploader.secret}/#{uploader.filename}" rescue StandardError => e Gitlab::ErrorTracking.track_exception(e, project_id: @note.project.id) end end + def add_uploads_as_attachments + # We read the uploads before in setup_service_desk_attachments, so let's just add them + @uploads_to_attach.each do |upload| + mail.add_file(filename: upload[:filename], content: upload[:content]) + end + end + def find_uploaders_for(note) uploads = FileUploader::MARKDOWN_PATTERN.scan(note.note) return unless uploads.present? diff --git a/app/mailers/emails/shared.rb b/app/mailers/emails/shared.rb new file mode 100644 index 00000000000..09876c0960a --- /dev/null +++ b/app/mailers/emails/shared.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Emails + module Shared + def csv_email(user, project, csv_data, export_status, type) + @project = project + @count = export_status.fetch(:rows_expected) + @written_count = export_status.fetch(:rows_written) + @truncated = export_status.fetch(:truncated) + @size_limit = ActiveSupport::NumberHelper + .number_to_human_size(ExportCsv::BaseService::TARGET_FILESIZE) + + filename = "#{project.full_path.parameterize}_#{type}_#{Date.today.iso8601}.csv" + attachments[filename] = { content: csv_data, mime_type: 'text/csv' } + email_with_layout( + to: user.notification_email_for(@project.group), + subject: subject("Exported #{type.humanize.downcase}")) + end + end +end diff --git a/app/mailers/emails/work_items.rb b/app/mailers/emails/work_items.rb new file mode 100644 index 00000000000..b14111c94eb --- /dev/null +++ b/app/mailers/emails/work_items.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Emails + module WorkItems + def import_work_items_csv_email(user_id, project_id, results) + @user = User.find(user_id) + @project = Project.find(project_id) + @results = results + + email_with_layout( + to: @user.notification_email_for(@project.group), + subject: subject('Imported work items')) + end + + def export_work_items_csv_email(user, project, csv_data, export_status) + csv_email(user, project, csv_data, export_status, 'work_items') + end + end +end diff --git a/app/mailers/notify.rb b/app/mailers/notify.rb index 28ef6d8d6c6..036a0fc012e 100644 --- a/app/mailers/notify.rb +++ b/app/mailers/notify.rb @@ -7,6 +7,7 @@ class Notify < ApplicationMailer include ReminderEmailsHelper include IssuablesHelper + include Emails::Shared include Emails::Issues include Emails::MergeRequests include Emails::Notes @@ -25,6 +26,7 @@ class Notify < ApplicationMailer include Emails::AdminNotification include Emails::IdentityVerification include Emails::Imports + include Emails::WorkItems helper TimeboxesHelper helper MergeRequestsHelper @@ -39,11 +41,12 @@ class Notify < ApplicationMailer helper InProductMarketingHelper def test_email(recipient_email, subject, body) - mail_with_locale(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", @@ -130,8 +133,8 @@ class Notify < ApplicationMailer @reason = headers['X-GitLab-NotificationReason'] - if Gitlab::IncomingEmail.enabled? && @sent_notification - headers['Reply-To'] = Mail::Address.new(Gitlab::IncomingEmail.reply_address(reply_key)).tap do |address| + if Gitlab::Email::IncomingEmail.enabled? && @sent_notification + headers['Reply-To'] = Mail::Address.new(Gitlab::Email::IncomingEmail.reply_address(reply_key)).tap do |address| address.display_name = reply_display_name(model) end @@ -219,8 +222,8 @@ class Notify < ApplicationMailer return unless !@labels_url && @sent_notification && @sent_notification.unsubscribable? list_unsubscribe_methods = [unsubscribe_sent_notification_url(@sent_notification, force: true)] - if Gitlab::IncomingEmail.enabled? && Gitlab::IncomingEmail.supports_wildcard? - list_unsubscribe_methods << "mailto:#{Gitlab::IncomingEmail.unsubscribe_address(reply_key)}" + if Gitlab::Email::IncomingEmail.enabled? && Gitlab::Email::IncomingEmail.supports_wildcard? + list_unsubscribe_methods << "mailto:#{Gitlab::Email::IncomingEmail.unsubscribe_address(reply_key)}" end headers['List-Unsubscribe'] = list_unsubscribe_methods.map { |e| "<#{e}>" }.join(',') diff --git a/app/mailers/previews/notify_preview.rb b/app/mailers/previews/notify_preview.rb index 7ed594bf571..d91f69cdd4b 100644 --- a/app/mailers/previews/notify_preview.rb +++ b/app/mailers/previews/notify_preview.rb @@ -60,6 +60,14 @@ class NotifyPreview < ActionMailer::Preview end end + def access_token_created_email + Notify.access_token_created_email(user, 'token_name').message + end + + def access_token_revoked_email + Notify.access_token_revoked_email(user, 'token_name').message + end + def new_mention_in_merge_request_email Notify.new_mention_in_merge_request_email(user.id, merge_request.id, user.id).message end @@ -84,6 +92,10 @@ class NotifyPreview < ActionMailer::Preview Notify.import_issues_csv_email(user.id, project.id, { success: 3, errors: [5, 6, 7], valid_file: true }) end + def import_work_items_csv_email + Notify.import_work_items_csv_email(user.id, project.id, { success: 4, error_lines: [2, 3, 4], parse_error: false }) + end + def issues_csv_email Notify.issues_csv_email(user, project, '1997,Ford,E350', { truncated: false, rows_expected: 3, rows_written: 3 }).message end @@ -201,6 +213,52 @@ class NotifyPreview < ActionMailer::Preview Notify.service_desk_thank_you_email(issue.id).message end + def service_desk_custom_email_verification_email + cleanup do + setup_service_desk_custom_email_objects + + Notify.service_desk_custom_email_verification_email(service_desk_setting).message + end + end + + def service_desk_verification_triggered_email + cleanup do + setup_service_desk_custom_email_objects + + Notify.service_desk_verification_triggered_email(service_desk_setting, 'owner@example.com').message + end + end + + def service_desk_verification_result_email_for_verified_state + cleanup do + setup_service_desk_custom_email_objects + + custom_email_verification.mark_as_finished! + + Notify.service_desk_verification_result_email(service_desk_setting, 'owner@example.com').message + end + end + + def service_desk_verification_result_email_for_incorrect_token_error + service_desk_verification_result_email_for_error_state(error: :incorrect_token) + end + + def service_desk_verification_result_email_for_incorrect_from_error + service_desk_verification_result_email_for_error_state(error: :incorrect_from) + end + + def service_desk_verification_result_email_for_mail_not_received_within_timeframe_error + service_desk_verification_result_email_for_error_state(error: :mail_not_received_within_timeframe) + end + + def service_desk_verification_result_email_for_invalid_credentials_error + service_desk_verification_result_email_for_error_state(error: :invalid_credentials) + end + + def service_desk_verification_result_email_for_smtp_host_issue_error + service_desk_verification_result_email_for_error_state(error: :smtp_host_issue) + end + def merge_when_pipeline_succeeds_email Notify.merge_when_pipeline_succeeds_email(user.id, merge_request.id, user.id).message end @@ -235,6 +293,53 @@ class NotifyPreview < ActionMailer::Preview @project ||= Project.first end + def service_desk_verification_result_email_for_error_state(error:) + cleanup do + setup_service_desk_custom_email_objects + + custom_email_verification.mark_as_failed!(error) + + Notify.service_desk_verification_result_email(service_desk_setting, 'owner@example.com').message + end + end + + def setup_service_desk_custom_email_objects + # Call accessors to ensure objects have been created + custom_email_credential + custom_email_verification + + # Update associations in projects, because we access + # custom_email_credential and custom_email_verification via project + project.reset + end + + def custom_email_verification + @custom_email_verification ||= project.service_desk_custom_email_verification || ServiceDesk::CustomEmailVerification.create!( + project: project, + token: 'XXXXXXXXXXXX', + triggerer: user, + triggered_at: Time.current, + state: 'started' + ) + end + + def custom_email_credential + @custom_email_credential ||= project.service_desk_custom_email_credential || ServiceDesk::CustomEmailCredential.create!( + project: project, + smtp_address: 'smtp.gmail.com', # Use gmail, because Gitlab::UrlBlocker resolves DNS + smtp_port: 587, + smtp_username: 'user@gmail.com', + smtp_password: 'supersecret' + ) + end + + def service_desk_setting + @service_desk_setting ||= project.service_desk_setting || ServiceDeskSetting.create!( + project: project, + custom_email: 'user@gmail.com' + ) + end + def issue @issue ||= project.issues.first end |