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

66 lines
1.9 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)
2021-06-08 01:23:25 +05:30
::Issues::UpdateService.new(project: issue.project, current_user: current_user, params: issue_modification_params).execute(issue)
2016-09-13 17:45:13 +05:30
end
2022-10-11 01:57:18 +05:30
def moving_to_list_items_relation
Boards::Issues::ListService.new(board.resource_parent, current_user, board_id: board.id, id: moving_to_list.id).execute
end
2016-09-13 17:45:13 +05:30
end
end
end
2019-12-04 20:38:33 +05:30
2021-06-08 01:23:25 +05:30
Boards::Issues::MoveService.prepend_mod_with('Boards::Issues::MoveService')