Commit eb759513 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch '4925-open-issues-based-on-prometheus-alerts-controller' into 'master'

Expose and manage incident management settings

See merge request gitlab-org/gitlab-ee!9773
parents 1c3e0ea4 6ca79ae4
......@@ -3,7 +3,6 @@
module Projects
module Settings
class OperationsController < Projects::ApplicationController
before_action :check_license
before_action :authorize_update_environment!
helper_method :error_tracking_setting
......@@ -65,10 +64,6 @@ module Projects
]
}
end
def check_license
render_404 unless helpers.settings_operations_available?
end
end
end
end
......
......@@ -25,7 +25,7 @@ module EE
end
end
helper_method :tracing_setting
helper_method :tracing_setting, :incident_management_available?
private
......@@ -45,11 +45,37 @@ module EE
def tracing_setting
@tracing_setting ||= project.tracing_setting || project.build_tracing_setting
end
def has_tracing_license?
project.feature_available?(:tracing, current_user)
end
def has_incident_management_license?
project.feature_available?(:incident_management, current_user)
end
def incident_management_feature_enabled?
::Feature.enabled?(:incident_management)
end
def incident_management_available?
incident_management_feature_enabled? && has_incident_management_license?
end
end
override :permitted_project_params
def permitted_project_params
super.merge(tracing_setting_attributes: [:external_url])
permitted_params = super
if has_tracing_license?
permitted_params[:tracing_setting_attributes] = [:external_url]
end
if incident_management_available?
permitted_params[:incident_management_setting_attributes] = [:create_issue, :send_email, :issue_template_key]
end
permitted_params
end
override :render_update_response
......
......@@ -214,5 +214,10 @@ module EE
@project.feature_available?(:tracing, current_user) && can?(current_user, :read_environment, @project)
end
def project_incident_management_setting
@project_incident_management_setting ||= @project.incident_management_setting ||
@project.build_incident_management_setting
end
end
end
......@@ -123,6 +123,7 @@ module EE
accepts_nested_attributes_for :tracing_setting, update_only: true, allow_destroy: true
accepts_nested_attributes_for :alerting_setting, update_only: true
accepts_nested_attributes_for :incident_management_setting, update_only: true
alias_attribute :fallback_approvals_required, :approvals_before_merge
end
......
......@@ -95,6 +95,7 @@ class License < ActiveRecord::Base
tracing
insights
web_ide_terminal
incident_management
]
EEU_FEATURES.freeze
......
......@@ -12,6 +12,7 @@ module EE
super
.merge(tracing_setting_params)
.merge(alerting_setting_params)
.merge(incident_management_setting_params)
end
private
......@@ -41,6 +42,10 @@ module EE
{ alerting_setting_attributes: attr }
end
def incident_management_setting_params
params.slice(:incident_management_setting_attributes)
end
end
end
end
......
---
title: Add an incident management settings form and create issues from alertmanager
alerts
merge_request: 9773
author:
type: added
# frozen_string_literal: true
require 'spec_helper'
describe ProjectsHelper do
describe '#project_incident_management_setting' do
set(:project) { create(:project) }
before do
helper.instance_variable_set(:@project, project)
end
context 'when incident_management_setting exists' do
let(:project_incident_management_setting) do
create(:project_incident_management_setting, project: project)
end
it 'return project_incident_management_setting' do
expect(helper.project_incident_management_setting).to(
eq(project_incident_management_setting)
)
end
end
context 'when incident_management_setting does not exist' do
it 'builds incident_management_setting' do
expect(helper.project_incident_management_setting.persisted?).to be(false)
expect(helper.project_incident_management_setting.send_email).to be(true)
expect(helper.project_incident_management_setting.create_issue).to be(false)
expect(helper.project_incident_management_setting.issue_template_key).to be(nil)
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