Commit fde6d7e4 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'fix-relative-position-on-move-and-copy-issue' into 'master'

Handle relative position on issue move or clone

See merge request gitlab-org/gitlab!55555
parents cd9876e5 40176558
...@@ -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
......
...@@ -50,6 +50,7 @@ module Issues ...@@ -50,6 +50,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: original_entity.author, author: original_entity.author,
assignee_ids: original_entity.assignee_ids, 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 ...@@ -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