Commit b044aa1d authored by Stan Hu's avatar Stan Hu Committed by Mayra Cabrera

Maintain related issues after moving issue

When moving an issue to another project, the related issues are not
retained. We now move all the old issue links to the new issue
without creating system notes

Closes https://gitlab.com/gitlab-org/gitlab-ee/issues/13632
parent c6cd689f
......@@ -9,6 +9,9 @@ class IssueLink < ApplicationRecord
validates :source, uniqueness: { scope: :target_id, message: 'is already related' }
validate :check_self_relation
scope :for_source_issue, ->(issue) { where(source_id: issue.id) }
scope :for_target_issue, ->(issue) { where(target_id: issue.id) }
private
def check_self_relation
......
......@@ -8,6 +8,7 @@ module EE
override :update_old_entity
def update_old_entity
rewrite_epic_issue
rewrite_related_issues
super
end
......@@ -20,6 +21,14 @@ module EE
epic_issue.update(issue_id: new_entity.id)
original_entity.reset
end
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
end
end
end
---
title: Maintain related issues after moving issue
merge_request: 15391
author:
type: fixed
......@@ -28,6 +28,45 @@ describe Issues::MoveService do
end
end
describe '#rewrite_related_issues' do
let(:user) { create(:user) }
let(:admin) { create(:admin) }
let(:authorized_project) { create(:project) }
let(:authorized_project2) { create(:project) }
let(:unauthorized_project) { create(:project) }
let(:authorized_issue_b) { create(:issue, project: authorized_project) }
let(:authorized_issue_c) { create(:issue, project: authorized_project2) }
let(:authorized_issue_d) { create(:issue, project: authorized_project2) }
let(:unauthorized_issue) { create(:issue, project: unauthorized_project) }
let!(:issue_link_a) { create(:issue_link, source: old_issue, target: authorized_issue_b) }
let!(:issue_link_b) { create(:issue_link, source: old_issue, target: unauthorized_issue) }
let!(:issue_link_c) { create(:issue_link, source: old_issue, target: authorized_issue_c) }
let!(:issue_link_d) { create(:issue_link, source: authorized_issue_d, target: old_issue) }
before do
stub_licensed_features(related_issues: true)
authorized_project.add_developer(user)
authorized_project2.add_developer(user)
end
context 'multiple related issues' do
it 'moves all related issues and retains permissions' do
new_issue = move_service.execute(old_issue, new_project)
expect(new_issue.related_issues(admin))
.to match_array([authorized_issue_b, authorized_issue_c, authorized_issue_d, unauthorized_issue])
expect(new_issue.related_issues(user))
.to match_array([authorized_issue_b, authorized_issue_c, authorized_issue_d])
expect(authorized_issue_d.related_issues(user))
.to match_array([new_issue])
end
end
end
describe '#rewrite_epic_issue' do
context 'issue assigned to epic' do
let!(:epic_issue) { create(:epic_issue, issue: old_issue) }
......
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