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 @@
module Issuable
module Clone
class BaseService < IssuableBaseService
attr_reader :original_entity, :new_entity
attr_reader :original_entity, :new_entity, :target_project
alias_method :old_project, :project
def execute(original_entity, new_project = nil)
def execute(original_entity, target_project = nil)
@original_entity = original_entity
@target_project = target_project
# Using transaction because of a high resources footprint
# on rewriting notes (unfolding references)
......@@ -77,6 +78,12 @@ module Issuable
new_entity.project.group
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
......
......@@ -47,6 +47,7 @@ module Issues
new_params = {
id: nil,
iid: nil,
relative_position: relative_position,
project: target_project,
author: current_user,
assignee_ids: original_entity.assignee_ids
......
......@@ -50,6 +50,7 @@ module Issues
new_params = {
id: nil,
iid: nil,
relative_position: relative_position,
project: target_project,
author: original_entity.author,
assignee_ids: original_entity.assignee_ids,
......
---
title: Handle relative position on issue move or clone
merge_request: 55555
author:
type: fixed
......@@ -280,6 +280,12 @@ RSpec.describe Issues::CloneService do
expect(new_issue.designs.first.notes.size).to eq(1)
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
describe 'clone permissions' do
......
......@@ -244,6 +244,12 @@ RSpec.describe Issues::MoveService do
expect(new_issue.designs.first.notes.size).to eq(1)
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
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