2019-05-31 21:19:08 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Issues
|
|
|
|
class ReorderService < Issues::BaseService
|
|
|
|
def execute(issue)
|
|
|
|
return false unless can?(current_user, :update_issue, issue)
|
|
|
|
return false if group && !can?(current_user, :read_group, group)
|
|
|
|
|
|
|
|
attrs = issue_params(group)
|
|
|
|
return false if attrs.empty?
|
|
|
|
|
|
|
|
update(issue, attrs)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def group
|
|
|
|
return unless params[:group_full_path]
|
|
|
|
|
|
|
|
@group ||= Group.find_by_full_path(params[:group_full_path])
|
|
|
|
end
|
|
|
|
|
|
|
|
def update(issue, attrs)
|
2021-05-11 23:10:21 -04:00
|
|
|
::Issues::UpdateService.new(project: project, current_user: current_user, params: attrs).execute(issue)
|
2019-05-31 21:19:08 -04:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def issue_params(group)
|
|
|
|
attrs = {}
|
|
|
|
|
|
|
|
if move_between_ids
|
|
|
|
attrs[:move_between_ids] = move_between_ids
|
|
|
|
attrs[:board_group_id] = group&.id
|
|
|
|
end
|
|
|
|
|
|
|
|
attrs
|
|
|
|
end
|
|
|
|
|
|
|
|
def move_between_ids
|
|
|
|
ids = [params[:move_after_id], params[:move_before_id]]
|
|
|
|
.map(&:to_i)
|
2020-08-12 02:09:53 -04:00
|
|
|
.map { |m| m > 0 ? m : nil }
|
2019-05-31 21:19:08 -04:00
|
|
|
|
|
|
|
ids.any? ? ids : nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|