Commit 56c44a68 authored by Andy Soiron's avatar Andy Soiron

Merge branch '352134-move-issues-contacts' into 'master'

Copy contacts when moving an issue

See merge request gitlab-org/gitlab!80069
parents 1fc1c63e 04a8db0a
......@@ -2,6 +2,8 @@
module Issues
class MoveService < Issuable::Clone::BaseService
extend ::Gitlab::Utils::Override
MoveError = Class.new(StandardError)
def execute(issue, target_project)
......@@ -47,6 +49,7 @@ module Issues
.sent_notifications.update_all(project_id: new_entity.project_id, noteable_id: new_entity.id)
end
override :update_old_entity
def update_old_entity
super
......@@ -54,6 +57,13 @@ module Issues
mark_as_moved
end
override :update_new_entity
def update_new_entity
super
copy_contacts
end
def create_new_entity
new_params = {
id: nil,
......@@ -99,6 +109,13 @@ module Issues
target_issue_links.update_all(target_id: new_entity.id)
end
def copy_contacts
return unless Feature.enabled?(:customer_relations, original_entity.project.root_ancestor)
return unless original_entity.project.root_ancestor == new_entity.project.root_ancestor
new_entity.customer_relations_contacts = original_entity.customer_relations_contacts
end
def notify_participants
notification_service.async.issue_moved(original_entity, new_entity, @current_user)
end
......
......@@ -168,6 +168,48 @@ RSpec.describe Issues::MoveService do
end
end
context 'issue with contacts' do
let_it_be(:contacts) { create_list(:contact, 2, group: group) }
before do
old_issue.customer_relations_contacts = contacts
end
it 'preserves contacts' do
new_issue = move_service.execute(old_issue, new_project)
expect(new_issue.customer_relations_contacts).to eq(contacts)
end
context 'when moving to another root group' do
let(:another_project) { create(:project, namespace: create(:group)) }
before do
another_project.add_reporter(user)
end
it 'does not preserve contacts' do
new_issue = move_service.execute(old_issue, another_project)
expect(new_issue.customer_relations_contacts).to be_empty
end
end
context 'when customer_relations feature is disabled' do
let(:another_project) { create(:project, namespace: create(:group)) }
before do
stub_feature_flags(customer_relations: false)
end
it 'does not preserve contacts' do
new_issue = move_service.execute(old_issue, new_project)
expect(new_issue.customer_relations_contacts).to be_empty
end
end
end
context 'moving to same project' do
let(:new_project) { old_project }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment