diff options
Diffstat (limited to 'app/models/service_desk_setting.rb')
-rw-r--r-- | app/models/service_desk_setting.rb | 80 |
1 files changed, 42 insertions, 38 deletions
diff --git a/app/models/service_desk_setting.rb b/app/models/service_desk_setting.rb index 5152746abb4..4216ad7e70f 100644 --- a/app/models/service_desk_setting.rb +++ b/app/models/service_desk_setting.rb @@ -2,59 +2,59 @@ class ServiceDeskSetting < ApplicationRecord include Gitlab::Utils::StrongMemoize + include IgnorableColumns + + CUSTOM_EMAIL_VERIFICATION_SUBADDRESS = '+verify' + + ignore_columns %i[ + custom_email_smtp_address + custom_email_smtp_port + custom_email_smtp_username + encrypted_custom_email_smtp_password + encrypted_custom_email_smtp_password_iv + ], remove_with: '16.1', remove_after: '2023-05-22' attribute :custom_email_enabled, default: false - attr_encrypted :custom_email_smtp_password, - mode: :per_attribute_iv, - algorithm: 'aes-256-gcm', - key: Settings.attr_encrypted_db_key_base_32, - encode: false, - encode_iv: false belongs_to :project + validates :project_id, presence: true validate :valid_issue_template validate :valid_project_key validates :outgoing_name, length: { maximum: 255 }, allow_blank: true validates :project_key, - length: { maximum: 255 }, - allow_blank: true, - format: { with: /\A[a-z0-9_]+\z/, message: -> (setting, data) { _("can contain only lowercase letters, digits, and '_'.") } } + length: { maximum: 255 }, + allow_blank: true, + format: { with: /\A[a-z0-9_]+\z/, message: -> (setting, data) { _("can contain only lowercase letters, digits, and '_'.") } } validates :custom_email, - length: { maximum: 255 }, - uniqueness: true, - allow_nil: true, - format: /\A[\w\-._]+@[\w\-.]+\.{1}[a-zA-Z]{2,}\z/ - validates :custom_email_smtp_address, length: { maximum: 255 } - validates :custom_email_smtp_username, length: { maximum: 255 } - + length: { maximum: 255 }, + uniqueness: true, + allow_nil: true, + format: /\A[\w\-._]+@[\w\-.]+\.{1}[a-zA-Z]{2,}\z/ + + validates :custom_email_credential, + presence: true, + if: :needs_custom_email_credentials? validates :custom_email, - presence: true, - devise_email: true, - if: :custom_email_enabled? - validates :custom_email_smtp_address, - presence: true, - hostname: { allow_numeric_hostname: true, require_valid_tld: true }, - if: :custom_email_enabled? - validates :custom_email_smtp_username, - presence: true, - if: :custom_email_enabled? - validates :custom_email_smtp_port, - presence: true, - numericality: { only_integer: true, greater_than: 0 }, - if: :custom_email_enabled? + presence: true, + devise_email: true, + if: :needs_custom_email_credentials? scope :with_project_key, ->(key) { where(project_key: key) } - def custom_email_delivery_options - { - user_name: custom_email_smtp_username, - password: custom_email_smtp_password, - address: custom_email_smtp_address, - domain: Mail::Address.new(custom_email).domain, - port: custom_email_smtp_port || 587 - } + def custom_email_credential + project&.service_desk_custom_email_credential + end + + def custom_email_verification + project&.service_desk_custom_email_verification + end + + def custom_email_address_for_verification + return unless custom_email.present? + + custom_email.sub("@", "#{CUSTOM_EMAIL_VERIFICATION_SUBADDRESS}@") end def issue_template_content @@ -102,6 +102,10 @@ class ServiceDeskSetting < ApplicationRecord setting.project.full_path_slug == project_slug end end + + def needs_custom_email_credentials? + custom_email_enabled? || custom_email_verification.present? + end end ServiceDeskSetting.prepend_mod |