2018-09-29 22:34:47 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-08-25 05:38:54 +00:00
|
|
|
module API
|
2020-10-15 00:08:42 +00:00
|
|
|
class ProtectedTags < ::API::Base
|
2018-08-25 05:38:54 +00:00
|
|
|
include PaginationParams
|
|
|
|
|
2018-11-08 12:18:17 +00:00
|
|
|
TAG_ENDPOINT_REQUIREMENTS = API::NAMESPACE_OR_PROJECT_REQUIREMENTS.merge(name: API::NO_SLASH_URL_PART_REGEX)
|
2018-08-25 05:38:54 +00:00
|
|
|
|
|
|
|
before { authorize_admin_project }
|
|
|
|
|
2020-10-30 18:08:56 +00:00
|
|
|
feature_category :source_code_management
|
|
|
|
|
2022-07-13 21:10:15 +00:00
|
|
|
helpers Helpers::ProtectedTagsHelpers
|
|
|
|
|
2018-08-25 05:38:54 +00:00
|
|
|
params do
|
2022-11-03 15:11:31 +00:00
|
|
|
requires :id, types: [String, Integer], desc: 'The ID or URL-encoded path of the project'
|
2018-08-25 05:38:54 +00:00
|
|
|
end
|
2018-11-08 12:18:17 +00:00
|
|
|
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
|
2018-08-25 05:38:54 +00:00
|
|
|
desc "Get a project's protected tags" do
|
|
|
|
detail 'This feature was introduced in GitLab 11.3.'
|
2022-11-02 21:09:03 +00:00
|
|
|
is_array true
|
|
|
|
success code: 200, model: Entities::ProtectedTag
|
|
|
|
failure [
|
|
|
|
{ code: 403, message: 'Unauthenticated' },
|
|
|
|
{ code: 404, message: 'Not found' }
|
|
|
|
]
|
|
|
|
tags %w[protected_tags]
|
2018-08-25 05:38:54 +00:00
|
|
|
end
|
|
|
|
params do
|
|
|
|
use :pagination
|
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-08-25 05:38:54 +00:00
|
|
|
get ':id/protected_tags' do
|
|
|
|
protected_tags = user_project.protected_tags.preload(:create_access_levels)
|
|
|
|
|
|
|
|
present paginate(protected_tags), with: Entities::ProtectedTag, project: user_project
|
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-08-25 05:38:54 +00:00
|
|
|
|
|
|
|
desc 'Get a single protected tag' do
|
|
|
|
detail 'This feature was introduced in GitLab 11.3.'
|
2022-11-02 21:09:03 +00:00
|
|
|
success code: 200, model: Entities::ProtectedTag
|
|
|
|
failure [
|
|
|
|
{ code: 403, message: 'Unauthenticated' },
|
|
|
|
{ code: 404, message: 'Not found' }
|
|
|
|
]
|
|
|
|
tags %w[protected_tags]
|
2018-08-25 05:38:54 +00:00
|
|
|
end
|
|
|
|
params do
|
2022-11-02 21:09:03 +00:00
|
|
|
requires :name, type: String, desc: 'The name of the tag or wildcard', documentation: { example: 'release*' }
|
2018-08-25 05:38:54 +00:00
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-08-25 05:38:54 +00:00
|
|
|
get ':id/protected_tags/:name', requirements: TAG_ENDPOINT_REQUIREMENTS do
|
|
|
|
protected_tag = user_project.protected_tags.find_by!(name: params[:name])
|
|
|
|
|
|
|
|
present protected_tag, with: Entities::ProtectedTag, project: user_project
|
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-08-25 05:38:54 +00:00
|
|
|
|
|
|
|
desc 'Protect a single tag or wildcard' do
|
|
|
|
detail 'This feature was introduced in GitLab 11.3.'
|
2022-11-02 21:09:03 +00:00
|
|
|
success code: 201, model: Entities::ProtectedTag
|
|
|
|
failure [
|
|
|
|
{ code: 403, message: 'Unauthenticated' },
|
|
|
|
{ code: 404, message: 'Not found' },
|
|
|
|
{ code: 422, message: 'Unprocessable entity' }
|
|
|
|
]
|
|
|
|
tags %w[protected_tags]
|
2018-08-25 05:38:54 +00:00
|
|
|
end
|
|
|
|
params do
|
2022-11-02 21:09:03 +00:00
|
|
|
requires :name, type: String, desc: 'The name of the protected tag', documentation: { example: 'release-1-0' }
|
|
|
|
optional :create_access_level,
|
|
|
|
type: Integer,
|
|
|
|
values: ProtectedTag::CreateAccessLevel.allowed_access_levels,
|
|
|
|
desc: 'Access levels allowed to create (defaults: `40`, maintainer access level)',
|
|
|
|
documentation: { example: 30 }
|
2022-07-13 21:10:15 +00:00
|
|
|
use :optional_params_ee
|
2018-08-25 05:38:54 +00:00
|
|
|
end
|
|
|
|
post ':id/protected_tags' do
|
|
|
|
protected_tags_params = {
|
|
|
|
name: params[:name],
|
2022-07-13 21:10:15 +00:00
|
|
|
create_access_levels_attributes: ::ProtectedRefs::AccessLevelParams.new(:create, params).access_levels
|
2018-08-25 05:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected_tag = ::ProtectedTags::CreateService.new(user_project,
|
|
|
|
current_user,
|
|
|
|
protected_tags_params).execute
|
|
|
|
|
|
|
|
if protected_tag.persisted?
|
|
|
|
present protected_tag, with: Entities::ProtectedTag, project: user_project
|
|
|
|
else
|
|
|
|
render_api_error!(protected_tag.errors.full_messages, 422)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Unprotect a single tag' do
|
|
|
|
detail 'This feature was introduced in GitLab 11.3.'
|
2022-11-02 21:09:03 +00:00
|
|
|
success code: 204
|
|
|
|
failure [
|
|
|
|
{ code: 403, message: 'Unauthenticated' },
|
|
|
|
{ code: 404, message: 'Not found' },
|
|
|
|
{ code: 412, message: 'Precondition Failed' }
|
|
|
|
]
|
|
|
|
tags %w[protected_tags]
|
2018-08-25 05:38:54 +00:00
|
|
|
end
|
|
|
|
params do
|
2022-11-02 21:09:03 +00:00
|
|
|
requires :name, type: String, desc: 'The name of the protected tag', documentation: { example: 'release-1-0' }
|
2018-08-25 05:38:54 +00:00
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-08-25 05:38:54 +00:00
|
|
|
delete ':id/protected_tags/:name', requirements: TAG_ENDPOINT_REQUIREMENTS do
|
|
|
|
protected_tag = user_project.protected_tags.find_by!(name: params[:name])
|
|
|
|
|
|
|
|
destroy_conditionally!(protected_tag)
|
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-08-25 05:38:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|