model: remove support for cloning procedures with old pj
This commit is contained in:
parent
ffe081c1f2
commit
0da0a2b446
5 changed files with 31 additions and 98 deletions
|
@ -220,7 +220,6 @@ class Procedure < ApplicationRecord
|
|||
procedure.remote_logo_url = self.logo_url
|
||||
procedure.lien_notice = nil
|
||||
|
||||
procedure.types_de_champ += PiecesJustificativesService.types_pj_as_types_de_champ(self)
|
||||
if is_different_admin || from_library
|
||||
procedure.types_de_champ.each { |tdc| tdc.options&.delete(:old_pj) }
|
||||
end
|
||||
|
|
|
@ -1,42 +1,4 @@
|
|||
class PiecesJustificativesService
|
||||
def self.types_pj_as_types_de_champ(procedure)
|
||||
max_order_place = procedure.types_de_champ.pluck(:order_place).compact.max || -1
|
||||
order_place = max_order_place + 1
|
||||
|
||||
types_de_champ = [
|
||||
TypeDeChamp.new(
|
||||
libelle: "Pièces jointes",
|
||||
type_champ: TypeDeChamp.type_champs.fetch(:header_section),
|
||||
order_place: order_place
|
||||
)
|
||||
]
|
||||
types_de_champ += procedure.types_de_piece_justificative.map do |tpj|
|
||||
order_place += 1
|
||||
description = tpj.description
|
||||
if tpj.lien_demarche.present?
|
||||
if description.present?
|
||||
description += "\n"
|
||||
end
|
||||
description += "Récupérer le formulaire vierge pour mon dossier : #{tpj.lien_demarche}"
|
||||
end
|
||||
TypeDeChamp.new(
|
||||
libelle: tpj.libelle,
|
||||
type_champ: TypeDeChamp.type_champs.fetch(:piece_justificative),
|
||||
description: description,
|
||||
order_place: order_place,
|
||||
mandatory: tpj.mandatory,
|
||||
old_pj: {
|
||||
stable_id: tpj.id
|
||||
}
|
||||
)
|
||||
end
|
||||
if types_de_champ.count > 1
|
||||
types_de_champ
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
def self.liste_pieces_justificatives(dossier)
|
||||
dossier.champs
|
||||
.select { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative) }
|
||||
|
|
|
@ -381,8 +381,6 @@ describe Procedure do
|
|||
let!(:type_de_champ_private_0) { create(:type_de_champ, :private, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_champ_private_1) { create(:type_de_champ, :private, procedure: procedure, order_place: 1) }
|
||||
let!(:type_de_champ_private_2) { create(:type_de_champ_drop_down_list, :private, procedure: procedure, order_place: 2) }
|
||||
let!(:piece_justificative_0) { create(:type_de_piece_justificative, procedure: procedure, order_place: 0) }
|
||||
let!(:piece_justificative_1) { create(:type_de_piece_justificative, procedure: procedure, order_place: 1) }
|
||||
let(:received_mail) { create(:received_mail) }
|
||||
let(:from_library) { false }
|
||||
let(:administrateur) { procedure.administrateurs.first }
|
||||
|
@ -408,7 +406,7 @@ describe Procedure do
|
|||
it 'should duplicate specific objects with different id' do
|
||||
expect(subject.id).not_to eq(procedure.id)
|
||||
|
||||
expect(subject.types_de_champ.size).to eq(procedure.types_de_champ.size + 1 + procedure.types_de_piece_justificative.size)
|
||||
expect(subject.types_de_champ.size).to eq(procedure.types_de_champ.size)
|
||||
expect(subject.types_de_champ_private.size).to eq procedure.types_de_champ_private.size
|
||||
expect(subject.types_de_champ.map(&:drop_down_list).compact.size).to eq procedure.types_de_champ.map(&:drop_down_list).compact.size
|
||||
expect(subject.types_de_champ_private.map(&:drop_down_list).compact.size).to eq procedure.types_de_champ_private.map(&:drop_down_list).compact.size
|
||||
|
@ -430,18 +428,6 @@ describe Procedure do
|
|||
expect(cloned_procedure).to have_same_attributes_as(procedure, except: ["path"])
|
||||
end
|
||||
|
||||
it 'should not clone piece justificatives but create corresponding champs' do
|
||||
expect(subject.types_de_piece_justificative.size).to eq(0)
|
||||
|
||||
champs_pj = subject.types_de_champ[procedure.types_de_champ.size + 1, procedure.types_de_piece_justificative.size]
|
||||
champs_pj.zip(procedure.types_de_piece_justificative).each do |stc, ptpj|
|
||||
expect(stc.libelle).to eq(ptpj.libelle)
|
||||
expect(stc.description).to eq(ptpj.description)
|
||||
expect(stc.mandatory).to eq(ptpj.mandatory)
|
||||
expect(stc.old_pj[:stable_id]).to eq(ptpj.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the procedure is cloned from the library' do
|
||||
let(:from_library) { true }
|
||||
|
||||
|
|
|
@ -46,26 +46,17 @@ describe DossierSerializer do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when a type PJ was cloned to a type champ PJ' do
|
||||
let(:original_procedure) do
|
||||
p = create(:procedure, :published)
|
||||
p.types_de_piece_justificative.create(
|
||||
context 'when a type de champ PJ was cloned from a legacy PJ' do
|
||||
let(:original_pj_id) { 3 }
|
||||
let(:cloned_type_de_champ) do
|
||||
tdc = create(:type_de_champ_piece_justificative,
|
||||
libelle: "Vidéo de votre demande de subvention",
|
||||
description: "Pour optimiser vos chances, soignez la chorégraphie et privilégiez le chant polyphonique",
|
||||
lien_demarche: "https://www.dance-academy.gouv.fr",
|
||||
order_place: 0
|
||||
)
|
||||
p
|
||||
description: "Pour optimiser vos chances, soignez la chorégraphie et privilégiez le chant polyphonique.\r\nRécupérer le formulaire vierge pour mon dossier : https://www.dance-academy.gouv.fr",
|
||||
order_place: 0)
|
||||
tdc.old_pj = { stable_id: original_pj_id }
|
||||
tdc
|
||||
end
|
||||
|
||||
let(:procedure) do
|
||||
p = original_procedure.clone(original_procedure.administrateurs.first, false)
|
||||
p.save
|
||||
p
|
||||
end
|
||||
|
||||
let(:type_pj) { original_procedure.types_de_piece_justificative.first }
|
||||
let(:migrated_type_champ) { procedure.types_de_champ.find_by(libelle: type_pj.libelle) }
|
||||
let(:procedure) { create(:procedure, :published, types_de_champ: [cloned_type_de_champ]) }
|
||||
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||
let(:champ_pj) { dossier.champs.last }
|
||||
|
||||
|
@ -79,18 +70,18 @@ describe DossierSerializer do
|
|||
is_expected.to include(
|
||||
types_de_piece_justificative: [
|
||||
{
|
||||
"id" => type_pj.id,
|
||||
"libelle" => type_pj.libelle,
|
||||
"description" => type_pj.description,
|
||||
"lien_demarche" => type_pj.lien_demarche,
|
||||
"order_place" => type_pj.order_place
|
||||
"id" => original_pj_id,
|
||||
"libelle" => cloned_type_de_champ.libelle,
|
||||
"description" => 'Pour optimiser vos chances, soignez la chorégraphie et privilégiez le chant polyphonique.',
|
||||
"lien_demarche" => 'https://www.dance-academy.gouv.fr',
|
||||
"order_place" => cloned_type_de_champ.order_place
|
||||
}
|
||||
],
|
||||
pieces_justificatives: [
|
||||
{
|
||||
"content_url" => champ_pj.for_api,
|
||||
"created_at" => champ_pj.created_at.in_time_zone('UTC').iso8601(3),
|
||||
"type_de_piece_justificative_id" => type_pj.id,
|
||||
"type_de_piece_justificative_id" => original_pj_id,
|
||||
"user" => a_hash_including("id" => dossier.user.id)
|
||||
}
|
||||
]
|
||||
|
@ -98,7 +89,7 @@ describe DossierSerializer do
|
|||
end
|
||||
|
||||
it "does not expose the PJ as a champ" do
|
||||
expect(subject[:champs]).not_to include(a_hash_including(type_de_champ: a_hash_including(id: migrated_type_champ.id)))
|
||||
expect(subject[:champs]).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,21 +10,16 @@ describe ProcedureSerializer do
|
|||
end
|
||||
|
||||
context 'when a type PJ was cloned to a type champ PJ' do
|
||||
let(:original_procedure) do
|
||||
p = create(:procedure, :published)
|
||||
p.types_de_piece_justificative.create(
|
||||
let(:original_pj_id) { 3 }
|
||||
let(:cloned_type_de_champ) do
|
||||
tdc = create(:type_de_champ_piece_justificative,
|
||||
libelle: "Vidéo de votre demande de subvention",
|
||||
description: "Pour optimiser vos chances, soignez la chorégraphie et privilégiez le chant polyphonique",
|
||||
lien_demarche: "https://www.dance-academy.gouv.fr",
|
||||
order_place: 0
|
||||
)
|
||||
p
|
||||
description: "Pour optimiser vos chances, soignez la chorégraphie et privilégiez le chant polyphonique.\r\nRécupérer le formulaire vierge pour mon dossier : https://www.dance-academy.gouv.fr",
|
||||
order_place: 0)
|
||||
tdc.old_pj = { stable_id: original_pj_id }
|
||||
tdc
|
||||
end
|
||||
|
||||
let(:procedure) { original_procedure.clone(original_procedure.administrateurs.first, false) }
|
||||
|
||||
let(:type_pj) { original_procedure.types_de_piece_justificative.first }
|
||||
let(:migrated_type_champ) { procedure.types_de_champ.find_by(libelle: type_pj.libelle) }
|
||||
let(:procedure) { create(:procedure, :published, types_de_champ: [cloned_type_de_champ]) }
|
||||
|
||||
subject { ProcedureSerializer.new(procedure).serializable_hash }
|
||||
|
||||
|
@ -32,18 +27,18 @@ describe ProcedureSerializer do
|
|||
is_expected.to include(
|
||||
types_de_piece_justificative: [
|
||||
{
|
||||
"id" => type_pj.id,
|
||||
"libelle" => type_pj.libelle,
|
||||
"description" => type_pj.description,
|
||||
"lien_demarche" => type_pj.lien_demarche,
|
||||
"order_place" => type_pj.order_place
|
||||
"id" => original_pj_id,
|
||||
"libelle" => cloned_type_de_champ.libelle,
|
||||
"description" => 'Pour optimiser vos chances, soignez la chorégraphie et privilégiez le chant polyphonique.',
|
||||
"lien_demarche" => 'https://www.dance-academy.gouv.fr',
|
||||
"order_place" => cloned_type_de_champ.order_place
|
||||
}
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
it "is not exposed as a type de champ" do
|
||||
expect(subject[:types_de_champ]).not_to include(a_hash_including(libelle: type_pj.libelle))
|
||||
expect(subject[:types_de_champ]).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue