summaryrefslogtreecommitdiff
path: root/app/models/incident_management
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-11 15:08:44 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-11 15:08:44 +0000
commitbcc77054ee9aefd1e332e04a4189390fd5a3112e (patch)
treee6e1908c310e4733038794e932196cae0d66ba9a /app/models/incident_management
parent05b5c609cb8c260b10c2eb1b92b711dc82d32c3f (diff)
downloadgitlab-ce-bcc77054ee9aefd1e332e04a4189390fd5a3112e.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/incident_management')
-rw-r--r--app/models/incident_management/project_incident_management_setting.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/app/models/incident_management/project_incident_management_setting.rb b/app/models/incident_management/project_incident_management_setting.rb
new file mode 100644
index 00000000000..bf57c5b883f
--- /dev/null
+++ b/app/models/incident_management/project_incident_management_setting.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+module IncidentManagement
+ class ProjectIncidentManagementSetting < ApplicationRecord
+ include Gitlab::Utils::StrongMemoize
+
+ belongs_to :project
+
+ validate :issue_template_exists, if: :create_issue?
+
+ def available_issue_templates
+ Gitlab::Template::IssueTemplate.all(project)
+ end
+
+ def issue_template_content
+ strong_memoize(:issue_template_content) do
+ issue_template&.content if issue_template_key.present?
+ end
+ end
+
+ private
+
+ def issue_template_exists
+ return unless issue_template_key.present?
+
+ errors.add(:issue_template_key, 'not found') unless issue_template
+ end
+
+ def issue_template
+ Gitlab::Template::IssueTemplate.find(issue_template_key, project)
+ rescue Gitlab::Template::Finders::RepoTemplateFinder::FileNotFoundError
+ end
+ end
+end