2018-07-16 12:31:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-15 08:41:40 -05:00
|
|
|
module Issues
|
2018-10-29 05:05:47 -04:00
|
|
|
class MoveService < Issuable::Clone::BaseService
|
2017-03-01 06:00:37 -05:00
|
|
|
MoveError = Class.new(StandardError)
|
2016-02-17 09:59:25 -05:00
|
|
|
|
2018-10-29 05:05:47 -04:00
|
|
|
def execute(issue, target_project)
|
|
|
|
@target_project = target_project
|
2016-03-15 05:14:39 -04:00
|
|
|
|
2018-10-29 05:05:47 -04:00
|
|
|
unless issue.can_move?(current_user, @target_project)
|
2019-04-15 08:25:48 -04:00
|
|
|
raise MoveError, s_('MoveIssue|Cannot move issue due to insufficient permissions!')
|
2016-03-15 05:14:39 -04:00
|
|
|
end
|
2016-03-15 06:35:40 -04:00
|
|
|
|
2018-10-29 05:05:47 -04:00
|
|
|
if @project == @target_project
|
2019-04-15 08:25:48 -04:00
|
|
|
raise MoveError, s_('MoveIssue|Cannot move issue to project it originates from!')
|
2016-03-15 06:35:40 -04:00
|
|
|
end
|
2016-02-17 09:59:25 -05:00
|
|
|
|
2018-10-29 05:05:47 -04:00
|
|
|
super
|
2016-02-22 05:00:40 -05:00
|
|
|
|
2016-03-15 05:14:39 -04:00
|
|
|
notify_participants
|
2016-02-15 08:41:40 -05:00
|
|
|
|
2018-10-29 05:05:47 -04:00
|
|
|
new_entity
|
2016-02-17 09:59:25 -05:00
|
|
|
end
|
|
|
|
|
2016-02-15 08:41:40 -05:00
|
|
|
private
|
|
|
|
|
2018-10-29 05:05:47 -04:00
|
|
|
def update_old_entity
|
|
|
|
super
|
2018-02-15 05:23:54 -05:00
|
|
|
|
|
|
|
mark_as_moved
|
|
|
|
end
|
|
|
|
|
2018-10-29 05:05:47 -04:00
|
|
|
def create_new_entity
|
|
|
|
new_params = {
|
|
|
|
id: nil,
|
|
|
|
iid: nil,
|
|
|
|
project: @target_project,
|
|
|
|
author: original_entity.author,
|
|
|
|
assignee_ids: original_entity.assignee_ids
|
|
|
|
}
|
2016-09-28 15:17:41 -04:00
|
|
|
|
2018-10-29 05:05:47 -04:00
|
|
|
new_params = original_entity.serializable_hash.symbolize_keys.merge(new_params)
|
|
|
|
CreateService.new(@target_project, @current_user, new_params).execute
|
2016-04-26 12:20:19 -04:00
|
|
|
end
|
2017-07-07 11:08:49 -04:00
|
|
|
|
2018-10-29 05:05:47 -04:00
|
|
|
def mark_as_moved
|
|
|
|
original_entity.update(moved_to: new_entity)
|
2016-03-24 07:28:43 -04:00
|
|
|
end
|
|
|
|
|
2018-10-29 05:05:47 -04:00
|
|
|
def notify_participants
|
|
|
|
notification_service.async.issue_moved(original_entity, new_entity, @current_user)
|
2016-02-15 08:41:40 -05:00
|
|
|
end
|
|
|
|
|
2018-10-29 05:05:47 -04:00
|
|
|
def add_note_from
|
|
|
|
SystemNoteService.noteable_moved(new_entity, @target_project,
|
|
|
|
original_entity, current_user,
|
2016-03-18 09:48:55 -04:00
|
|
|
direction: :from)
|
2016-02-15 08:41:40 -05:00
|
|
|
end
|
|
|
|
|
2018-10-29 05:05:47 -04:00
|
|
|
def add_note_to
|
|
|
|
SystemNoteService.noteable_moved(original_entity, old_project,
|
|
|
|
new_entity, current_user,
|
2016-03-18 09:48:55 -04:00
|
|
|
direction: :to)
|
2016-02-15 08:41:40 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
Issues::MoveService.prepend_if_ee('EE::Issues::MoveService')
|