debian-mirror-gitlab/app/services/projects/operations/update_service.rb

100 lines
3.2 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
module Projects
module Operations
class UpdateService < BaseService
def execute
Projects::UpdateService
.new(project, current_user, project_update_params)
.execute
end
private
def project_update_params
2019-12-21 20:55:43 +05:30
error_tracking_params
.merge(metrics_setting_params)
.merge(grafana_integration_params)
2020-03-09 13:42:32 +05:30
.merge(prometheus_integration_params)
.merge(incident_management_setting_params)
2019-07-31 22:56:46 +05:30
end
def metrics_setting_params
attribs = params[:metrics_setting_attributes]
return {} unless attribs
destroy = attribs[:external_dashboard_url].blank?
{ metrics_setting_attributes: attribs.merge(_destroy: destroy) }
2019-07-07 11:18:12 +05:30
end
def error_tracking_params
settings = params[:error_tracking_setting_attributes]
return {} if settings.blank?
2020-03-09 13:42:32 +05:30
if error_tracking_params_partial_updates?(settings)
error_tracking_params_for_partial_update(settings)
else
error_tracking_params_for_update(settings)
end
end
def error_tracking_params_partial_updates?(settings)
# Help from @splattael :bow:
# Make sure we're converting to symbols because
# * ActionController::Parameters#keys returns a list of strings
# * in specs we're using hashes with symbols as keys
settings.keys.map(&:to_sym) == %i[enabled]
end
def error_tracking_params_for_partial_update(settings)
{ error_tracking_setting_attributes: settings }
end
def error_tracking_params_for_update(settings)
api_url = ::ErrorTracking::ProjectErrorTrackingSetting.build_api_url_from(
2019-07-07 11:18:12 +05:30
api_host: settings[:api_host],
project_slug: settings.dig(:project, :slug),
organization_slug: settings.dig(:project, :organization_slug)
)
2019-10-31 01:37:42 +05:30
params = {
2019-07-07 11:18:12 +05:30
error_tracking_setting_attributes: {
api_url: api_url,
enabled: settings[:enabled],
project_name: settings.dig(:project, :name),
organization_name: settings.dig(:project, :organization_name)
}
}
2019-10-31 01:37:42 +05:30
params[:error_tracking_setting_attributes][:token] = settings[:token] unless /\A\*+\z/.match?(settings[:token]) # Don't update token if we receive masked value
params
2019-02-15 15:39:39 +05:30
end
2019-12-21 20:55:43 +05:30
def grafana_integration_params
return {} unless attrs = params[:grafana_integration_attributes]
destroy = attrs[:grafana_url].blank? && attrs[:token].blank?
{ grafana_integration_attributes: attrs.merge(_destroy: destroy) }
end
2020-03-09 13:42:32 +05:30
def prometheus_integration_params
return {} unless attrs = params[:prometheus_integration_attributes]
service = project.find_or_initialize_service(::PrometheusService.to_param)
service.assign_attributes(attrs)
{ prometheus_service_attributes: service.attributes.except(*%w(id project_id created_at updated_at)) }
end
def incident_management_setting_params
params.slice(:incident_management_setting_attributes)
end
2019-02-15 15:39:39 +05:30
end
end
end
2019-12-04 20:38:33 +05:30
Projects::Operations::UpdateService.prepend_if_ee('::EE::Projects::Operations::UpdateService')