2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
module Issues
|
2018-12-23 12:14:25 +05:30
|
|
|
class MoveService < Issuable::Clone::BaseService
|
2017-08-17 22:00:37 +05:30
|
|
|
MoveError = Class.new(StandardError)
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2018-12-23 12:14:25 +05:30
|
|
|
def execute(issue, target_project)
|
|
|
|
@target_project = target_project
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2018-12-23 12:14:25 +05:30
|
|
|
unless issue.can_move?(current_user, @target_project)
|
2016-06-02 11:05:42 +05:30
|
|
|
raise MoveError, 'Cannot move issue due to insufficient permissions!'
|
|
|
|
end
|
|
|
|
|
2018-12-23 12:14:25 +05:30
|
|
|
if @project == @target_project
|
2016-06-02 11:05:42 +05:30
|
|
|
raise MoveError, 'Cannot move issue to project it originates from!'
|
|
|
|
end
|
|
|
|
|
2018-12-23 12:14:25 +05:30
|
|
|
super
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
notify_participants
|
|
|
|
|
2018-12-23 12:14:25 +05:30
|
|
|
new_entity
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-12-23 12:14:25 +05:30
|
|
|
def update_old_entity
|
|
|
|
super
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
mark_as_moved
|
|
|
|
end
|
|
|
|
|
2018-12-23 12:14:25 +05:30
|
|
|
def create_new_entity
|
|
|
|
new_params = {
|
|
|
|
id: nil,
|
|
|
|
iid: nil,
|
|
|
|
project: @target_project,
|
|
|
|
author: original_entity.author,
|
|
|
|
assignee_ids: original_entity.assignee_ids
|
|
|
|
}
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2018-12-23 12:14:25 +05:30
|
|
|
new_params = original_entity.serializable_hash.symbolize_keys.merge(new_params)
|
|
|
|
CreateService.new(@target_project, @current_user, new_params).execute
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-12-23 12:14:25 +05:30
|
|
|
def mark_as_moved
|
|
|
|
original_entity.update(moved_to: new_entity)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
2018-12-23 12:14:25 +05:30
|
|
|
def notify_participants
|
|
|
|
notification_service.async.issue_moved(original_entity, new_entity, @current_user)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
2018-12-23 12:14:25 +05:30
|
|
|
def add_note_from
|
|
|
|
SystemNoteService.noteable_moved(new_entity, @target_project,
|
|
|
|
original_entity, current_user,
|
2016-06-02 11:05:42 +05:30
|
|
|
direction: :from)
|
|
|
|
end
|
|
|
|
|
2018-12-23 12:14:25 +05:30
|
|
|
def add_note_to
|
|
|
|
SystemNoteService.noteable_moved(original_entity, old_project,
|
|
|
|
new_entity, current_user,
|
2016-06-02 11:05:42 +05:30
|
|
|
direction: :to)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|