2016-07-28 02:33:41 -04:00
|
|
|
module Boards
|
|
|
|
module Issues
|
2016-08-02 20:49:26 -04:00
|
|
|
class MoveService < Boards::BaseService
|
2016-07-28 02:33:41 -04:00
|
|
|
def execute
|
|
|
|
return false unless issue.present?
|
2016-08-02 21:53:44 -04:00
|
|
|
return false unless valid_move?
|
2016-07-28 02:33:41 -04:00
|
|
|
|
|
|
|
update_service.execute(issue)
|
|
|
|
reopen_service.execute(issue) if moving_from.done?
|
|
|
|
close_service.execute(issue) if moving_to.done?
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-08-02 21:53:44 -04:00
|
|
|
def valid_move?
|
|
|
|
moving_from.present? && moving_to.present?
|
|
|
|
end
|
|
|
|
|
2016-07-28 02:33:41 -04:00
|
|
|
def issue
|
|
|
|
@issue ||= project.issues.visible_to_user(user).find_by!(iid: params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def moving_from
|
2016-08-02 21:53:44 -04:00
|
|
|
@moving_from ||= board.lists.find_by(id: params[:from])
|
2016-07-28 02:33:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def moving_to
|
2016-08-02 21:53:44 -04:00
|
|
|
@moving_to ||= board.lists.find_by(id: params[:to])
|
2016-07-28 02:33:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def close_service
|
|
|
|
::Issues::CloseService.new(project, user)
|
|
|
|
end
|
|
|
|
|
|
|
|
def reopen_service
|
|
|
|
::Issues::ReopenService.new(project, user)
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_service
|
|
|
|
::Issues::UpdateService.new(project, user, issue_params)
|
|
|
|
end
|
|
|
|
|
|
|
|
def issue_params
|
|
|
|
{
|
2016-08-03 11:45:44 -04:00
|
|
|
add_label_ids: add_label_ids,
|
|
|
|
remove_label_ids: remove_label_ids
|
2016-07-28 02:33:41 -04:00
|
|
|
}
|
|
|
|
end
|
2016-08-03 11:45:44 -04:00
|
|
|
|
|
|
|
def add_label_ids
|
|
|
|
[moving_to.label_id].compact
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_label_ids
|
|
|
|
label_ids =
|
|
|
|
if moving_to.label?
|
|
|
|
moving_from.label_id
|
|
|
|
else
|
|
|
|
board.lists.label.pluck(:label_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
Array(label_ids).compact
|
|
|
|
end
|
2016-07-28 02:33:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|