Commit 03917328 authored by Peter Leitzen's avatar Peter Leitzen Committed by Dmitriy Zaporozhets

Add database table and model for incident settings

These settings will be managed via the settings operation controller.
parent b37e1217
......@@ -2284,6 +2284,12 @@ ActiveRecord::Schema.define(version: 20190228092516) do
t.index ["project_id"], name: "index_project_import_data_on_project_id", using: :btree
end
create_table "project_incident_management_settings", primary_key: "project_id", id: :integer, force: :cascade do |t|
t.boolean "create_issue", default: false, null: false
t.boolean "send_email", default: true, null: false
t.text "issue_template_key"
end
create_table "project_mirror_data", force: :cascade do |t|
t.integer "project_id", null: false
t.integer "retry_count", default: 0, null: false
......@@ -3512,6 +3518,7 @@ ActiveRecord::Schema.define(version: 20190228092516) do
add_foreign_key "project_features", "projects", name: "fk_18513d9b92", on_delete: :cascade
add_foreign_key "project_group_links", "projects", name: "fk_daa8cee94c", on_delete: :cascade
add_foreign_key "project_import_data", "projects", name: "fk_ffb9ee3a10", on_delete: :cascade
add_foreign_key "project_incident_management_settings", "projects", on_delete: :cascade
add_foreign_key "project_mirror_data", "projects", name: "fk_d1aad367d7", on_delete: :cascade
add_foreign_key "project_repositories", "projects", on_delete: :cascade
add_foreign_key "project_repositories", "shards", on_delete: :restrict
......
......@@ -41,6 +41,7 @@ module EE
has_one :gitlab_slack_application_service
has_one :tracing_setting, class_name: 'ProjectTracingSetting'
has_one :alerting_setting, inverse_of: :project, class_name: 'Alerting::ProjectAlertingSetting'
has_one :incident_management_setting, inverse_of: :project, class_name: 'IncidentManagement::ProjectIncidentManagementSetting'
has_one :feature_usage, class_name: 'ProjectFeatureUsage'
has_many :reviews, inverse_of: :project
......
# frozen_string_literal: true
module IncidentManagement
class ProjectIncidentManagementSetting < ApplicationRecord
belongs_to :project
validate :issue_template_exists, if: :create_issue?
private
def issue_template_exists
return unless issue_template_key.present?
Gitlab::Template::IssueTemplate.find(issue_template_key, project)
rescue Gitlab::Template::Finders::RepoTemplateFinder::FileNotFoundError
errors.add(:issue_template_key, 'not found')
end
end
end
# frozen_string_literal: true
class CreateProjectIncidentManagementSettings < ActiveRecord::Migration[5.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def change
create_table :project_incident_management_settings, id: :int, primary_key: :project_id do |t|
t.boolean :create_issue, default: false, null: false
t.boolean :send_email, default: true, null: false
t.text :issue_template_key
t.foreign_key :projects, column: :project_id, on_delete: :cascade
end
end
end
# frozen_string_literal: true
FactoryBot.define do
factory :project_incident_management_setting, class: IncidentManagement::ProjectIncidentManagementSetting do
project
create_issue false
issue_template_key nil
send_email false
end
end
......@@ -79,6 +79,7 @@ project:
- alerting_setting
- webide_pipelines
- reviews
- incident_management_setting
prometheus_metrics:
- project
- prometheus_alerts
......@@ -99,3 +100,5 @@ reviews:
- merge_request
- author
- notes
incident_management_setting:
- project
# frozen_string_literal: true
require 'spec_helper'
describe IncidentManagement::ProjectIncidentManagementSetting do
set(:project) { create(:project, :repository, create_templates: :issue) }
describe 'Associations' do
it { is_expected.to belong_to(:project) }
end
describe 'Validations' do
describe 'validate issue_template_exists' do
subject { build(:project_incident_management_setting, project: project) }
context 'with create_issue enabled' do
before do
subject.create_issue = true
end
context 'with valid issue_template_key' do
before do
subject.issue_template_key = 'bug'
end
it { is_expected.to be_valid }
end
context 'with empty issue_template_key' do
before do
subject.issue_template_key = ''
end
it { is_expected.to be_valid }
end
context 'with nil issue_template_key' do
before do
subject.issue_template_key = nil
end
it { is_expected.to be_valid }
end
context 'with invalid issue_template_key' do
before do
subject.issue_template_key = 'unknown'
end
it { is_expected.to be_invalid }
it 'returns error' do
subject.valid?
expect(subject.errors[:issue_template_key]).to eq(['not found'])
end
end
end
context 'with create_issue disabled' do
before do
subject.create_issue = false
end
context 'with unknown issue_template_key' do
before do
subject.issue_template_key = 'unknown'
end
it { is_expected.to be_valid }
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment