debian-mirror-gitlab/app/services/releases/update_service.rb

43 lines
1.2 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# 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?
2019-12-04 20:38:33 +05:30
return error("Milestone(s) not found: #{inexistent_milestones.join(', ')}", 400) if inexistent_milestones.any?
2020-03-13 15:44:24 +05:30
if param_for_milestone_titles_provided?
previous_milestones = release.milestones.map(&:title)
params[:milestones] = milestones
end
2019-02-15 15:39:39 +05:30
if release.update(params)
2020-03-13 15:44:24 +05:30
success(tag: existing_tag, release: release, milestones_updated: milestones_updated?(previous_milestones))
2019-02-15 15:39:39 +05:30
else
error(release.errors.messages || '400 Bad request', 400)
end
end
private
def allowed?
Ability.allowed?(current_user, :update_release, release)
end
def empty_params?
params.except(:tag).empty?
end
2020-03-13 15:44:24 +05:30
def milestones_updated?(previous_milestones)
return false unless param_for_milestone_titles_provided?
previous_milestones.to_set != release.milestones.map(&:title)
end
2019-02-15 15:39:39 +05:30
end
end