Merge pull request #6490 from betagouv/feat/6487
ETQ expert, je veux télécharger le dossier en pdf et ses pj
This commit is contained in:
commit
5108b4f9d7
8 changed files with 100 additions and 18 deletions
|
@ -1,11 +1,12 @@
|
|||
module Experts
|
||||
class AvisController < ExpertController
|
||||
include CreateAvisConcern
|
||||
include Zipline
|
||||
|
||||
before_action :authenticate_expert!, except: [:sign_up, :update_expert]
|
||||
before_action :check_if_avis_revoked, only: [:show]
|
||||
before_action :redirect_if_no_sign_up_needed, only: [:sign_up, :update_expert]
|
||||
before_action :set_avis_and_dossier, only: [:show, :instruction, :messagerie, :create_commentaire, :update]
|
||||
before_action :set_avis_and_dossier, only: [:show, :instruction, :messagerie, :create_commentaire, :update, :telecharger_pjs]
|
||||
|
||||
A_DONNER_STATUS = 'a-donner'
|
||||
DONNES_STATUS = 'donnes'
|
||||
|
@ -120,6 +121,14 @@ module Experts
|
|||
end
|
||||
end
|
||||
|
||||
def telecharger_pjs
|
||||
return head(:forbidden) if !avis.dossier.export_and_attachments_downloadable?
|
||||
|
||||
files = ActiveStorage::DownloadableFile.create_list_from_dossier(@dossier, true)
|
||||
|
||||
zipline(files, "dossier-#{@dossier.id}.zip")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def redirect_if_no_sign_up_needed
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class ActiveStorage::DownloadableFile
|
||||
def self.create_list_from_dossier(dossier)
|
||||
def self.create_list_from_dossier(dossier, for_expert = false)
|
||||
dossier_export = PiecesJustificativesService.generate_dossier_export(dossier)
|
||||
pjs = [dossier_export] + PiecesJustificativesService.liste_documents(dossier)
|
||||
pjs = [dossier_export] + PiecesJustificativesService.liste_documents(dossier, for_expert)
|
||||
pjs.map do |piece_justificative|
|
||||
[
|
||||
piece_justificative,
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
class PiecesJustificativesService
|
||||
def self.liste_documents(dossier)
|
||||
pjs_champs = pjs_for_champs(dossier)
|
||||
def self.liste_documents(dossier, for_expert)
|
||||
pjs_champs = pjs_for_champs(dossier, for_expert)
|
||||
pjs_commentaires = pjs_for_commentaires(dossier)
|
||||
pjs_dossier = pjs_for_dossier(dossier)
|
||||
pjs_dossier = pjs_for_dossier(dossier, for_expert)
|
||||
|
||||
(pjs_champs + pjs_commentaires + pjs_dossier)
|
||||
.filter(&:attached?)
|
||||
|
@ -120,8 +120,8 @@ class PiecesJustificativesService
|
|||
|
||||
private
|
||||
|
||||
def self.pjs_for_champs(dossier)
|
||||
allowed_champs = dossier.champs + dossier.champs_private
|
||||
def self.pjs_for_champs(dossier, for_expert = false)
|
||||
allowed_champs = for_expert ? dossier.champs : dossier.champs + dossier.champs_private
|
||||
|
||||
allowed_child_champs = allowed_champs
|
||||
.filter { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:repetition) }
|
||||
|
@ -138,17 +138,22 @@ class PiecesJustificativesService
|
|||
.map(&:piece_jointe)
|
||||
end
|
||||
|
||||
def self.pjs_for_dossier(dossier)
|
||||
bill_signatures = dossier.dossier_operation_logs.filter_map(&:bill_signature).uniq
|
||||
|
||||
[
|
||||
def self.pjs_for_dossier(dossier, for_expert = false)
|
||||
pjs = [
|
||||
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)
|
||||
dossier.etablissement&.entreprise_attestation_fiscale
|
||||
].flatten.compact
|
||||
|
||||
if !for_expert
|
||||
bill_signatures = dossier.dossier_operation_logs.filter_map(&:bill_signature).uniq
|
||||
pjs += [
|
||||
dossier.dossier_operation_logs.map(&:serialized),
|
||||
bill_signatures.map(&:serialized),
|
||||
bill_signatures.map(&:signature)
|
||||
].flatten.compact
|
||||
end
|
||||
pjs
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,6 +5,16 @@
|
|||
%li= link_to(dossier.procedure.libelle, procedure_expert_avis_index_path(avis.procedure))
|
||||
%li= link_to("Dossier nº #{dossier.id}", expert_avis_path(avis.procedure, avis))
|
||||
|
||||
%span.dropdown.print-menu-opener
|
||||
%button.button.dropdown-button.icon-only{ 'aria-expanded' => 'false', 'aria-controls' => 'print-pj-menu' }
|
||||
%span.icon.attached
|
||||
%ul#print-pj-menu.print-menu.dropdown-content
|
||||
%li
|
||||
- if dossier.export_and_attachments_downloadable?
|
||||
= link_to "Télécharger le dossier et toutes ses pièces jointes", telecharger_pjs_expert_avis_path(avis), target: "_blank", rel: "noopener", class: "menu-item menu-link"
|
||||
- else
|
||||
%p.menu-item Le téléchargement des pièces jointes est désactivé pour les dossiers de plus de #{number_to_human_size Dossier::TAILLE_MAX_ZIP}.
|
||||
|
||||
%ul.tabs
|
||||
= dynamic_tab_item('Demande', expert_avis_path(avis.procedure, avis))
|
||||
= dynamic_tab_item('Avis', instruction_expert_avis_path(avis.procedure, avis), notification: avis.answer.blank?)
|
||||
|
|
|
@ -295,6 +295,7 @@ Rails.application.routes.draw do
|
|||
post 'commentaire' => 'avis#create_commentaire'
|
||||
post 'avis' => 'avis#create_avis'
|
||||
get 'bilans_bdf'
|
||||
get 'telecharger_pjs' => 'avis#telecharger_pjs'
|
||||
|
||||
get 'sign_up' => 'avis#sign_up'
|
||||
post 'sign_up' => 'avis#update_expert'
|
||||
|
|
|
@ -5,9 +5,10 @@ feature 'Inviting an expert:' do
|
|||
context 'as an invited Expert' do
|
||||
let(:expert) { create(:expert) }
|
||||
let(:instructeur) { create(:instructeur) }
|
||||
let(:procedure) { create(:procedure, :published, instructeurs: [instructeur]) }
|
||||
let(:procedure) { create(:procedure, :published, :with_piece_justificative, instructeurs: [instructeur]) }
|
||||
let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) }
|
||||
let(:dossier) { create(:dossier, :en_construction, :with_dossier_link, procedure: procedure) }
|
||||
let(:champ) { dossier.champs.first }
|
||||
let(:avis) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure, confidentiel: true) }
|
||||
|
||||
context 'when I don’t already have an account' do
|
||||
|
@ -83,6 +84,42 @@ feature 'Inviting an expert:' do
|
|||
|
||||
# scenario 'I can invite other experts' do
|
||||
# end
|
||||
|
||||
context 'with dossiers having attached files', js: true do
|
||||
let(:path) { 'spec/fixtures/files/piece_justificative_0.pdf' }
|
||||
let(:commentaire) { create(:commentaire, instructeur: instructeur, dossier: dossier) }
|
||||
|
||||
before do
|
||||
champ.piece_justificative_file.attach(io: File.open(path), filename: "piece_justificative_0.pdf", content_type: "application/pdf")
|
||||
dossier.champs_private << create(:champ_piece_justificative, :with_piece_justificative_file, private: true, dossier: dossier)
|
||||
end
|
||||
|
||||
scenario 'An Expert can download an archive containing attachments without any private champ, bill signature and operations logs' do
|
||||
avis # create avis
|
||||
login_as expert.user, scope: :user
|
||||
visit expert_all_avis_path
|
||||
|
||||
click_on '1 avis à donner'
|
||||
click_on avis.dossier.user.email
|
||||
|
||||
find(:css, '.attached').click
|
||||
click_on 'Télécharger le dossier et toutes ses pièces jointes'
|
||||
# For some reason, clicking the download link does not trigger the download in the headless browser ;
|
||||
# So we need to go to the download link directly
|
||||
visit telecharger_pjs_expert_avis_path(avis.dossier.procedure, avis)
|
||||
|
||||
DownloadHelpers.wait_for_download
|
||||
files = ZipTricks::FileReader.read_zip_structure(io: File.open(DownloadHelpers.download))
|
||||
expect(DownloadHelpers.download).to include "dossier-#{dossier.id}.zip"
|
||||
expect(files.size).to be 2
|
||||
expect(files[0].filename.include?('export')).to be_truthy
|
||||
expect(files[1].filename.include?('piece_justificative_0')).to be_truthy
|
||||
expect(files[1].uncompressed_size).to be File.size(path)
|
||||
end
|
||||
|
||||
before { DownloadHelpers.clear_downloads }
|
||||
after { DownloadHelpers.clear_downloads }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when there are two experts' do
|
||||
|
|
|
@ -50,5 +50,25 @@ describe ActiveStorage::DownloadableFile do
|
|||
|
||||
it { expect(list.length).to eq 2 }
|
||||
end
|
||||
|
||||
context 'when the files are asked by an expert with piece justificative and private piece justificative' do
|
||||
let(:expert) { create(:expert) }
|
||||
let(:instructeur) { create(:instructeur) }
|
||||
let(:procedure) { create(:procedure, :published, :with_piece_justificative, instructeurs: [instructeur]) }
|
||||
let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) }
|
||||
let(:dossier) { create(:dossier, :en_construction, :with_dossier_link, procedure: procedure) }
|
||||
let(:champ) { dossier.champs.first }
|
||||
let(:avis) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure, confidentiel: true) }
|
||||
|
||||
subject(:list) { ActiveStorage::DownloadableFile.create_list_from_dossier(dossier, true) }
|
||||
|
||||
before do
|
||||
dossier.champs_private << create(:champ_piece_justificative, :with_piece_justificative_file, private: true, dossier: dossier)
|
||||
|
||||
dossier.champs << create(:champ_piece_justificative, :with_piece_justificative_file, dossier: dossier)
|
||||
end
|
||||
|
||||
it { expect(list.length).to eq 2 }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -33,7 +33,7 @@ describe PiecesJustificativesService do
|
|||
end
|
||||
|
||||
describe '.liste_documents' do
|
||||
subject { PiecesJustificativesService.liste_documents(dossier) }
|
||||
subject { PiecesJustificativesService.liste_documents(dossier, false) }
|
||||
|
||||
it "doesn't return sensitive documents like titre_identite" do
|
||||
expect(champ_identite.piece_justificative_file).to be_attached
|
||||
|
|
Loading…
Reference in a new issue