Class: ServiceDeskSetting

Inherits:
ApplicationRecord show all
Includes:
Gitlab::Utils::StrongMemoize, IgnorableColumns
Defined in:
app/models/service_desk_setting.rb

Constant Summary collapse

CUSTOM_EMAIL_VERIFICATION_SUBADDRESS =
'+verify'

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Instance Method Summary collapse

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Instance Method Details

#custom_email_address_for_verificationObject



55
56
57
58
59
# File 'app/models/service_desk_setting.rb', line 55

def custom_email_address_for_verification
  return unless custom_email.present?

  custom_email.sub("@", "#{CUSTOM_EMAIL_VERIFICATION_SUBADDRESS}@")
end

#custom_email_credentialObject



47
48
49
# File 'app/models/service_desk_setting.rb', line 47

def custom_email_credential
  project&.service_desk_custom_email_credential
end

#custom_email_enabled_stateObject



90
91
92
93
94
95
96
# File 'app/models/service_desk_setting.rb', line 90

def custom_email_enabled_state
  return unless custom_email_enabled?

  if custom_email_verification.blank? || !custom_email_verification.finished?
    errors.add(:custom_email_enabled, 'cannot be enabled until verification process has finished.')
  end
end

#custom_email_verificationObject



51
52
53
# File 'app/models/service_desk_setting.rb', line 51

def custom_email_verification
  project&.service_desk_custom_email_verification
end

#issue_template_contentObject



61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/models/service_desk_setting.rb', line 61

def issue_template_content
  strong_memoize(:issue_template_content) do
    next unless issue_template_key.present?

    TemplateFinder.new(
      :issues, project,
      name: issue_template_key,
      source_template_project: source_template_project
    ).execute.content
  rescue ::Gitlab::Template::Finders::RepoTemplateFinder::FileNotFoundError
  end
end

#issue_template_missing?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'app/models/service_desk_setting.rb', line 74

def issue_template_missing?
  issue_template_key.present? && !issue_template_content.present?
end

#valid_issue_templateObject



78
79
80
81
82
# File 'app/models/service_desk_setting.rb', line 78

def valid_issue_template
  if issue_template_missing?
    errors.add(:issue_template_key, 'is empty or does not exist')
  end
end

#valid_project_keyObject



84
85
86
87
88
# File 'app/models/service_desk_setting.rb', line 84

def valid_project_key
  if projects_with_same_slug_and_key_exists?
    errors.add(:project_key, 'already in use for another service desk address.')
  end
end