2019-02-15 15:39:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Projects
|
|
|
|
module Settings
|
|
|
|
class OperationsController < Projects::ApplicationController
|
2019-12-04 20:38:33 +05:30
|
|
|
before_action :authorize_admin_operations!
|
2020-04-22 19:07:51 +05:30
|
|
|
before_action :authorize_read_prometheus_alerts!, only: [:reset_alerting_token]
|
|
|
|
|
|
|
|
respond_to :json, only: [:reset_alerting_token]
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
helper_method :error_tracking_setting
|
|
|
|
|
|
|
|
def show
|
2020-04-08 14:13:33 +05:30
|
|
|
render locals: { prometheus_service: prometheus_service }
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
result = ::Projects::Operations::UpdateService.new(project, current_user, update_params).execute
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
track_events(result)
|
2019-07-07 11:18:12 +05:30
|
|
|
render_update_response(result)
|
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
# overridden in EE
|
|
|
|
def track_events(result)
|
2020-03-13 15:44:24 +05:30
|
|
|
if result[:status] == :success
|
|
|
|
::Gitlab::Tracking::IncidentManagement.track_from_params(
|
|
|
|
update_params[:incident_management_setting_attributes]
|
|
|
|
)
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
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
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
private
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
def alerting_params
|
|
|
|
{ alerting_setting_attributes: { regenerate_token: true } }
|
|
|
|
end
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
def prometheus_service
|
|
|
|
project.find_or_initialize_service(::PrometheusService.to_param)
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
def render_update_response(result)
|
|
|
|
respond_to do |format|
|
2020-03-13 15:44:24 +05:30
|
|
|
format.html do
|
|
|
|
render_update_html_response(result)
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
format.json do
|
|
|
|
render_update_json_response(result)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
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-07-07 11:18:12 +05:30
|
|
|
def render_update_json_response(result)
|
2019-02-15 15:39:39 +05:30
|
|
|
if result[:status] == :success
|
|
|
|
flash[:notice] = _('Your changes have been saved')
|
2019-07-07 11:18:12 +05:30
|
|
|
render json: {
|
|
|
|
status: result[:status]
|
|
|
|
}
|
2019-02-15 15:39:39 +05:30
|
|
|
else
|
2019-07-07 11:18:12 +05:30
|
|
|
render(
|
|
|
|
status: result[:http_status] || :bad_request,
|
|
|
|
json: {
|
|
|
|
status: result[:status],
|
|
|
|
message: result[:message]
|
|
|
|
}
|
|
|
|
)
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def error_tracking_setting
|
|
|
|
@error_tracking_setting ||= project.error_tracking_setting ||
|
|
|
|
project.build_error_tracking_setting
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_params
|
|
|
|
params.require(:project).permit(permitted_project_params)
|
|
|
|
end
|
|
|
|
|
|
|
|
# overridden in EE
|
|
|
|
def permitted_project_params
|
2020-03-13 15:44:24 +05:30
|
|
|
project_params = {
|
|
|
|
incident_management_setting_attributes: ::Gitlab::Tracking::IncidentManagement.tracking_keys.keys,
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
metrics_setting_attributes: [:external_dashboard_url],
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
error_tracking_setting_attributes: [
|
|
|
|
:enabled,
|
|
|
|
:api_host,
|
|
|
|
:token,
|
|
|
|
project: [:slug, :name, :organization_slug, :organization_name]
|
2019-12-21 20:55:43 +05:30
|
|
|
],
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
grafana_integration_attributes: [:token, :grafana_url, :enabled]
|
2019-07-07 11:18:12 +05:30
|
|
|
}
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
if Feature.enabled?(:settings_operations_prometheus_service, project)
|
|
|
|
project_params[:prometheus_integration_attributes] = [:manual_configuration, :api_url]
|
|
|
|
end
|
|
|
|
|
|
|
|
project_params
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
Projects::Settings::OperationsController.prepend_if_ee('::EE::Projects::Settings::OperationsController')
|