Commit 356491bd authored by Etienne Baqué's avatar Etienne Baqué

Merge branch '339023-unify-configuration-ee-ce' into 'master'

Unify Security Configuration between EE and CE

See merge request gitlab-org/gitlab!76866
parents a7c77762 c86b24c8
......@@ -9,6 +9,37 @@ module Projects
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
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,9 +32,8 @@ module EE
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 ||= configuration_presenter
respond_to do |format|
format.html
format.json do
......@@ -92,6 +91,11 @@ module EE
def authorize_read_security_dashboard!
render_403 unless can_read_security_dashboard?
end
override :presenter_attributes
def presenter_attributes
super.merge({ auto_fix_permission: auto_fix_authorized? })
end
end
end
end
......
......@@ -36,6 +36,31 @@ RSpec.describe Projects::Security::ConfigurationController do
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment