1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
# frozen_string_literal: true
module API
class FeatureFlagsUserLists < ::API::Base
include PaginationParams
feature_flags_user_lists_tags = %w[feature_flags_user_lists]
error_formatter :json, ->(message, _backtrace, _options, _env, _original_exception) {
message.is_a?(String) ? { message: message }.to_json : message.to_json
}
feature_category :feature_flags
urgency :low
before do
authorize_admin_feature_flags_user_lists!
end
params do
requires :id, types: [String, Integer], desc: 'The ID or URL-encoded path of the project'
end
resource 'projects/:id', requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
resource :feature_flags_user_lists do
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.'
success ::API::Entities::FeatureFlag::UserList
failure [
{ code: 401, message: 'Unauthorized' },
{ code: 404, message: 'Not found' }
]
is_array true
tags feature_flags_user_lists_tags
end
params do
optional :search, type: String, desc: 'Return user lists matching the search criteria'
use :pagination
end
get do
user_lists = ::FeatureFlagsUserListsFinder.new(user_project, current_user, params).execute
present paginate(user_lists),
with: ::API::Entities::FeatureFlag::UserList
end
desc 'Create a feature flag user list' do
detail 'Creates a feature flag user list. This feature was introduced in GitLab 12.10.'
success ::API::Entities::FeatureFlag::UserList
failure [
{ code: 400, message: 'Bad request' },
{ code: 401, message: 'Unauthorized' },
{ code: 404, message: 'Not found' }
]
tags feature_flags_user_lists_tags
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
# TODO: Move the business logic to a service class in app/services/feature_flags.
# https://gitlab.com/gitlab-org/gitlab/-/issues/367021
list = user_project.operations_feature_flags_user_lists.create(declared_params)
if list.save
update_last_feature_flag_updated_at!
present list, with: ::API::Entities::FeatureFlag::UserList
else
render_api_error!(list.errors.full_messages, :bad_request)
end
end
end
params do
requires :iid, types: [String, Integer], desc: "The internal ID of the project's feature flag user list"
end
resource 'feature_flags_user_lists/:iid' do
desc 'Get a feature flag user list' do
detail 'Gets a feature flag user list. This feature was introduced in GitLab 12.10.'
success ::API::Entities::FeatureFlag::UserList
failure [
{ code: 401, message: 'Unauthorized' },
{ code: 404, message: 'Not found' }
]
tags feature_flags_user_lists_tags
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
detail 'Updates a feature flag user list. This feature was introduced in GitLab 12.10.'
success ::API::Entities::FeatureFlag::UserList
failure [
{ code: 400, message: 'Bad request' },
{ code: 401, message: 'Unauthorized' },
{ code: 404, message: 'Not found' }
]
tags feature_flags_user_lists_tags
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
# TODO: Move the business logic to a service class in app/services/feature_flags.
# https://gitlab.com/gitlab-org/gitlab/-/issues/367021
list = user_project.operations_feature_flags_user_lists.find_by_iid!(params[:iid])
if list.update(declared_params(include_missing: false))
update_last_feature_flag_updated_at!
present list, with: ::API::Entities::FeatureFlag::UserList
else
render_api_error!(list.errors.full_messages, :bad_request)
end
end
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
end
delete do
# TODO: Move the business logic to a service class in app/services/feature_flags.
# https://gitlab.com/gitlab-org/gitlab/-/issues/367021
list = user_project.operations_feature_flags_user_lists.find_by_iid!(params[:iid])
if list.destroy
update_last_feature_flag_updated_at!
nil
else
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
def update_last_feature_flag_updated_at!
Operations::FeatureFlagsClient.update_last_feature_flag_updated_at!(user_project)
end
end
end
end
|