diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-12-25 10:36:25 +0300 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-12-31 08:35:14 +0300 |
commit | dc8a8c7d998e2c1f78fcf60f8dc45b572f62abe8 (patch) | |
tree | 6ea5a747af393d7470ec197f09e07301251e30d4 /app | |
parent | 6a2decf5454922441606fce1560389acbbd9eff1 (diff) |
Add delete method in Release API
Introduce DELETE endpoint in Release API
Diffstat (limited to 'app')
-rw-r--r-- | app/services/delete_release_service.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/app/services/delete_release_service.rb b/app/services/delete_release_service.rb new file mode 100644 index 00000000000..4e595971949 --- /dev/null +++ b/app/services/delete_release_service.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +class DeleteReleaseService < BaseService + include Gitlab::Utils::StrongMemoize + + def execute + return error('Tag does not exist', 404) unless existing_tag + return error('Release does not exist', 404) unless release + return error('Access Denied', 403) unless allowed? + + if release.destory + success(release: release) + else + error(release.errors.messages || '400 Bad request', 400) + end + end + + private + + def allowed? + Ability.allowed?(current_user, :admin_release, release) + end + + def release + strong_memoize(:release) do + project.releases.find_by_tag(@tag_name) + end + end + + def existing_tag + strong_memoize(:existing_tag) do + repository.find_tag(@tag_name) + end + end + + def repository + strong_memoize(:repository) do + project.repository + end + end +end |