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

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

102 lines
3.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
2023-03-04 22:38:38 +05:30
NAMESPACES_TAGS = %w[namespaces].freeze
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
2021-06-08 01:23:25 +05:30
prepend_mod_with('API::Namespaces') # rubocop: disable Cop/InjectEnterpriseEditionModule
2019-12-04 20:38:33 +05:30
2014-09-02 18:07:02 +05:30
resource :namespaces do
2023-03-04 22:38:38 +05:30
desc 'List namespaces' do
detail 'Get a list of the namespaces of the authenticated user. If the user is an administrator, a list of all namespaces in the GitLab instance is shown.'
2016-11-03 12:29:30 +05:30
success Entities::Namespace
2023-03-04 22:38:38 +05:30
failure [
{ code: 401, message: 'Unauthorized' }
]
is_array true
tags NAMESPACES_TAGS
2016-11-03 12:29:30 +05:30
end
params do
2023-03-04 22:38:38 +05:30
optional :search, type: String, desc: 'Returns a list of namespaces the user is authorized to view based on the search criteria'
optional :owned_only, type: Boolean, desc: 'In GitLab 14.2 and later, returns a list of owned namespaces only'
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
2022-07-16 23:28:13 +05:30
get feature_category: :subgroups, urgency: :low do
2021-10-27 15:23:28 +05:30
owned_only = params[:owned_only] == true
namespaces = current_user.admin ? Namespace.all : current_user.namespaces(owned_only: owned_only)
2016-11-03 12:29:30 +05:30
2021-12-11 22:18:48 +05:30
namespaces = namespaces.without_project_namespaces.include_route
2021-01-03 14:25:43 +05:30
namespaces = namespaces.include_gitlab_subscription_with_hosted_plan if Gitlab.ee?
2020-03-13 15:44:24 +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
2023-03-04 22:38:38 +05:30
desc 'Get namespace by ID' do
detail 'Get a namespace by ID'
2018-03-17 18:26:18 +05:30
success Entities::Namespace
2023-03-04 22:38:38 +05:30
failure [
{ code: 401, message: 'Unauthorized' },
{ code: 404, message: 'Not found' }
]
tags NAMESPACES_TAGS
2018-03-17 18:26:18 +05:30
end
params do
2023-03-04 22:38:38 +05:30
requires :id, types: [String, Integer], desc: 'ID or URL-encoded path of the namespace'
2018-03-17 18:26:18 +05:30
end
2022-07-16 23:28:13 +05:30
get ':id', requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS, feature_category: :subgroups, urgency: :low 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
2021-04-29 21:17:54 +05:30
2023-03-04 22:38:38 +05:30
desc 'Get existence of a namespace' do
detail 'Get existence of a namespace by path. Suggests a new namespace path that does not already exist.'
2021-04-29 21:17:54 +05:30
success Entities::NamespaceExistence
2023-03-04 22:38:38 +05:30
failure [
{ code: 401, message: 'Unauthorized' }
]
tags NAMESPACES_TAGS
2021-04-29 21:17:54 +05:30
end
params do
2023-03-04 22:38:38 +05:30
requires :namespace, type: String, desc: "Namespaces path"
optional :parent_id, type: Integer, desc: 'The ID of the parent namespace. If no ID is specified, only top-level namespaces are considered.'
2021-04-29 21:17:54 +05:30
end
2022-07-16 23:28:13 +05:30
get ':namespace/exists', requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS, feature_category: :subgroups, urgency: :low do
2022-10-11 01:57:18 +05:30
check_rate_limit!(:namespace_exists, scope: current_user)
2021-04-29 21:17:54 +05:30
namespace_path = params[:namespace]
2022-07-23 23:45:48 +05:30
existing_namespaces_within_the_parent = Namespace.without_project_namespaces.by_parent(params[:parent_id])
2021-04-29 21:17:54 +05:30
2022-07-23 23:45:48 +05:30
exists = existing_namespaces_within_the_parent.filter_by_path(namespace_path).exists?
suggestions = exists ? [Namespace.clean_path(namespace_path, limited_to: existing_namespaces_within_the_parent)] : []
2021-04-29 21:17:54 +05:30
present :exists, exists
present :suggests, suggestions
end
2014-09-02 18:07:02 +05:30
end
end
end