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

67 lines
1.7 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2016-06-02 11:05:42 +05:30
module Issues
2019-02-15 15:39:39 +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
2019-02-15 15:39:39 +05:30
def execute(issue, target_project)
@target_project = target_project
2016-06-02 11:05:42 +05:30
2019-02-15 15:39:39 +05:30
unless issue.can_move?(current_user, @target_project)
2019-07-31 22:56:46 +05:30
raise MoveError, s_('MoveIssue|Cannot move issue due to insufficient permissions!')
2016-06-02 11:05:42 +05:30
end
2019-02-15 15:39:39 +05:30
if @project == @target_project
2019-07-31 22:56:46 +05:30
raise MoveError, s_('MoveIssue|Cannot move issue to project it originates from!')
2016-06-02 11:05:42 +05:30
end
2019-02-15 15:39:39 +05:30
super
2016-06-02 11:05:42 +05:30
notify_participants
2019-02-15 15:39:39 +05:30
new_entity
2016-06-02 11:05:42 +05:30
end
private
2019-02-15 15:39:39 +05:30
def update_old_entity
super
2018-03-27 19:54:05 +05:30
mark_as_moved
end
2019-02-15 15:39:39 +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
}
2019-01-03 12:48:30 +05:30
2019-02-15 15:39:39 +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
2019-01-03 12:48:30 +05:30
2019-02-15 15:39:39 +05:30
def mark_as_moved
original_entity.update(moved_to: new_entity)
2019-01-03 12:48:30 +05:30
end
2019-02-15 15:39:39 +05:30
def notify_participants
notification_service.async.issue_moved(original_entity, new_entity, @current_user)
2019-01-03 12:48:30 +05:30
end
2019-02-15 15:39:39 +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
2019-02-15 15:39:39 +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