gitlab-org--gitlab-foss/app/services/releases/update_service.rb
Shinya Maeda 8f1e96c89b Add spec for Release API
Add spec for all release API - GET, POST, PUT, DELETE.
Also, fixes some minior bugs.
2018-12-31 14:35:57 +09:00

32 lines
826 B
Ruby

# frozen_string_literal: true
module Releases
class UpdateService < BaseService
include Releases::Concerns
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?
return error('params is empty', 400) if empty_params?
if release.update(params)
success(tag: existing_tag, release: release)
else
error(release.errors.messages || '400 Bad request', 400)
end
end
private
def allowed?
Ability.allowed?(current_user, :update_release, release)
end
# rubocop: disable CodeReuse/ActiveRecord
def empty_params?
params.except(:tag).empty?
end
# rubocop: enable CodeReuse/ActiveRecord
end
end