debian-mirror-gitlab/app/services/issues/reorder_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

33 lines
812 B
Ruby
Raw Normal View History

2019-09-30 21:07:59 +05:30
# frozen_string_literal: true
module Issues
class ReorderService < Issues::BaseService
2022-04-04 11:22:00 +05:30
include Gitlab::Utils::StrongMemoize
2019-09-30 21:07:59 +05:30
def execute(issue)
return false unless can?(current_user, :update_issue, issue)
2022-04-04 11:22:00 +05:30
return false unless move_between_ids
2019-09-30 21:07:59 +05:30
2022-04-04 11:22:00 +05:30
update(issue, { move_between_ids: move_between_ids })
2019-09-30 21:07:59 +05:30
end
private
def update(issue, attrs)
2021-06-08 01:23:25 +05:30
::Issues::UpdateService.new(project: project, current_user: current_user, params: attrs).execute(issue)
2019-09-30 21:07:59 +05:30
rescue ActiveRecord::RecordNotFound
false
end
def move_between_ids
2022-04-04 11:22:00 +05:30
strong_memoize(:move_between_ids) do
ids = [params[:move_before_id], params[:move_after_id]]
.map(&:to_i)
.map { |m| m > 0 ? m : nil }
2019-09-30 21:07:59 +05:30
2022-04-04 11:22:00 +05:30
ids.any? ? ids : nil
end
2019-09-30 21:07:59 +05:30
end
end
end