Commit 40176558 authored by Alexandru Croitor's avatar Alexandru Croitor

Handle relative position on issue move or clone

When an issue is moved or cloned to different project we need
to ensure that we either reset the relative position, if it is
moved to a different hierarchy so that we do not carry over large
relative position or we keep the same if it remains within the same
hierarchy just a different project as we want to keep the position on
group boards in that case.
parent 8347576d
...@@ -3,12 +3,13 @@ ...@@ -3,12 +3,13 @@
module Issuable module Issuable
module Clone module Clone
class BaseService < IssuableBaseService class BaseService < IssuableBaseService
attr_reader :original_entity, :new_entity attr_reader :original_entity, :new_entity, :target_project
alias_method :old_project, :project alias_method :old_project, :project
def execute(original_entity, new_project = nil) def execute(original_entity, target_project = nil)
@original_entity = original_entity @original_entity = original_entity
@target_project = target_project
# Using transaction because of a high resources footprint # Using transaction because of a high resources footprint
# on rewriting notes (unfolding references) # on rewriting notes (unfolding references)
...@@ -77,6 +78,12 @@ module Issuable ...@@ -77,6 +78,12 @@ module Issuable
new_entity.project.group new_entity.project.group
end end
end end
def relative_position
return if original_entity.project.root_ancestor.id != target_project.root_ancestor.id
original_entity.relative_position
end
end end
end end
end end
......
...@@ -47,6 +47,7 @@ module Issues ...@@ -47,6 +47,7 @@ module Issues
new_params = { new_params = {
id: nil, id: nil,
iid: nil, iid: nil,
relative_position: relative_position,
project: target_project, project: target_project,
author: current_user, author: current_user,
assignee_ids: original_entity.assignee_ids assignee_ids: original_entity.assignee_ids
......
...@@ -48,13 +48,14 @@ module Issues ...@@ -48,13 +48,14 @@ module Issues
def create_new_entity def create_new_entity
new_params = { new_params = {
id: nil, id: nil,
iid: nil, iid: nil,
project: target_project, relative_position: relative_position,
author: original_entity.author, project: target_project,
assignee_ids: original_entity.assignee_ids, author: original_entity.author,
moved_issue: true assignee_ids: original_entity.assignee_ids,
} moved_issue: true
}
new_params = original_entity.serializable_hash.symbolize_keys.merge(new_params) new_params = original_entity.serializable_hash.symbolize_keys.merge(new_params)
......
---
title: Handle relative position on issue move or clone
merge_request: 55555
author:
type: fixed
...@@ -280,6 +280,12 @@ RSpec.describe Issues::CloneService do ...@@ -280,6 +280,12 @@ RSpec.describe Issues::CloneService do
expect(new_issue.designs.first.notes.size).to eq(1) expect(new_issue.designs.first.notes.size).to eq(1)
end end
end end
context 'issue relative position' do
let(:subject) { clone_service.execute(old_issue, new_project) }
it_behaves_like 'copy or reset relative position'
end
end end
describe 'clone permissions' do describe 'clone permissions' do
......
...@@ -244,6 +244,12 @@ RSpec.describe Issues::MoveService do ...@@ -244,6 +244,12 @@ RSpec.describe Issues::MoveService do
expect(new_issue.designs.first.notes.size).to eq(1) expect(new_issue.designs.first.notes.size).to eq(1)
end end
end end
context 'issue relative position' do
let(:subject) { move_service.execute(old_issue, new_project) }
it_behaves_like 'copy or reset relative position'
end
end end
describe 'move permissions' do describe 'move permissions' do
......
# frozen_string_literal: true
RSpec.shared_examples 'copy or reset relative position' do
before do
# ensure we have a relative position and it is known
old_issue.update!(relative_position: 1000)
end
context 'when moved to a project within same group hierarchy' do
it 'does not reset the relative_position' do
expect(subject.relative_position).to eq(1000)
end
end
context 'when moved to a project in a different group hierarchy' do
let_it_be(:new_project) { create(:project, group: create(:group)) }
it 'does reset the relative_position' do
expect(subject.relative_position).to be_nil
end
end
end
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