Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2019-01-03 14:37:02 +0300
committerShinya Maeda <shinya@gitlab.com>2019-01-07 08:07:05 +0300
commit124905e23b6d23253aee461f9d89d434a7b5b44b (patch)
tree89c8dd45251e8c8d7030d922d95473480a80f1c5 /lib
parentb83be5032716548ea9d738a03e0a20f660dc04ac (diff)
Add API for release asset links
Authorize against release not project
Diffstat (limited to 'lib')
-rw-r--r--lib/api/api.rb1
-rw-r--r--lib/api/release/link.rb116
2 files changed, 117 insertions, 0 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb
index 72f979220d7..59b67c67f9d 100644
--- a/lib/api/api.rb
+++ b/lib/api/api.rb
@@ -141,6 +141,7 @@ module API
mount ::API::ProtectedBranches
mount ::API::ProtectedTags
mount ::API::Releases
+ mount ::API::Release::Links
mount ::API::Repositories
mount ::API::Runner
mount ::API::Runners
diff --git a/lib/api/release/link.rb b/lib/api/release/link.rb
new file mode 100644
index 00000000000..cde61aefd67
--- /dev/null
+++ b/lib/api/release/link.rb
@@ -0,0 +1,116 @@
+# frozen_string_literal: true
+
+module API
+ module Release
+ class Links < Grape::API
+ include PaginationParams
+
+ RELEASE_ENDPOINT_REQUIREMETS = API::NAMESPACE_OR_PROJECT_REQUIREMENTS
+ .merge(tag_name: API::NO_SLASH_URL_PART_REGEX)
+
+ before { error!('404 Not Found', 404) unless Feature.enabled?(:releases_page, user_project) }
+
+ params do
+ requires :id, type: String, desc: 'The ID of a project'
+ end
+ resource 'projects/:id', requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
+ resource 'releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMETS do
+ resource :assets do
+ desc 'Get a list of links of a release' do
+ detail 'This feature was introduced in GitLab 11.7.'
+ success Entities::Releases::Link
+ end
+ params do
+ use :pagination
+ end
+ get 'links' do
+ authorize! :read_release, release
+
+ present paginate(release.links), with: Entities::Releases::Link
+ end
+
+ desc 'Get a link detail of a release' do
+ detail 'This feature was introduced in GitLab 11.7.'
+ success Entities::Releases::Link
+ end
+ params do
+ requires :link_id, type: String, desc: 'The id of the link'
+ end
+ get 'links/:link_id' do
+ authorize! :read_release, release
+
+ present link, with: Entities::Releases::Link
+ end
+
+ desc 'Create a link of a release' do
+ detail 'This feature was introduced in GitLab 11.7.'
+ success Entities::Releases::Link
+ end
+ params do
+ requires :name, type: String, desc: 'The name of the link'
+ requires :url, type: String, desc: 'The URL of the link'
+ end
+ post 'links' do
+ authorize! :create_release, release
+
+ new_link = release.links.create(declared_params(include_missing: false))
+
+ if new_link.persisted?
+ present new_link, with: Entities::Releases::Link
+ else
+ render_api_error!(result[:message], result[:http_status])
+ end
+ end
+
+ desc 'Update a link of a release' do
+ detail 'This feature was introduced in GitLab 11.7.'
+ success Entities::Releases::Link
+ end
+ params do
+ requires :link_id, type: Integer, desc: 'The id of the link'
+ optional :name, type: String, desc: 'The name of the link'
+ optional :url, type: String, desc: 'The URL of the link'
+ at_least_one_of :name, :url
+ end
+ put 'links/:link_id' do
+ authorize! :update_release, release
+
+ if link.update(declared_params(include_missing: false))
+ present link, with: Entities::Releases::Link
+ else
+ render_api_error!(result[:message], result[:http_status])
+ end
+ end
+
+ desc 'Delete a link of a release' do
+ detail 'This feature was introduced in GitLab 11.7.'
+ success Entities::Releases::Link
+ end
+ params do
+ requires :link_id, type: Integer, desc: 'The id of the link'
+ end
+ put 'links/:link_id' do
+ authorize! :destroy_release, release
+
+ if link.destroy
+ present link, with: Entities::Releases::Link
+ else
+ render_api_error!(result[:message], result[:http_status])
+ end
+ end
+ end
+ end
+ end
+
+ helpers do
+ def release
+ @release ||= user_project.releases.find_by_tag(params[:tag_name])
+ end
+
+ def link
+ @link ||= release.links.find(params[:link_id])
+ end
+ end
+ end
+ end
+end