2019-01-06 07:59:10 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Projects
|
|
|
|
module Settings
|
|
|
|
class OperationsController < Projects::ApplicationController
|
2019-09-05 17:17:36 -04:00
|
|
|
before_action :authorize_admin_operations!
|
2020-03-25 05:08:11 -04:00
|
|
|
before_action :authorize_read_prometheus_alerts!, only: [:reset_alerting_token]
|
2020-07-14 20:09:23 -04:00
|
|
|
|
2020-08-21 11:10:03 -04:00
|
|
|
before_action do
|
|
|
|
push_frontend_feature_flag(:auto_close_incident)
|
|
|
|
end
|
|
|
|
|
2020-07-14 20:09:23 -04:00
|
|
|
respond_to :json, only: [:reset_alerting_token, :reset_pagerduty_token]
|
2019-01-06 07:59:10 -05:00
|
|
|
|
2019-01-07 13:46:34 -05:00
|
|
|
helper_method :error_tracking_setting
|
|
|
|
|
2019-01-06 07:59:10 -05:00
|
|
|
def update
|
|
|
|
result = ::Projects::Operations::UpdateService.new(project, current_user, update_params).execute
|
|
|
|
|
2019-10-17 20:07:45 -04:00
|
|
|
track_events(result)
|
2019-03-01 09:51:54 -05:00
|
|
|
render_update_response(result)
|
|
|
|
end
|
|
|
|
|
2019-10-17 20:07:45 -04:00
|
|
|
# overridden in EE
|
|
|
|
def track_events(result)
|
2020-02-15 16:08:49 -05:00
|
|
|
if result[:status] == :success
|
|
|
|
::Gitlab::Tracking::IncidentManagement.track_from_params(
|
|
|
|
update_params[:incident_management_setting_attributes]
|
|
|
|
)
|
|
|
|
end
|
2019-10-17 20:07:45 -04:00
|
|
|
end
|
|
|
|
|
2020-03-25 05:08:11 -04:00
|
|
|
def reset_alerting_token
|
|
|
|
result = ::Projects::Operations::UpdateService
|
|
|
|
.new(project, current_user, alerting_params)
|
|
|
|
.execute
|
|
|
|
|
|
|
|
if result[:status] == :success
|
|
|
|
render json: { token: project.alerting_setting.token }
|
|
|
|
else
|
|
|
|
render json: {}, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-14 20:09:23 -04:00
|
|
|
def reset_pagerduty_token
|
|
|
|
result = ::Projects::Operations::UpdateService
|
|
|
|
.new(project, current_user, pagerduty_token_params)
|
|
|
|
.execute
|
|
|
|
|
|
|
|
if result[:status] == :success
|
|
|
|
pagerduty_token = project.incident_management_setting&.pagerduty_token
|
2020-07-20 14:09:27 -04:00
|
|
|
webhook_url = project_incidents_integrations_pagerduty_url(project, token: pagerduty_token)
|
2020-07-14 20:09:23 -04:00
|
|
|
|
|
|
|
render json: { pagerduty_webhook_url: webhook_url, pagerduty_token: pagerduty_token }
|
|
|
|
else
|
|
|
|
render json: {}, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-01 09:51:54 -05:00
|
|
|
private
|
|
|
|
|
2020-03-25 05:08:11 -04:00
|
|
|
def alerting_params
|
|
|
|
{ alerting_setting_attributes: { regenerate_token: true } }
|
|
|
|
end
|
|
|
|
|
2020-07-14 20:09:23 -04:00
|
|
|
def pagerduty_token_params
|
|
|
|
{ incident_management_setting_attributes: { regenerate_token: true } }
|
|
|
|
end
|
|
|
|
|
2019-03-01 09:51:54 -05:00
|
|
|
def render_update_response(result)
|
|
|
|
respond_to do |format|
|
2020-02-15 16:08:49 -05:00
|
|
|
format.html do
|
|
|
|
render_update_html_response(result)
|
|
|
|
end
|
|
|
|
|
2019-03-01 09:51:54 -05:00
|
|
|
format.json do
|
|
|
|
render_update_json_response(result)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-15 16:08:49 -05:00
|
|
|
def render_update_html_response(result)
|
|
|
|
if result[:status] == :success
|
|
|
|
flash[:notice] = _('Your changes have been saved')
|
|
|
|
redirect_to project_settings_operations_path(@project)
|
|
|
|
else
|
|
|
|
render 'show'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-01 09:51:54 -05:00
|
|
|
def render_update_json_response(result)
|
2019-01-06 07:59:10 -05:00
|
|
|
if result[:status] == :success
|
|
|
|
flash[:notice] = _('Your changes have been saved')
|
2019-03-01 09:51:54 -05:00
|
|
|
render json: {
|
|
|
|
status: result[:status]
|
|
|
|
}
|
2019-01-06 07:59:10 -05:00
|
|
|
else
|
2019-03-01 09:51:54 -05:00
|
|
|
render(
|
|
|
|
status: result[:http_status] || :bad_request,
|
|
|
|
json: {
|
|
|
|
status: result[:status],
|
|
|
|
message: result[:message]
|
|
|
|
}
|
|
|
|
)
|
2019-01-06 07:59:10 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-07 13:46:34 -05:00
|
|
|
def error_tracking_setting
|
|
|
|
@error_tracking_setting ||= project.error_tracking_setting ||
|
|
|
|
project.build_error_tracking_setting
|
|
|
|
end
|
|
|
|
|
2019-01-06 07:59:10 -05:00
|
|
|
def update_params
|
|
|
|
params.require(:project).permit(permitted_project_params)
|
|
|
|
end
|
|
|
|
|
|
|
|
# overridden in EE
|
|
|
|
def permitted_project_params
|
2020-02-12 19:08:46 -05:00
|
|
|
project_params = {
|
2020-02-15 16:08:49 -05:00
|
|
|
incident_management_setting_attributes: ::Gitlab::Tracking::IncidentManagement.tracking_keys.keys,
|
|
|
|
|
2020-06-08 23:08:27 -04:00
|
|
|
metrics_setting_attributes: [:external_dashboard_url, :dashboard_timezone],
|
2019-04-26 13:23:26 -04:00
|
|
|
|
2019-03-01 09:51:54 -05:00
|
|
|
error_tracking_setting_attributes: [
|
|
|
|
:enabled,
|
|
|
|
:api_host,
|
|
|
|
:token,
|
|
|
|
project: [:slug, :name, :organization_slug, :organization_name]
|
2019-10-03 17:07:29 -04:00
|
|
|
],
|
|
|
|
|
2019-11-01 14:06:00 -04:00
|
|
|
grafana_integration_attributes: [:token, :grafana_url, :enabled]
|
2019-03-01 09:51:54 -05:00
|
|
|
}
|
2020-02-12 19:08:46 -05:00
|
|
|
|
|
|
|
if Feature.enabled?(:settings_operations_prometheus_service, project)
|
|
|
|
project_params[:prometheus_integration_attributes] = [:manual_configuration, :api_url]
|
|
|
|
end
|
|
|
|
|
|
|
|
project_params
|
2019-01-06 07:59:10 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
Projects::Settings::OperationsController.prepend_if_ee('::EE::Projects::Settings::OperationsController')
|