Commit eb97c21b authored by Shinya Maeda's avatar Shinya Maeda

Merge branch 'support-switch-strategy' into 'master'

Support Changing Type of Feature Flag Strategy from gitlabUserList

See merge request gitlab-org/gitlab!33426
parents 42893446 0104420a
......@@ -14,6 +14,12 @@ module FeatureFlags
ActiveRecord::Base.transaction do
feature_flag.assign_attributes(params)
feature_flag.strategies.each do |strategy|
if strategy.name_changed? && strategy.name_was == ::Operations::FeatureFlags::Strategy::STRATEGY_GITLABUSERLIST
strategy.user_list = nil
end
end
audit_event = audit_event(feature_flag)
if feature_flag.save
......
......@@ -1427,6 +1427,39 @@ RSpec.describe Projects::FeatureFlagsController do
}])
end
it 'automatically dissociates the user list when switching the type of an existing gitlabUserList strategy' do
user_list = create(:operations_feature_flag_user_list, project: project, name: 'My List', user_xids: 'user1,user2')
strategy = create(:operations_strategy, feature_flag: new_version_flag, name: 'gitlabUserList', parameters: {}, user_list: user_list)
params = {
namespace_id: project.namespace,
project_id: project,
iid: new_version_flag.iid,
operations_feature_flag: {
strategies_attributes: [{
id: strategy.id,
name: 'gradualRolloutUserId',
parameters: {
groupId: 'default',
percentage: '25'
}
}]
}
}
put(:update, params: params, format: :json)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['strategies']).to eq([{
'id' => strategy.id,
'name' => 'gradualRolloutUserId',
'parameters' => {
'groupId' => 'default',
'percentage' => '25'
},
'scopes' => []
}])
end
it 'does not delete a user list when deleting a gitlabUserList strategy' do
user_list = create(:operations_feature_flag_user_list, project: project, name: 'My List', user_xids: 'user1,user2')
strategy = create(:operations_strategy, feature_flag: new_version_flag, name: 'gitlabUserList', parameters: {}, user_list: user_list)
......
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