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

121 lines
3.6 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
2021-11-18 22:05:49 +05:30
verify_can_move_issue!(issue, target_project)
2016-06-02 11:05:42 +05:30
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
2021-01-03 14:25:43 +05:30
queue_copy_designs
2019-02-15 15:39:39 +05:30
new_entity
2016-06-02 11:05:42 +05:30
end
private
2021-01-03 14:25:43 +05:30
attr_reader :target_project
2021-11-18 22:05:49 +05:30
def verify_can_move_issue!(issue, target_project)
unless issue.supports_move_and_clone?
raise MoveError, s_('MoveIssue|Cannot move issues of \'%{issue_type}\' type.') % { issue_type: issue.issue_type }
end
unless issue.can_move?(current_user, @target_project)
raise MoveError, s_('MoveIssue|Cannot move issue due to insufficient permissions!')
end
if @project == @target_project
raise MoveError, s_('MoveIssue|Cannot move issue to project it originates from!')
end
end
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 = {
2021-04-17 20:07:23 +05:30
id: nil,
iid: nil,
relative_position: relative_position,
project: target_project,
author: original_entity.author,
assignee_ids: original_entity.assignee_ids,
moved_issue: true
}
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)
2021-09-30 23:02:18 +05:30
# spam checking is not necessary, as no new content is being created. Passing nil for
# spam_params will cause SpamActionService to skip checking and return a success response.
spam_params = nil
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.
2021-09-30 23:02:18 +05:30
CreateService.new(project: @target_project, current_user: @current_user, params: new_params, spam_params: spam_params).execute(skip_system_notes: true)
2016-06-02 11:05:42 +05:30
end
2019-01-03 12:48:30 +05:30
2021-01-03 14:25:43 +05:30
def queue_copy_designs
return unless original_entity.designs.present?
response = DesignManagement::CopyDesignCollection::QueueService.new(
current_user,
original_entity,
new_entity
).execute
log_error(response.message) if response.error?
end
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
2021-01-03 14:25:43 +05:30
SystemNoteService.noteable_moved(new_entity, target_project,
2019-02-15 15:39:39 +05:30
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
2021-06-08 01:23:25 +05:30
Issues::MoveService.prepend_mod_with('Issues::MoveService')