debian-mirror-gitlab/lib/api/feature_flags_user_lists.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

157 lines
5.8 KiB
Ruby
Raw Normal View History

2021-01-03 14:25:43 +05:30
# frozen_string_literal: true
module API
class FeatureFlagsUserLists < ::API::Base
include PaginationParams
2023-01-13 00:05:48 +05:30
feature_flags_user_lists_tags = %w[feature_flags_user_lists]
2021-01-03 14:25:43 +05:30
error_formatter :json, -> (message, _backtrace, _options, _env, _original_exception) {
message.is_a?(String) ? { message: message }.to_json : message.to_json
}
2021-01-29 00:20:46 +05:30
feature_category :feature_flags
2022-07-16 23:28:13 +05:30
urgency :low
2021-01-29 00:20:46 +05:30
2021-01-03 14:25:43 +05:30
before do
authorize_admin_feature_flags_user_lists!
end
params do
2023-01-13 00:05:48 +05:30
requires :id, types: [String, Integer], desc: 'The ID or URL-encoded path of the project'
2021-01-03 14:25:43 +05:30
end
resource 'projects/:id', requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
resource :feature_flags_user_lists do
2023-01-13 00:05:48 +05:30
desc 'List all feature flag user lists for a project' do
detail 'Gets all feature flag user lists for the requested project. ' \
'This feature was introduced in GitLab 12.10.'
2021-01-03 14:25:43 +05:30
success ::API::Entities::FeatureFlag::UserList
2023-01-13 00:05:48 +05:30
failure [
{ code: 401, message: 'Unauthorized' },
{ code: 404, message: 'Not found' }
]
is_array true
tags feature_flags_user_lists_tags
2021-01-03 14:25:43 +05:30
end
params do
2023-01-13 00:05:48 +05:30
optional :search, type: String, desc: 'Return user lists matching the search criteria'
2021-01-29 00:20:46 +05:30
2021-01-03 14:25:43 +05:30
use :pagination
end
get do
2021-01-29 00:20:46 +05:30
user_lists = ::FeatureFlagsUserListsFinder.new(user_project, current_user, params).execute
present paginate(user_lists),
2021-01-03 14:25:43 +05:30
with: ::API::Entities::FeatureFlag::UserList
end
2023-01-13 00:05:48 +05:30
desc 'Create a feature flag user list' do
detail 'Creates a feature flag user list. This feature was introduced in GitLab 12.10.'
2021-01-03 14:25:43 +05:30
success ::API::Entities::FeatureFlag::UserList
2023-01-13 00:05:48 +05:30
failure [
{ code: 400, message: 'Bad request' },
{ code: 401, message: 'Unauthorized' },
{ code: 404, message: 'Not found' }
]
tags feature_flags_user_lists_tags
2021-01-03 14:25:43 +05:30
end
params do
requires :name, type: String, desc: 'The name of the list'
requires :user_xids, type: String, desc: 'A comma separated list of external user ids'
end
post do
2022-08-13 15:12:31 +05:30
# TODO: Move the business logic to a service class in app/services/feature_flags.
# https://gitlab.com/gitlab-org/gitlab/-/issues/367021
2021-01-03 14:25:43 +05:30
list = user_project.operations_feature_flags_user_lists.create(declared_params)
if list.save
2022-08-13 15:12:31 +05:30
update_last_feature_flag_updated_at!
2021-01-03 14:25:43 +05:30
present list, with: ::API::Entities::FeatureFlag::UserList
else
render_api_error!(list.errors.full_messages, :bad_request)
end
end
end
params do
2023-01-13 00:05:48 +05:30
requires :iid, types: [String, Integer], desc: "The internal ID of the project's feature flag user list"
2021-01-03 14:25:43 +05:30
end
resource 'feature_flags_user_lists/:iid' do
2023-01-13 00:05:48 +05:30
desc 'Get a feature flag user list' do
detail 'Gets a feature flag user list. This feature was introduced in GitLab 12.10.'
2021-01-03 14:25:43 +05:30
success ::API::Entities::FeatureFlag::UserList
2023-01-13 00:05:48 +05:30
failure [
{ code: 401, message: 'Unauthorized' },
{ code: 404, message: 'Not found' }
]
tags feature_flags_user_lists_tags
2021-01-03 14:25:43 +05:30
end
get do
present user_project.operations_feature_flags_user_lists.find_by_iid!(params[:iid]),
with: ::API::Entities::FeatureFlag::UserList
end
desc 'Update a feature flag user list' do
2023-01-13 00:05:48 +05:30
detail 'Updates a feature flag user list. This feature was introduced in GitLab 12.10.'
2021-01-03 14:25:43 +05:30
success ::API::Entities::FeatureFlag::UserList
2023-01-13 00:05:48 +05:30
failure [
{ code: 400, message: 'Bad request' },
{ code: 401, message: 'Unauthorized' },
{ code: 404, message: 'Not found' }
]
tags feature_flags_user_lists_tags
2021-01-03 14:25:43 +05:30
end
params do
optional :name, type: String, desc: 'The name of the list'
optional :user_xids, type: String, desc: 'A comma separated list of external user ids'
end
put do
2022-08-13 15:12:31 +05:30
# TODO: Move the business logic to a service class in app/services/feature_flags.
# https://gitlab.com/gitlab-org/gitlab/-/issues/367021
2021-01-03 14:25:43 +05:30
list = user_project.operations_feature_flags_user_lists.find_by_iid!(params[:iid])
if list.update(declared_params(include_missing: false))
2022-08-13 15:12:31 +05:30
update_last_feature_flag_updated_at!
2021-01-03 14:25:43 +05:30
present list, with: ::API::Entities::FeatureFlag::UserList
else
render_api_error!(list.errors.full_messages, :bad_request)
end
end
2023-01-13 00:05:48 +05:30
desc 'Delete feature flag user list' do
detail 'Deletes a feature flag user list. This feature was introduced in GitLab 12.10.'
failure [
{ code: 401, message: 'Unauthorized' },
{ code: 404, message: 'Not found' },
{ code: 409, message: 'Conflict' }
]
tags feature_flags_user_lists_tags
2021-01-03 14:25:43 +05:30
end
delete do
2022-08-13 15:12:31 +05:30
# TODO: Move the business logic to a service class in app/services/feature_flags.
# https://gitlab.com/gitlab-org/gitlab/-/issues/367021
2021-01-03 14:25:43 +05:30
list = user_project.operations_feature_flags_user_lists.find_by_iid!(params[:iid])
2022-08-13 15:12:31 +05:30
if list.destroy
update_last_feature_flag_updated_at!
nil
else
2021-01-03 14:25:43 +05:30
render_api_error!(list.errors.full_messages, :conflict)
end
end
end
end
helpers do
def authorize_admin_feature_flags_user_lists!
authorize! :admin_feature_flags_user_lists, user_project
end
2022-08-13 15:12:31 +05:30
def update_last_feature_flag_updated_at!
Operations::FeatureFlagsClient.update_last_feature_flag_updated_at!(user_project)
end
2021-01-03 14:25:43 +05:30
end
end
end