2018-09-29 22:34:47 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-11-15 13:24:10 +00:00
|
|
|
module API
|
|
|
|
class Namespaces < Grape::API
|
2016-12-04 17:11:19 +00:00
|
|
|
include PaginationParams
|
|
|
|
|
2015-05-25 20:51:37 +00:00
|
|
|
before { authenticate! }
|
2013-11-15 13:24:10 +00:00
|
|
|
|
2018-12-07 13:29:53 +00:00
|
|
|
helpers do
|
|
|
|
params :optional_list_params_ee do
|
|
|
|
# EE::API::Namespaces would override this helper
|
|
|
|
end
|
|
|
|
|
|
|
|
# EE::API::Namespaces would override this method
|
|
|
|
def custom_namespace_present_options
|
|
|
|
{}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-13 13:26:31 +00:00
|
|
|
prepend_if_ee('EE::API::Namespaces') # rubocop: disable Cop/InjectEnterpriseEditionModule
|
|
|
|
|
2013-11-15 13:24:10 +00:00
|
|
|
resource :namespaces do
|
2016-09-13 18:55:26 +00:00
|
|
|
desc 'Get a namespaces list' do
|
|
|
|
success Entities::Namespace
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
optional :search, type: String, desc: "Search query for namespaces"
|
2018-12-07 13:29:53 +00:00
|
|
|
|
2016-12-04 17:11:19 +00:00
|
|
|
use :pagination
|
2018-12-07 13:29:53 +00:00
|
|
|
use :optional_list_params_ee
|
2016-09-13 18:55:26 +00:00
|
|
|
end
|
2013-11-15 13:24:10 +00:00
|
|
|
get do
|
2016-09-13 18:55:26 +00:00
|
|
|
namespaces = current_user.admin ? Namespace.all : current_user.namespaces
|
|
|
|
|
2019-12-23 15:07:48 +00:00
|
|
|
namespaces = namespaces.include_gitlab_subscription if Gitlab.ee?
|
|
|
|
|
2016-09-13 18:55:26 +00:00
|
|
|
namespaces = namespaces.search(params[:search]) if params[:search].present?
|
2013-11-15 13:24:10 +00:00
|
|
|
|
2018-12-07 13:29:53 +00:00
|
|
|
options = { with: Entities::Namespace, current_user: current_user }
|
|
|
|
|
|
|
|
present paginate(namespaces), options.reverse_merge(custom_namespace_present_options)
|
2013-11-15 13:24:10 +00:00
|
|
|
end
|
2017-11-17 01:43:55 +00:00
|
|
|
|
|
|
|
desc 'Get a namespace by ID' do
|
|
|
|
success Entities::Namespace
|
|
|
|
end
|
|
|
|
params do
|
2017-11-23 13:32:16 +00:00
|
|
|
requires :id, type: String, desc: "Namespace's ID or path"
|
2017-11-17 01:43:55 +00:00
|
|
|
end
|
2018-11-08 12:18:17 +00:00
|
|
|
get ':id', requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
|
2019-04-24 17:39:59 +00:00
|
|
|
user_namespace = find_namespace!(params[:id])
|
|
|
|
|
2017-11-23 13:32:16 +00:00
|
|
|
present user_namespace, with: Entities::Namespace, current_user: current_user
|
2017-11-17 01:43:55 +00:00
|
|
|
end
|
2013-11-15 13:24:10 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|