fix dossier directory for commentaire when export with export template
This commit is contained in:
parent
06cbb65d4e
commit
ce6ebf3589
4 changed files with 37 additions and 3 deletions
|
@ -48,7 +48,7 @@ class ExportTemplate < ApplicationRecord
|
|||
def attachment_and_path(dossier, attachment, index: 0, row_index: nil, champ: nil)
|
||||
[
|
||||
attachment,
|
||||
path(dossier, attachment, index, row_index, champ)
|
||||
path(dossier, attachment, index:, row_index:, champ:)
|
||||
]
|
||||
end
|
||||
|
||||
|
@ -116,7 +116,7 @@ class ExportTemplate < ApplicationRecord
|
|||
"#{render_attributes_for(content["pdf_name"], dossier)}.pdf"
|
||||
end
|
||||
|
||||
def path(dossier, attachment, index, row_index, champ)
|
||||
def path(dossier, attachment, index: 0, row_index: nil, champ: nil)
|
||||
if attachment.name == 'pdf_export_for_instructeur'
|
||||
return export_path(dossier)
|
||||
end
|
||||
|
|
|
@ -169,7 +169,12 @@ class PiecesJustificativesService
|
|||
.filter { |a| safe_attachment(a) }
|
||||
.map do |a|
|
||||
dossier_id = commentaire_id_dossier_id[a.record_id]
|
||||
ActiveStorage::DownloadableFile.pj_and_path(dossier_id, a)
|
||||
if @export_template
|
||||
dossier = dossiers.find { _1.id == dossier_id }
|
||||
@export_template.attachment_and_path(dossier, a)
|
||||
else
|
||||
ActiveStorage::DownloadableFile.pj_and_path(dossier_id, a)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -42,5 +42,27 @@ FactoryBot.define do
|
|||
export_template.save
|
||||
end
|
||||
end
|
||||
|
||||
trait :with_custom_ddd_prefix do
|
||||
transient do
|
||||
ddd_prefix { 'dossier_' }
|
||||
end
|
||||
|
||||
to_create do |export_template, context|
|
||||
export_template.set_default_values
|
||||
export_template.content["default_dossier_directory"]["content"] = [
|
||||
{
|
||||
"type" => "paragraph",
|
||||
"content" =>
|
||||
[
|
||||
{ "text" => context.ddd_prefix, "type" => "text" },
|
||||
{ "type" => "mention", "attrs" => { "id" => "dossier_number", "label" => "numéro du dossier" } },
|
||||
{ "text" => " ", "type" => "text" }
|
||||
]
|
||||
}
|
||||
]
|
||||
export_template.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -164,6 +164,13 @@ describe PiecesJustificativesService do
|
|||
end
|
||||
|
||||
it { expect(subject).to match_array(dossier.commentaires.first.piece_jointe.attachments) }
|
||||
|
||||
context 'with export_template' do
|
||||
let(:export_template) { create(:export_template, :with_custom_ddd_prefix, ddd_prefix: "DOSSIER-", groupe_instructeur: procedure.defaut_groupe_instructeur) }
|
||||
it 'uses specific name for dossier directory' do
|
||||
expect(PiecesJustificativesService.new(user_profile:, export_template:).liste_documents(dossiers).map(&:second)[0].starts_with?("DOSSIER-#{dossier.id}/messagerie")).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a pj not safe on a commentaire' do
|
||||
|
|
Loading…
Reference in a new issue