summaryrefslogtreecommitdiff
path: root/lib/api/features.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-10-20 09:40:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-10-20 09:40:42 +0000
commitee664acb356f8123f4f6b00b73c1e1cf0866c7fb (patch)
treef8479f94a28f66654c6a4f6fb99bad6b4e86a40e /lib/api/features.rb
parent62f7d5c5b69180e82ae8196b7b429eeffc8e7b4f (diff)
downloadgitlab-ce-ee664acb356f8123f4f6b00b73c1e1cf0866c7fb.tar.gz
Add latest changes from gitlab-org/gitlab@15-5-stable-eev15.5.0-rc42
Diffstat (limited to 'lib/api/features.rb')
-rw-r--r--lib/api/features.rb62
1 files changed, 39 insertions, 23 deletions
diff --git a/lib/api/features.rb b/lib/api/features.rb
index f89da48acea..9d4e6eee82c 100644
--- a/lib/api/features.rb
+++ b/lib/api/features.rb
@@ -7,6 +7,7 @@ module API
feature_category :feature_flags
urgency :low
+ # TODO: remove these helpers with feature flag set_feature_flag_service
helpers do
def gate_value(params)
case params[:value]
@@ -87,35 +88,49 @@ module API
mutually_exclusive :key, :project
end
post ':name' do
- validate_feature_flag_name!(params[:name]) unless params[:force]
-
- targets = gate_targets(params)
- value = gate_value(params)
- key = gate_key(params)
-
- case value
- when true
- if gate_specified?(params)
- targets.each { |target| Feature.enable(params[:name], target) }
- else
- Feature.enable(params[:name])
- end
- when false
- if gate_specified?(params)
- targets.each { |target| Feature.disable(params[:name], target) }
+ if Feature.enabled?(:set_feature_flag_service)
+ flag_params = declared_params(include_missing: false)
+ response = ::Admin::SetFeatureFlagService
+ .new(feature_flag_name: params[:name], params: flag_params)
+ .execute
+
+ if response.success?
+ present response.payload[:feature_flag],
+ with: Entities::Feature, current_user: current_user
else
- Feature.disable(params[:name])
+ bad_request!(response.message)
end
else
- if key == :percentage_of_actors
- Feature.enable_percentage_of_actors(params[:name], value)
+ validate_feature_flag_name!(params[:name]) unless params[:force]
+
+ targets = gate_targets(params)
+ value = gate_value(params)
+ key = gate_key(params)
+
+ case value
+ when true
+ if gate_specified?(params)
+ targets.each { |target| Feature.enable(params[:name], target) }
+ else
+ Feature.enable(params[:name])
+ end
+ when false
+ if gate_specified?(params)
+ targets.each { |target| Feature.disable(params[:name], target) }
+ else
+ Feature.disable(params[:name])
+ end
else
- Feature.enable_percentage_of_time(params[:name], value)
+ if key == :percentage_of_actors
+ Feature.enable_percentage_of_actors(params[:name], value)
+ else
+ Feature.enable_percentage_of_time(params[:name], value)
+ end
end
- end
- present Feature.get(params[:name]), # rubocop:disable Gitlab/AvoidFeatureGet
- with: Entities::Feature, current_user: current_user
+ present Feature.get(params[:name]), # rubocop:disable Gitlab/AvoidFeatureGet
+ with: Entities::Feature, current_user: current_user
+ end
rescue Feature::Target::UnknowTargetError => e
bad_request!(e.message)
end
@@ -128,6 +143,7 @@ module API
end
end
+ # TODO: remove this helper with feature flag set_feature_flag_service
helpers do
def validate_feature_flag_name!(name)
# no-op