summaryrefslogtreecommitdiff
path: root/app/controllers/projects/security/configuration_controller.rb
blob: cdb02047215c9ee9d419bef8c74a194c1b44be6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# frozen_string_literal: true

module Projects
  module Security
    class ConfigurationController < Projects::ApplicationController
      include SecurityAndCompliancePermissions

      feature_category :static_application_security_testing, [:show]
      urgency :low, [:show]

      def show
        render_403 unless can?(current_user, :read_security_configuration, project)

        @configuration ||= configuration_presenter

        respond_to do |format|
          format.html
          format.json do
            render status: :ok, json: configuration.to_h
          end
        end
      end

      private

      def configuration
        if unify_configuration_enabled?
          configuration_presenter
        else
          {}
        end
      end

      def configuration_presenter
        ::Projects::Security::ConfigurationPresenter.new(project,
                                                         **presenter_attributes,
                                                         current_user: current_user)
      end

      def presenter_attributes
        {}
      end

      def unify_configuration_enabled?
        Feature.enabled?(:unify_security_configuration, project, default_enabled: :yaml)
      end
    end
  end
end

Projects::Security::ConfigurationController.prepend_mod_with('Projects::Security::ConfigurationController')