Commit 03034a09 authored by Alan (Maciej) Paruszewski's avatar Alan (Maciej) Paruszewski Committed by James Lopez

Update Vulnerability::IssueLinks when moving Issues to new Project

parent 19368f19
......@@ -19,5 +19,6 @@ module Vulnerabilities
if: :created?
scope :by_link_type, -> (link_type) { link_type ? where(link_type: link_type.downcase) : all }
scope :for_issue, -> (issue) { where(issue_id: issue) }
end
end
......@@ -9,6 +9,7 @@ module EE
def update_old_entity
rewrite_epic_issue
rewrite_related_issues
rewrite_related_vulnerability_issues
super
end
......@@ -29,6 +30,11 @@ module EE
target_issue_links = IssueLink.for_target_issue(original_entity)
target_issue_links.update_all(target_id: new_entity.id)
end
def rewrite_related_vulnerability_issues
issue_links = Vulnerabilities::IssueLink.for_issue(original_entity)
issue_links.update_all(issue_id: new_entity.id)
end
end
end
end
---
title: Update Vulnerability::IssueLinks when moving Issues to new Project
merge_request: 38765
author:
type: fixed
......@@ -103,4 +103,14 @@ RSpec.describe Vulnerabilities::IssueLink do
it { is_expected.to match_array([related_issue_link]) }
end
end
describe '.for_issue' do
let_it_be(:issue) { create(:issue) }
let_it_be(:created_issue_link) { create(:vulnerabilities_issue_link, :created, issue: issue) }
let_it_be(:related_issue_link) { create(:vulnerabilities_issue_link, :related, issue: issue) }
subject { described_class.for_issue(issue).to_a }
it { is_expected.to match_array([created_issue_link, related_issue_link]) }
end
end
......@@ -86,6 +86,18 @@ RSpec.describe Issues::MoveService do
end
end
describe '#rewrite_related_vulnerability_issues' do
let(:user) { create(:user) }
let!(:vulnerabilities_issue_link) { create(:vulnerabilities_issue_link, issue: old_issue) }
it 'updates all vulnerability issue links with new issue' do
new_issue = move_service.execute(old_issue, new_project)
expect(vulnerabilities_issue_link.reload.issue).to eq(new_issue)
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