mirror of
https://github.com/opf/openproject.git
synced 2026-06-14 03:30:14 +00:00
[27746] When validating the contract, ignore the old parent
https://community.openproject.com/wp/27746
This commit is contained in:
@@ -269,10 +269,19 @@ module WorkPackages
|
||||
end
|
||||
|
||||
def invalid_relations_with_new_hierarchy
|
||||
Relation
|
||||
.from_parent_to_self_and_descendants(model)
|
||||
.or(Relation.from_self_and_descendants_to_ancestors(model))
|
||||
.direct
|
||||
query = Relation.from_parent_to_self_and_descendants(model)
|
||||
.or(Relation.from_self_and_descendants_to_ancestors(model))
|
||||
.direct
|
||||
|
||||
# Ignore the immediate relation from the old parent to the model
|
||||
# since that will still exist before saving.
|
||||
old_parent_id = model.parent_id_was
|
||||
|
||||
if old_parent_id.present?
|
||||
query.where.not(hierarchy: 1, from_id: old_parent_id, to_id: model.id)
|
||||
else
|
||||
query
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1119,4 +1119,27 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# Regression test for #27746
|
||||
# - Parent: A
|
||||
# - Child1: B
|
||||
# - Child2: C
|
||||
#
|
||||
# Trying to set parent of C to B failed because parent relation is requested before change is saved.
|
||||
describe 'Changing parent to a new one that has the same parent as the current element (Regression #27746)' do
|
||||
let(:project) { FactoryGirl.create :project }
|
||||
let!(:wp_a) { FactoryGirl.create :work_package }
|
||||
let!(:wp_b) { FactoryGirl.create :work_package, parent: wp_a }
|
||||
let!(:wp_c) { FactoryGirl.create :work_package, parent: wp_a }
|
||||
|
||||
let(:user) { FactoryGirl.create :admin }
|
||||
let(:work_package) { wp_c }
|
||||
|
||||
let(:attributes) { { parent: wp_b } }
|
||||
|
||||
it 'allows changing the parent' do
|
||||
expect(subject).to be_success
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user