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

62 lines
1.7 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
module API
2021-01-03 14:25:43 +05:30
class Namespaces < ::API::Base
2017-08-17 22:00:37 +05:30
include PaginationParams
2015-09-11 14:41:01 +05:30
before { authenticate! }
2014-09-02 18:07:02 +05:30
2021-01-29 00:20:46 +05:30
feature_category :subgroups
2019-02-15 15:39:39 +05:30
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-12-04 20:38:33 +05:30
prepend_if_ee('EE::API::Namespaces') # rubocop: disable Cop/InjectEnterpriseEditionModule
2014-09-02 18:07:02 +05:30
resource :namespaces do
2016-11-03 12:29:30 +05:30
desc 'Get a namespaces list' do
success Entities::Namespace
end
params do
optional :search, type: String, desc: "Search query for namespaces"
2019-02-15 15:39:39 +05:30
2017-08-17 22:00:37 +05:30
use :pagination
2019-02-15 15:39:39 +05:30
use :optional_list_params_ee
2016-11-03 12:29:30 +05:30
end
2014-09-02 18:07:02 +05:30
get do
2016-11-03 12:29:30 +05:30
namespaces = current_user.admin ? Namespace.all : current_user.namespaces
2021-01-03 14:25:43 +05:30
namespaces = namespaces.include_route
namespaces = namespaces.include_gitlab_subscription_with_hosted_plan if Gitlab.ee?
2020-03-09 13:42:32 +05:30
2016-11-03 12:29:30 +05:30
namespaces = namespaces.search(params[:search]) if params[:search].present?
2014-09-02 18:07:02 +05:30
2019-02-15 15:39:39 +05:30
options = { with: Entities::Namespace, current_user: current_user }
present paginate(namespaces), options.reverse_merge(custom_namespace_present_options)
2014-09-02 18:07:02 +05:30
end
2018-03-17 18:26:18 +05:30
desc 'Get a namespace by ID' do
success Entities::Namespace
end
params do
requires :id, type: String, desc: "Namespace's ID or path"
end
2019-02-15 15:39:39 +05:30
get ':id', requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
2019-07-31 22:56:46 +05:30
user_namespace = find_namespace!(params[:id])
2018-03-17 18:26:18 +05:30
present user_namespace, with: Entities::Namespace, current_user: current_user
end
2014-09-02 18:07:02 +05:30
end
end
end