Read about our upcoming Code of Conduct on this issue

operations_controller.rb 1.87 KB
Newer Older
1
2
3
4
5
# frozen_string_literal: true

module Projects
  module Settings
    class OperationsController < Projects::ApplicationController
6
      before_action :authorize_admin_operations!
7

8
9
      helper_method :error_tracking_setting

10
11
12
13
14
15
      def show
      end

      def update
        result = ::Projects::Operations::UpdateService.new(project, current_user, update_params).execute

Reuben Pereira's avatar
Reuben Pereira committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
        render_update_response(result)
      end

      private

      # overridden in EE
      def render_update_response(result)
        respond_to do |format|
          format.json do
            render_update_json_response(result)
          end
        end
      end

      def render_update_json_response(result)
31
32
        if result[:status] == :success
          flash[:notice] = _('Your changes have been saved')
Reuben Pereira's avatar
Reuben Pereira committed
33
34
35
          render json: {
            status: result[:status]
          }
36
        else
Reuben Pereira's avatar
Reuben Pereira committed
37
38
39
40
41
42
43
          render(
            status: result[:http_status] || :bad_request,
            json: {
              status: result[:status],
              message: result[:message]
            }
          )
44
45
46
        end
      end

47
48
49
50
51
      def error_tracking_setting
        @error_tracking_setting ||= project.error_tracking_setting ||
          project.build_error_tracking_setting
      end

52
53
54
55
56
57
      def update_params
        params.require(:project).permit(permitted_project_params)
      end

      # overridden in EE
      def permitted_project_params
Reuben Pereira's avatar
Reuben Pereira committed
58
        {
59
60
          metrics_setting_attributes: [:external_dashboard_url],

Reuben Pereira's avatar
Reuben Pereira committed
61
62
63
64
65
          error_tracking_setting_attributes: [
            :enabled,
            :api_host,
            :token,
            project: [:slug, :name, :organization_slug, :organization_name]
66
67
68
          ],

          grafana_integration_attributes: [:token, :grafana_url]
Reuben Pereira's avatar
Reuben Pereira committed
69
        }
70
71
72
73
      end
    end
  end
end
74
75

Projects::Settings::OperationsController.prepend_if_ee('::EE::Projects::Settings::OperationsController')