Merge pull request #5778 from tchak/export-horodatage
Add attestation, justificatifs, operation_logs and bill_signatures to export
This commit is contained in:
commit
96e5622351
6 changed files with 70 additions and 10 deletions
|
@ -23,15 +23,29 @@ class ActiveStorage::DownloadableFile
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def self.timestamped_filename(piece_justificative)
|
def self.timestamped_filename(attachment)
|
||||||
# we pad the original file name with a timestamp
|
# we pad the original file name with a timestamp
|
||||||
# and a short id in order to help identify multiple versions and avoid name collisions
|
# and a short id in order to help identify multiple versions and avoid name collisions
|
||||||
extension = File.extname(piece_justificative.filename.to_s)
|
folder = self.folder(attachment)
|
||||||
basename = File.basename(piece_justificative.filename.to_s, extension)
|
extension = File.extname(attachment.filename.to_s)
|
||||||
timestamp = piece_justificative.created_at.strftime("%d-%m-%Y-%H-%M")
|
basename = File.basename(attachment.filename.to_s, extension)
|
||||||
id = piece_justificative.id % 10000
|
timestamp = attachment.created_at.strftime("%d-%m-%Y-%H-%M")
|
||||||
|
id = attachment.id % 10000
|
||||||
|
|
||||||
"#{basename}-#{timestamp}-#{id}#{extension}"
|
"#{folder}/#{basename}-#{timestamp}-#{id}#{extension}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.folder(attachment)
|
||||||
|
case attachment.record_type
|
||||||
|
when 'Dossier'
|
||||||
|
'dossier'
|
||||||
|
when 'DossierOperationLog', 'BillSignature'
|
||||||
|
'horodatage'
|
||||||
|
when 'Commentaire'
|
||||||
|
'messagerie'
|
||||||
|
else
|
||||||
|
'pieces_justificatives'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def using_local_backend?
|
def using_local_backend?
|
||||||
|
|
|
@ -2,8 +2,9 @@ class PiecesJustificativesService
|
||||||
def self.liste_pieces_justificatives(dossier)
|
def self.liste_pieces_justificatives(dossier)
|
||||||
pjs_champs = pjs_for_champs(dossier)
|
pjs_champs = pjs_for_champs(dossier)
|
||||||
pjs_commentaires = pjs_for_commentaires(dossier)
|
pjs_commentaires = pjs_for_commentaires(dossier)
|
||||||
|
pjs_dossier = pjs_for_dossier(dossier)
|
||||||
|
|
||||||
(pjs_champs + pjs_commentaires)
|
(pjs_champs + pjs_commentaires + pjs_dossier)
|
||||||
.filter(&:attached?)
|
.filter(&:attached?)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -59,4 +60,18 @@ class PiecesJustificativesService
|
||||||
.commentaires
|
.commentaires
|
||||||
.map(&:piece_jointe)
|
.map(&:piece_jointe)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.pjs_for_dossier(dossier)
|
||||||
|
bill_signatures = dossier.dossier_operation_logs.map(&:bill_signature).compact.uniq
|
||||||
|
|
||||||
|
[
|
||||||
|
dossier.justificatif_motivation,
|
||||||
|
dossier.attestation&.pdf,
|
||||||
|
dossier.etablissement&.entreprise_attestation_sociale,
|
||||||
|
dossier.etablissement&.entreprise_attestation_fiscale,
|
||||||
|
dossier.dossier_operation_logs.map(&:serialized),
|
||||||
|
bill_signatures.map(&:serialized),
|
||||||
|
bill_signatures.map(&:signature)
|
||||||
|
].flatten.compact
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -306,7 +306,7 @@ describe Instructeurs::DossiersController, type: :controller do
|
||||||
context 'when the dossier has an attestation' do
|
context 'when the dossier has an attestation' do
|
||||||
before do
|
before do
|
||||||
attestation = Attestation.new
|
attestation = Attestation.new
|
||||||
allow(attestation).to receive(:pdf).and_return(double(read: 'pdf', size: 2.megabytes))
|
allow(attestation).to receive(:pdf).and_return(double(read: 'pdf', size: 2.megabytes, attached?: false))
|
||||||
allow(attestation).to receive(:pdf_url).and_return('http://some_document_url')
|
allow(attestation).to receive(:pdf_url).and_return('http://some_document_url')
|
||||||
|
|
||||||
allow_any_instance_of(Dossier).to receive(:build_attestation).and_return(attestation)
|
allow_any_instance_of(Dossier).to receive(:build_attestation).and_return(attestation)
|
||||||
|
|
|
@ -170,6 +170,12 @@ FactoryBot.define do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
trait :with_titre_identite do
|
||||||
|
after(:build) do |procedure, _evaluator|
|
||||||
|
build(:type_de_champ_titre_identite, procedure: procedure)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
trait :with_repetition do
|
trait :with_repetition do
|
||||||
after(:build) do |procedure, _evaluator|
|
after(:build) do |procedure, _evaluator|
|
||||||
build(:type_de_champ_repetition, :with_types_de_champ, procedure: procedure)
|
build(:type_de_champ_repetition, :with_types_de_champ, procedure: procedure)
|
||||||
|
|
|
@ -146,6 +146,7 @@ feature 'Instructing a dossier:' do
|
||||||
let(:commentaire) { create(:commentaire, instructeur: instructeur, dossier: dossier) }
|
let(:commentaire) { create(:commentaire, instructeur: instructeur, dossier: dossier) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
dossier.passer_en_instruction!(instructeur)
|
||||||
champ.piece_justificative_file.attach(io: File.open(path), filename: "piece_justificative_0.pdf", content_type: "application/pdf")
|
champ.piece_justificative_file.attach(io: File.open(path), filename: "piece_justificative_0.pdf", content_type: "application/pdf")
|
||||||
|
|
||||||
log_in(instructeur.email, password)
|
log_in(instructeur.email, password)
|
||||||
|
@ -163,9 +164,10 @@ feature 'Instructing a dossier:' do
|
||||||
files = ZipTricks::FileReader.read_zip_structure(io: File.open(DownloadHelpers.download))
|
files = ZipTricks::FileReader.read_zip_structure(io: File.open(DownloadHelpers.download))
|
||||||
|
|
||||||
expect(DownloadHelpers.download).to include "dossier-#{dossier.id}.zip"
|
expect(DownloadHelpers.download).to include "dossier-#{dossier.id}.zip"
|
||||||
expect(files.size).to be 1
|
expect(files.size).to be 2
|
||||||
expect(files[0].filename.include?('piece_justificative_0')).to be_truthy
|
expect(files[0].filename.include?('piece_justificative_0')).to be_truthy
|
||||||
expect(files[0].uncompressed_size).to be File.size(path)
|
expect(files[0].uncompressed_size).to be File.size(path)
|
||||||
|
expect(files[1].filename.include?('horodatage/operation')).to be_truthy
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'A instructeur can download an archive containing several identical attachments' do
|
scenario 'A instructeur can download an archive containing several identical attachments' do
|
||||||
|
@ -176,12 +178,13 @@ feature 'Instructing a dossier:' do
|
||||||
files = ZipTricks::FileReader.read_zip_structure(io: File.open(DownloadHelpers.download))
|
files = ZipTricks::FileReader.read_zip_structure(io: File.open(DownloadHelpers.download))
|
||||||
|
|
||||||
expect(DownloadHelpers.download).to include "dossier-#{dossier.id}.zip"
|
expect(DownloadHelpers.download).to include "dossier-#{dossier.id}.zip"
|
||||||
expect(files.size).to be 2
|
expect(files.size).to be 3
|
||||||
expect(files[0].filename.include?('piece_justificative_0')).to be_truthy
|
expect(files[0].filename.include?('piece_justificative_0')).to be_truthy
|
||||||
expect(files[1].filename.include?('piece_justificative_0')).to be_truthy
|
expect(files[1].filename.include?('piece_justificative_0')).to be_truthy
|
||||||
expect(files[0].filename).not_to eq files[1].filename
|
expect(files[0].filename).not_to eq files[1].filename
|
||||||
expect(files[0].uncompressed_size).to be File.size(path)
|
expect(files[0].uncompressed_size).to be File.size(path)
|
||||||
expect(files[1].uncompressed_size).to be File.size(path)
|
expect(files[1].uncompressed_size).to be File.size(path)
|
||||||
|
expect(files[2].filename.include?('horodatage/operation')).to be_truthy
|
||||||
end
|
end
|
||||||
|
|
||||||
after { DownloadHelpers.clear_downloads }
|
after { DownloadHelpers.clear_downloads }
|
||||||
|
|
22
spec/services/pieces_justificatives_service_spec.rb
Normal file
22
spec/services/pieces_justificatives_service_spec.rb
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
describe PiecesJustificativesService do
|
||||||
|
describe '.liste_pieces_justificatives' do
|
||||||
|
let(:procedure) { create(:procedure, :with_titre_identite) }
|
||||||
|
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||||
|
let(:champ_identite) { dossier.champs.find { |c| c.type == 'Champs::TitreIdentiteChamp' } }
|
||||||
|
|
||||||
|
before do
|
||||||
|
champ_identite
|
||||||
|
.piece_justificative_file
|
||||||
|
.attach(io: StringIO.new("toto"), filename: "toto.png", content_type: "image/png")
|
||||||
|
end
|
||||||
|
|
||||||
|
subject { PiecesJustificativesService.liste_pieces_justificatives(dossier) }
|
||||||
|
|
||||||
|
# titre identite is too sensitive
|
||||||
|
# to be exported
|
||||||
|
it 'ensures no titre identite is given' do
|
||||||
|
expect(champ_identite.piece_justificative_file).to be_attached
|
||||||
|
expect(subject).to eq([])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue