Class: ServiceDeskSetting

Inherits:
ApplicationRecord show all
Includes:
Gitlab::Utils::StrongMemoize
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 HasCheckConstraints

HasCheckConstraints::NOT_NULL_CHECK_PATTERN

Constants included from ResetOnColumnErrors

ResetOnColumnErrors::MAX_RESET_PERIOD

Instance Method Summary collapse

Methods inherited from ApplicationRecord

===, cached_column_list, #create_or_load_association, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, 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 Organizations::Sharding

#sharding_organization

Methods included from ResetOnColumnErrors

#reset_on_union_error, #reset_on_unknown_attribute_error

Methods included from Gitlab::SensitiveSerializableHash

#serializable_hash

Instance Method Details

#custom_email_address_for_verificationObject



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

def custom_email_address_for_verification
  return unless custom_email.present?

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

#custom_email_credentialObject



41
42
43
# File 'app/models/service_desk_setting.rb', line 41

def custom_email_credential
  project&.service_desk_custom_email_credential
end

#custom_email_enabled_stateObject



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

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



45
46
47
# File 'app/models/service_desk_setting.rb', line 45

def custom_email_verification
  project&.service_desk_custom_email_verification
end

#issue_template_contentObject



55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/models/service_desk_setting.rb', line 55

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)


68
69
70
# File 'app/models/service_desk_setting.rb', line 68

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

#tickets_confidential_by_default?Boolean

Returns:

  • (Boolean)


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

def tickets_confidential_by_default?
  # Tickets in public projects should always be confidential by default
  return true if project.public?

  self[:tickets_confidential_by_default]
end

#valid_issue_templateObject



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

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

#valid_project_keyObject



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

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