diff options
Diffstat (limited to 'app/models/service_desk_setting.rb')
-rw-r--r-- | app/models/service_desk_setting.rb | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/app/models/service_desk_setting.rb b/app/models/service_desk_setting.rb index 5152746abb4..69afb445734 100644 --- a/app/models/service_desk_setting.rb +++ b/app/models/service_desk_setting.rb @@ -3,6 +3,8 @@ class ServiceDeskSetting < ApplicationRecord include Gitlab::Utils::StrongMemoize + CUSTOM_EMAIL_VERIFICATION_SUBADDRESS = '+verify' + attribute :custom_email_enabled, default: false attr_encrypted :custom_email_smtp_password, mode: :per_attribute_iv, @@ -12,6 +14,7 @@ class ServiceDeskSetting < ApplicationRecord encode_iv: false belongs_to :project + validates :project_id, presence: true validate :valid_issue_template validate :valid_project_key @@ -32,21 +35,25 @@ class ServiceDeskSetting < ApplicationRecord validates :custom_email, presence: true, devise_email: true, - if: :custom_email_enabled? + if: :needs_custom_email_smtp_credentials? validates :custom_email_smtp_address, presence: true, hostname: { allow_numeric_hostname: true, require_valid_tld: true }, - if: :custom_email_enabled? + if: :needs_custom_email_smtp_credentials? validates :custom_email_smtp_username, presence: true, - if: :custom_email_enabled? + if: :needs_custom_email_smtp_credentials? validates :custom_email_smtp_port, presence: true, numericality: { only_integer: true, greater_than: 0 }, - if: :custom_email_enabled? + if: :needs_custom_email_smtp_credentials? scope :with_project_key, ->(key) { where(project_key: key) } + def custom_email_verification + project&.service_desk_custom_email_verification + end + def custom_email_delivery_options { user_name: custom_email_smtp_username, @@ -57,6 +64,12 @@ class ServiceDeskSetting < ApplicationRecord } end + def custom_email_address_for_verification + return unless custom_email.present? + + custom_email.sub("@", "#{CUSTOM_EMAIL_VERIFICATION_SUBADDRESS}@") + end + def issue_template_content strong_memoize(:issue_template_content) do next unless issue_template_key.present? @@ -102,6 +115,10 @@ class ServiceDeskSetting < ApplicationRecord setting.project.full_path_slug == project_slug end end + + def needs_custom_email_smtp_credentials? + custom_email_enabled? || custom_email_verification.present? + end end ServiceDeskSetting.prepend_mod |