generate pdf export for dossier only on demand

This commit is contained in:
Christophe Robillard 2021-04-29 16:16:12 +02:00
parent f40d96fbd2
commit 3d04221dab
3 changed files with 7 additions and 8 deletions

View file

@ -1,6 +1,7 @@
class ActiveStorage::DownloadableFile
def self.create_list_from_dossier(dossier)
pjs = PiecesJustificativesService.liste_pieces_justificatives(dossier)
dossier_export = PiecesJustificativesService.generate_dossier_export(dossier)
pjs = [dossier_export] + PiecesJustificativesService.liste_pieces_justificatives(dossier)
pjs.map do |piece_justificative|
[
piece_justificative,

View file

@ -1,11 +1,10 @@
class PiecesJustificativesService
def self.liste_pieces_justificatives(dossier)
dossier_export = generate_dossier_export(dossier)
pjs_champs = pjs_for_champs(dossier)
pjs_commentaires = pjs_for_commentaires(dossier)
pjs_dossier = pjs_for_dossier(dossier)
([dossier_export] + pjs_champs + pjs_commentaires + pjs_dossier)
(pjs_champs + pjs_commentaires + pjs_dossier)
.filter(&:attached?)
end
@ -42,8 +41,6 @@ class PiecesJustificativesService
end
end
private
def self.generate_dossier_export(dossier)
pdf = ApplicationController
.render(template: 'dossiers/show', formats: [:pdf],
@ -55,6 +52,8 @@ class PiecesJustificativesService
dossier.pdf_export_for_instructeur
end
private
def self.pjs_for_champs(dossier)
allowed_champs = dossier.champs + dossier.champs_private

View file

@ -19,9 +19,8 @@ describe PiecesJustificativesService do
expect(subject.any? { |piece| piece.name == 'piece_justificative_file' }).to be_falsy
end
it 'returns export pdf of the dossier' do
expect(champ_identite.piece_justificative_file).to be_attached
expect(subject.any? { |piece| piece.name == 'pdf_export_for_instructeur' }).to be_truthy
it "doesn't return export pdf of the dossier" do
expect(subject.any? { |piece| piece.name == 'pdf_export_for_instructeur' }).to be_falsy
end
end
end