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

92 lines
2.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
2020-07-28 23:09:34 +05:30
# Updates old issue sent notifications allowing
# to receive service desk emails on the new moved issue.
update_service_desk_sent_notifications
2019-02-15 15:39:39 +05:30
new_entity
2016-06-02 11:05:42 +05:30
end
private
2020-07-28 23:09:34 +05:30
def update_service_desk_sent_notifications
return unless original_entity.from_service_desk?
original_entity
.sent_notifications.update_all(project_id: new_entity.project_id, noteable_id: new_entity.id)
end
2019-02-15 15:39:39 +05:30
def update_old_entity
super
2018-03-27 19:54:05 +05:30
2020-11-24 15:15:51 +05:30
rewrite_related_issues
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)
2020-11-24 15:15:51 +05:30
# Skip creation of system notes for existing attributes of the issue. The system notes of the old
# issue are copied over so we don't want to end up with duplicate notes.
CreateService.new(@target_project, @current_user, new_params).execute(skip_system_notes: true)
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
2020-11-24 15:15:51 +05:30
def rewrite_related_issues
source_issue_links = IssueLink.for_source_issue(original_entity)
source_issue_links.update_all(source_id: new_entity.id)
target_issue_links = IssueLink.for_target_issue(original_entity)
target_issue_links.update_all(target_id: new_entity.id)
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
2019-12-04 20:38:33 +05:30
Issues::MoveService.prepend_if_ee('EE::Issues::MoveService')