Commit 4b5da3c2 authored by Sashi Kumar Kumaresan's avatar Sashi Kumar Kumaresan Committed by Alex Kalderimis

Fix feature flag check for security policy project

This change fixes a bug due to checking
feature flag for the newly created security policy project
rather than the target project.

EE: true
Changelog: fixed
parent ea72d0ff
...@@ -55,18 +55,18 @@ module EE ...@@ -55,18 +55,18 @@ module EE
override :after_create_actions override :after_create_actions
def after_create_actions def after_create_actions
super do super do
create_security_policy_configuration if security_policy_target_project? create_security_policy_configuration_if_exists
end end
create_predefined_push_rule create_predefined_push_rule
end end
def security_policy_target_project? def create_security_policy_configuration_if_exists
security_policy_target_project_id && ::Feature.enabled?(:security_orchestration_policies_configuration, project) return unless security_policy_target_project_id.present?
end
def create_security_policy_configuration
if (security_policy_target_project = ::Project.find(security_policy_target_project_id)) if (security_policy_target_project = ::Project.find(security_policy_target_project_id))
return unless ::Feature.enabled?(:security_orchestration_policies_configuration, security_policy_target_project)
::Security::Orchestration::AssignService ::Security::Orchestration::AssignService
.new(security_policy_target_project, current_user, policy_project_id: project.id) .new(security_policy_target_project, current_user, policy_project_id: project.id)
.execute .execute
......
...@@ -367,7 +367,7 @@ RSpec.describe Projects::CreateService, '#execute' do ...@@ -367,7 +367,7 @@ RSpec.describe Projects::CreateService, '#execute' do
stub_feature_flags(security_orchestration_policies_configuration: feature_enabled) stub_feature_flags(security_orchestration_policies_configuration: feature_enabled)
end end
context 'when feature flag is enabled' do context 'when feature flag is enabled globally' do
let_it_be(:feature_enabled) { true } let_it_be(:feature_enabled) { true }
it 'creates security policy configuration for the project' do it 'creates security policy configuration for the project' do
...@@ -377,7 +377,7 @@ RSpec.describe Projects::CreateService, '#execute' do ...@@ -377,7 +377,7 @@ RSpec.describe Projects::CreateService, '#execute' do
end end
end end
context 'when feature flag is disabled' do context 'when feature flag is disabled globally' do
let_it_be(:feature_enabled) { false } let_it_be(:feature_enabled) { false }
it 'does not create security policy configuration' do it 'does not create security policy configuration' do
...@@ -386,6 +386,16 @@ RSpec.describe Projects::CreateService, '#execute' do ...@@ -386,6 +386,16 @@ RSpec.describe Projects::CreateService, '#execute' do
create_project(user, opts) create_project(user, opts)
end end
end end
context 'when feature flag is enabled only for target project' do
let_it_be(:feature_enabled) { security_policy_target_project }
it 'creates security policy configuration' do
expect(::Security::Orchestration::AssignService).to receive_message_chain(:new, :execute)
create_project(user, opts)
end
end
end end
def create_project(user, opts) def create_project(user, opts)
......
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