Read about our upcoming Code of Conduct on this issue

This instance was upgraded to Heptapod 0.28.0 today

update_service.rb 1.74 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 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
15
16
17
        error_tracking_params
          .merge(metrics_setting_params)
          .merge(grafana_integration_params)
18
19
20
21
22
23
24
25
26
      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) }
Reuben Pereira's avatar
Reuben Pereira committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
      end

      def error_tracking_params
        settings = params[:error_tracking_setting_attributes]
        return {} if settings.blank?

        api_url = ErrorTracking::ProjectErrorTrackingSetting.build_api_url_from(
          api_host: settings[:api_host],
          project_slug: settings.dig(:project, :slug),
          organization_slug: settings.dig(:project, :organization_slug)
        )

        {
          error_tracking_setting_attributes: {
            api_url: api_url,
            token: settings[:token],
            enabled: settings[:enabled],
            project_name: settings.dig(:project, :name),
            organization_name: settings.dig(:project, :organization_name)
          }
        }
48
      end
49
50
51
52
53
54
55
56

      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
57
58
59
    end
  end
end
60
61

Projects::Operations::UpdateService.prepend_if_ee('::EE::Projects::Operations::UpdateService')