Class: ServiceDeskSetting

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

Constant Summary

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

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

#issue_template_contentObject


18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/service_desk_setting.rb', line 18

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)

31
32
33
# File 'app/models/service_desk_setting.rb', line 31

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

#valid_issue_templateObject


35
36
37
38
39
# File 'app/models/service_desk_setting.rb', line 35

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

#valid_project_keyObject


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

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