2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
module Boards
|
|
|
|
module Issues
|
2021-04-17 20:07:23 +05:30
|
|
|
class MoveService < Boards::BaseItemMoveService
|
|
|
|
extend ::Gitlab::Utils::Override
|
2019-09-30 21:07:59 +05:30
|
|
|
|
|
|
|
def execute_multiple(issues)
|
|
|
|
return execute_multiple_empty_result if issues.empty?
|
|
|
|
|
|
|
|
handled_issues = []
|
|
|
|
last_inserted_issue_id = nil
|
|
|
|
count = issues.each.inject(0) do |moved_count, issue|
|
2021-04-17 20:07:23 +05:30
|
|
|
issue_modification_params = issuable_params(issue)
|
2019-09-30 21:07:59 +05:30
|
|
|
next moved_count if issue_modification_params.empty?
|
|
|
|
|
|
|
|
if last_inserted_issue_id
|
|
|
|
issue_modification_params[:move_between_ids] = move_below(last_inserted_issue_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
last_inserted_issue_id = issue.id
|
2021-04-17 20:07:23 +05:30
|
|
|
handled_issue = move_single_issuable(issue, issue_modification_params)
|
2019-09-30 21:07:59 +05:30
|
|
|
handled_issues << present_issue_entity(handled_issue) if handled_issue
|
|
|
|
handled_issue && handled_issue.valid? ? moved_count + 1 : moved_count
|
|
|
|
end
|
|
|
|
|
|
|
|
{
|
|
|
|
count: count,
|
|
|
|
success: count == issues.size,
|
|
|
|
issues: handled_issues
|
|
|
|
}
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
def present_issue_entity(issue)
|
|
|
|
::API::Entities::Issue.represent(issue)
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute_multiple_empty_result
|
|
|
|
@execute_multiple_empty_result ||= {
|
|
|
|
count: 0,
|
|
|
|
success: false,
|
|
|
|
issues: []
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def move_below(id)
|
|
|
|
move_between_ids({ move_after_id: nil, move_before_id: id })
|
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
def board
|
2018-03-17 18:26:18 +05:30
|
|
|
@board ||= parent.boards.find(params[:board_id])
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
def update(issue, issue_modification_params)
|
|
|
|
::Issues::UpdateService.new(issue.project, current_user, issue_modification_params).execute(issue)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
override :issuable_params
|
|
|
|
def issuable_params(issuable)
|
|
|
|
attrs = super
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
move_between_ids = move_between_ids(params)
|
2018-05-01 15:08:00 +05:30
|
|
|
if move_between_ids
|
|
|
|
attrs[:move_between_ids] = move_between_ids
|
2019-03-02 22:35:43 +05:30
|
|
|
attrs[:board_group_id] = board.group&.id
|
2018-05-01 15:08:00 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
attrs
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
def move_between_ids(move_params)
|
|
|
|
ids = [move_params[:move_after_id], move_params[:move_before_id]]
|
|
|
|
.map(&:to_i)
|
2020-10-24 23:57:45 +05:30
|
|
|
.map { |m| m > 0 ? m : nil }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
ids.any? ? ids : nil
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
Boards::Issues::MoveService.prepend_if_ee('EE::Boards::Issues::MoveService')
|