2019-05-31 21:19:08 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Issues
|
|
|
|
class ReorderService < Issues::BaseService
|
2022-02-04 10:15:34 -05:00
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
2019-05-31 21:19:08 -04:00
|
|
|
def execute(issue)
|
|
|
|
return false unless can?(current_user, :update_issue, issue)
|
2022-02-04 10:15:34 -05:00
|
|
|
return false unless move_between_ids
|
2019-05-31 21:19:08 -04:00
|
|
|
|
2022-02-04 10:15:34 -05:00
|
|
|
update(issue, { move_between_ids: move_between_ids })
|
2019-05-31 21:19:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
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 move_between_ids
|
2022-02-04 10:15:34 -05:00
|
|
|
strong_memoize(:move_between_ids) do
|
2022-02-09 13:16:19 -05:00
|
|
|
ids = [params[:move_before_id], params[:move_after_id]]
|
2022-02-04 10:15:34 -05:00
|
|
|
.map(&:to_i)
|
|
|
|
.map { |m| m > 0 ? m : nil }
|
2019-05-31 21:19:08 -04:00
|
|
|
|
2022-02-04 10:15:34 -05:00
|
|
|
ids.any? ? ids : nil
|
|
|
|
end
|
2019-05-31 21:19:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|