debian-mirror-gitlab/app/services/boards/issues/move_service.rb

66 lines
1.8 KiB
Ruby
Raw Normal View History

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
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-29 21:17:54 +05:30
def reposition_parent
{ board_group_id: board.group&.id }
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')