debian-mirror-gitlab/app/controllers/projects/settings/operations_controller.rb

143 lines
4.1 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
module Projects
module Settings
class OperationsController < Projects::ApplicationController
2021-04-29 21:17:54 +05:30
layout 'project_settings'
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]
2022-05-07 20:08:51 +05:30
before_action do
push_frontend_feature_flag(:integrated_error_tracking, project)
end
2020-07-28 23:09:34 +05:30
respond_to :json, only: [:reset_alerting_token, :reset_pagerduty_token]
2019-02-15 15:39:39 +05:30
2020-07-28 23:09:34 +05:30
helper_method :error_tracking_setting
2021-01-03 14:25:43 +05:30
feature_category :incident_management
2022-07-16 23:28:13 +05:30
urgency :low
2019-02-15 15:39:39 +05:30
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
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
2020-07-28 23:09:34 +05:30
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-10-24 23:57:45 +05:30
webhook_url = project_incidents_integrations_pagerduty_url(project, token: pagerduty_token)
2020-07-28 23:09:34 +05:30
render json: { pagerduty_webhook_url: webhook_url, pagerduty_token: pagerduty_token }
else
render json: {}, status: :unprocessable_entity
end
end
2019-07-07 11:18:12 +05:30
private
2021-01-03 14:25:43 +05:30
def track_events(result)
if result[:status] == :success
::Gitlab::Tracking::IncidentManagement.track_from_params(
update_params[:incident_management_setting_attributes]
)
end
end
2020-04-22 19:07:51 +05:30
def alerting_params
{ alerting_setting_attributes: { regenerate_token: true } }
end
2020-07-28 23:09:34 +05:30
def pagerduty_token_params
{ incident_management_setting_attributes: { regenerate_token: true } }
2020-04-08 14:13:33 +05:30
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
2022-07-16 23:28:13 +05:30
{
2020-03-13 15:44:24 +05:30
incident_management_setting_attributes: ::Gitlab::Tracking::IncidentManagement.tracking_keys.keys,
2020-06-23 00:09:42 +05:30
metrics_setting_attributes: [:external_dashboard_url, :dashboard_timezone],
2019-07-31 22:56:46 +05:30
2019-07-07 11:18:12 +05:30
error_tracking_setting_attributes: [
:enabled,
2021-11-11 11:23:49 +05:30
:integrated,
2019-07-07 11:18:12 +05:30
:api_host,
:token,
2022-07-01 11:34:44 +05:30
project: [:slug, :name, :organization_slug, :organization_name, :sentry_project_id]
2019-12-21 20:55:43 +05:30
],
2022-08-13 15:12:31 +05:30
grafana_integration_attributes: [:token, :grafana_url, :enabled]
2019-07-07 11:18:12 +05:30
}
2019-02-15 15:39:39 +05:30
end
end
end
end
2019-12-04 20:38:33 +05:30
2021-06-08 01:23:25 +05:30
Projects::Settings::OperationsController.prepend_mod_with('Projects::Settings::OperationsController')