Commit 761b6947 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'sh-move-related-issues' into 'master'

Maintain related issues after moving issue

See merge request gitlab-org/gitlab!15391
parents c6cd689f b044aa1d
...@@ -9,6 +9,9 @@ class IssueLink < ApplicationRecord ...@@ -9,6 +9,9 @@ class IssueLink < ApplicationRecord
validates :source, uniqueness: { scope: :target_id, message: 'is already related' } validates :source, uniqueness: { scope: :target_id, message: 'is already related' }
validate :check_self_relation 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 private
def check_self_relation def check_self_relation
......
...@@ -8,6 +8,7 @@ module EE ...@@ -8,6 +8,7 @@ module EE
override :update_old_entity override :update_old_entity
def update_old_entity def update_old_entity
rewrite_epic_issue rewrite_epic_issue
rewrite_related_issues
super super
end end
...@@ -20,6 +21,14 @@ module EE ...@@ -20,6 +21,14 @@ module EE
epic_issue.update(issue_id: new_entity.id) epic_issue.update(issue_id: new_entity.id)
original_entity.reset original_entity.reset
end 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 end
end end
---
title: Maintain related issues after moving issue
merge_request: 15391
author:
type: fixed
...@@ -28,6 +28,45 @@ describe Issues::MoveService do ...@@ -28,6 +28,45 @@ describe Issues::MoveService do
end end
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 describe '#rewrite_epic_issue' do
context 'issue assigned to epic' do context 'issue assigned to epic' do
let!(:epic_issue) { create(:epic_issue, issue: old_issue) } 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