Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api/feature_flags.rb')
-rw-r--r--lib/api/feature_flags.rb58
1 files changed, 12 insertions, 46 deletions
diff --git a/lib/api/feature_flags.rb b/lib/api/feature_flags.rb
index 6fdc4535be3..fb5858bc10b 100644
--- a/lib/api/feature_flags.rb
+++ b/lib/api/feature_flags.rb
@@ -90,56 +90,11 @@ module API
end
get do
authorize_read_feature_flag!
+ exclude_legacy_flags_check!
present_entity(feature_flag)
end
- desc 'Enable a strategy for a feature flag on an environment' do
- detail 'This feature was introduced in GitLab 12.5'
- success ::API::Entities::FeatureFlag
- end
- params do
- requires :environment_scope, type: String, desc: 'The environment scope of the feature flag'
- requires :strategy, type: JSON, desc: 'The strategy to be enabled on the scope'
- end
- post :enable do
- not_found! unless Feature.enabled?(:feature_flag_api, user_project)
- render_api_error!('Version 2 flags not supported', :unprocessable_entity) if new_version_flag_present?
-
- result = ::FeatureFlags::EnableService
- .new(user_project, current_user, params).execute
-
- if result[:status] == :success
- status :ok
- present_entity(result[:feature_flag])
- else
- render_api_error!(result[:message], result[:http_status])
- end
- end
-
- desc 'Disable a strategy for a feature flag on an environment' do
- detail 'This feature is going to be introduced in GitLab 12.5 if `feature_flag_api` feature flag is removed'
- success ::API::Entities::FeatureFlag
- end
- params do
- requires :environment_scope, type: String, desc: 'The environment scope of the feature flag'
- requires :strategy, type: JSON, desc: 'The strategy to be disabled on the scope'
- end
- post :disable do
- not_found! unless Feature.enabled?(:feature_flag_api, user_project)
- render_api_error!('Version 2 flags not supported', :unprocessable_entity) if feature_flag.new_version_flag?
-
- result = ::FeatureFlags::DisableService
- .new(user_project, current_user, params).execute
-
- if result[:status] == :success
- status :ok
- present_entity(result[:feature_flag])
- else
- render_api_error!(result[:message], result[:http_status])
- end
- end
-
desc 'Update a feature flag' do
detail 'This feature was introduced in GitLab 13.2'
success ::API::Entities::FeatureFlag
@@ -162,6 +117,7 @@ module API
end
put do
authorize_update_feature_flag!
+ exclude_legacy_flags_check!
render_api_error!('PUT operations are not supported for legacy feature flags', :unprocessable_entity) if feature_flag.legacy_flag?
attrs = declared_params(include_missing: false)
@@ -232,6 +188,10 @@ module API
@feature_flag ||= user_project.operations_feature_flags.find_by_name!(params[:feature_flag_name])
end
+ def project
+ @project ||= feature_flag.project
+ end
+
def new_version_flag_present?
user_project.operations_feature_flags.new_version_flag.find_by_name(params[:name]).present?
end
@@ -245,6 +205,12 @@ module API
hash[key] = yield(hash[key]) if hash.key?(key)
hash
end
+
+ def exclude_legacy_flags_check!
+ if feature_flag.legacy_flag?
+ not_found!
+ end
+ end
end
end
end