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

78 lines
1.8 KiB
Ruby
Raw Normal View History

2016-09-13 17:45:13 +05:30
module Boards
module Issues
2016-11-03 12:29:30 +05:30
class MoveService < BaseService
2016-09-13 17:45:13 +05:30
def execute(issue)
return false unless can?(current_user, :update_issue, issue)
2017-08-17 22:00:37 +05:30
return false if issue_params.empty?
2016-09-13 17:45:13 +05:30
update_service.execute(issue)
end
private
2016-11-03 12:29:30 +05:30
def board
@board ||= project.boards.find(params[:board_id])
end
2017-08-17 22:00:37 +05:30
def move_between_lists?
2016-09-13 17:45:13 +05:30
moving_from_list.present? && moving_to_list.present? &&
moving_from_list != moving_to_list
end
def moving_from_list
@moving_from_list ||= board.lists.find_by(id: params[:from_list_id])
end
def moving_to_list
@moving_to_list ||= board.lists.find_by(id: params[:to_list_id])
end
def update_service
::Issues::UpdateService.new(project, current_user, issue_params)
end
def issue_params
2017-08-17 22:00:37 +05:30
attrs = {}
if move_between_lists?
attrs.merge!(
add_label_ids: add_label_ids,
remove_label_ids: remove_label_ids,
state_event: issue_state,
)
end
attrs[:move_between_iids] = move_between_iids if move_between_iids
attrs
2016-09-13 17:45:13 +05:30
end
def issue_state
2017-08-17 22:00:37 +05:30
return 'reopen' if moving_from_list.closed?
return 'close' if moving_to_list.closed?
2016-09-13 17:45:13 +05:30
end
def add_label_ids
[moving_to_list.label_id].compact
end
def remove_label_ids
label_ids =
if moving_to_list.movable?
moving_from_list.label_id
else
2017-08-17 22:00:37 +05:30
Label.on_project_boards(project.id).pluck(:label_id)
2016-09-13 17:45:13 +05:30
end
Array(label_ids).compact
end
2017-08-17 22:00:37 +05:30
def move_between_iids
return unless params[:move_after_iid] || params[:move_before_iid]
[params[:move_after_iid], params[:move_before_iid]]
end
2016-09-13 17:45:13 +05:30
end
end
end