Merge pull request #10852 from tchak/fix-export-with-row_ids
fix(champ): improve row_id validation and remove it during export
This commit is contained in:
commit
e35584811c
3 changed files with 10 additions and 7 deletions
|
@ -82,7 +82,6 @@ module DossierChampsConcern
|
|||
end
|
||||
|
||||
def champ_for_export(type_de_champ, row_id)
|
||||
check_valid_row_id?(type_de_champ, row_id)
|
||||
champ = champs_by_public_id[type_de_champ.public_id(row_id)]
|
||||
if champ.blank? || !champ.visible?
|
||||
nil
|
||||
|
@ -131,10 +130,10 @@ module DossierChampsConcern
|
|||
def check_valid_row_id?(type_de_champ, row_id)
|
||||
if type_de_champ.child?(revision)
|
||||
if row_id.blank?
|
||||
raise "type_de_champ #{type_de_champ.stable_id} must have a row_id because it is part of a repetition"
|
||||
raise "type_de_champ #{type_de_champ.stable_id} in revision #{revision_id} must have a row_id because it is part of a repetition"
|
||||
end
|
||||
elsif row_id.present?
|
||||
raise "type_de_champ #{type_de_champ.stable_id} can not have a row_id because it is not part of a repetition"
|
||||
elsif row_id.present? && type_de_champ.in_revision?(revision)
|
||||
raise "type_de_champ #{type_de_champ.stable_id} in revision #{revision_id} can not have a row_id because it is not part of a repetition"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -456,8 +456,12 @@ class TypeDeChamp < ApplicationRecord
|
|||
!private?
|
||||
end
|
||||
|
||||
def in_revision?(revision)
|
||||
revision.types_de_champ.any? { _1.stable_id == stable_id }
|
||||
end
|
||||
|
||||
def child?(revision)
|
||||
revision.revision_types_de_champ.find { _1.type_de_champ_id == id }&.child?
|
||||
revision.revision_types_de_champ.find { _1.stable_id == stable_id }&.child?
|
||||
end
|
||||
|
||||
def filename_for_attachement(attachment_sym)
|
||||
|
|
|
@ -55,7 +55,7 @@ RSpec.describe DossierChampsConcern do
|
|||
context "invalid row_id" do
|
||||
let(:type_de_champ_public) { dossier.find_type_de_champ_by_stable_id(99) }
|
||||
it {
|
||||
expect { subject }.to raise_error("type_de_champ #{type_de_champ_public.stable_id} can not have a row_id because it is not part of a repetition")
|
||||
expect { subject }.to raise_error("type_de_champ #{type_de_champ_public.stable_id} in revision #{dossier.revision_id} can not have a row_id because it is not part of a repetition")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
@ -81,7 +81,7 @@ RSpec.describe DossierChampsConcern do
|
|||
context "invalid row_id" do
|
||||
let(:type_de_champ_public) { dossier.find_type_de_champ_by_stable_id(99) }
|
||||
it {
|
||||
expect { subject }.to raise_error("type_de_champ #{type_de_champ_public.stable_id} can not have a row_id because it is not part of a repetition")
|
||||
expect { subject }.to raise_error("type_de_champ #{type_de_champ_public.stable_id} in revision #{dossier.revision_id} can not have a row_id because it is not part of a repetition")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue