Merge pull request #10091 from tchak/fix-apply_diff

fix(dossier): safely remove child champs in apply_diff
This commit is contained in:
Paul Chavard 2024-03-11 09:20:30 +00:00 committed by GitHub
commit 256d63e5f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -167,9 +167,10 @@ module DossierCloneConcern
end end
champs_to_remove += diff[:removed] champs_to_remove += diff[:removed]
champs_to_remove children_champs_to_remove, root_champs_to_remove = champs_to_remove.partition(&:child?)
.filter { !_1.child? || !champs_to_remove.include?(_1.parent) }
.each do |champ| children_champs_to_remove.each(&:destroy!)
root_champs_to_remove.each do |champ|
champ.rows.flatten.each(&:destroy!) if champ.repetition? champ.rows.flatten.each(&:destroy!) if champ.repetition?
champ.destroy! champ.destroy!
end end