Skip to content
Snippets Groups Projects
Verified Commit 1b238156 authored by Tetiana Chupryna's avatar Tetiana Chupryna :sunflower:
Browse files

Add configuration response to FOSS

To unify codebase for Security Configuration page
we need to start responsing with Configuration details
for json request for FOSS Configuration controller

Issue #339023
parent 7ef2f115
No related branches found
No related tags found
1 merge request!76866Unify Security Configuration between EE and CE
......@@ -9,6 +9,37 @@ class ConfigurationController < Projects::ApplicationController
def show
render_403 unless can?(current_user, :read_security_configuration, project)
respond_to do |format|
format.html
format.json do
render status: :ok, json: configuration.to_h
end
end
end
private
def configuration
@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
......
---
name: unify_security_configuration
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/76866
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/350177
milestone: '14.7'
type: development
group: group::composition analysis
default_enabled: false
......@@ -32,13 +32,12 @@ module ConfigurationController
def show
return super unless security_dashboard_feature_enabled? && can_read_security_dashboard?
@configuration = ::Projects::Security::ConfigurationPresenter.new(project,
auto_fix_permission: auto_fix_authorized?,
current_user: current_user)
configuration
respond_to do |format|
format.html
format.json do
render status: :ok, json: @configuration.to_h
render status: :ok, json: configuration.to_h
end
end
end
......@@ -77,6 +76,11 @@ def check_feature_flag!
render_404 if ::Feature.disabled?(:security_auto_fix, project)
end
override :configuration
def configuration
@configuration ||= configuration_presenter
end
def security_dashboard_feature_enabled?
vulnerable.feature_available?(:security_dashboard)
end
......@@ -92,6 +96,11 @@ def ensure_security_dashboard_feature_enabled!
def authorize_read_security_dashboard!
render_403 unless can_read_security_dashboard?
end
override :presenter_attributes
def presenter_attributes
{ auto_fix_permission: auto_fix_authorized? }
end
end
end
end
......
......@@ -36,6 +36,31 @@
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:show)
end
it 'responds with configuration data json' do
get :show, params: { namespace_id: project.namespace, project_id: project, format: :json }
features = json_response['features']
sast_feature = features.find { |feature| feature['type'] == 'sast' }
dast_feature = features.find { |feature| feature['type'] == 'dast' }
expect(response).to have_gitlab_http_status(:ok)
expect(sast_feature['available']).to be_truthy
expect(dast_feature['available']).to be_falsey
end
context 'with feature flag unify_security_configuration turned off' do
before do
stub_feature_flags(unify_security_configuration: false)
end
it 'responds with empty configuration data json' do
get :show, params: { namespace_id: project.namespace, project_id: project, format: :json }
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to be_empty
end
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment