always allow dossier pjs download (-9 queries)
This commit is contained in:
parent
c21eac0513
commit
57f9e5bac3
7 changed files with 2 additions and 49 deletions
|
@ -139,8 +139,6 @@ module Experts
|
||||||
end
|
end
|
||||||
|
|
||||||
def telecharger_pjs
|
def telecharger_pjs
|
||||||
return head(:forbidden) if !avis.dossier.export_and_attachments_downloadable?
|
|
||||||
|
|
||||||
files = ActiveStorage::DownloadableFile.create_list_from_dossier(@dossier, true)
|
files = ActiveStorage::DownloadableFile.create_list_from_dossier(@dossier, true)
|
||||||
|
|
||||||
zipline(files, "dossier-#{@dossier.id}.zip")
|
zipline(files, "dossier-#{@dossier.id}.zip")
|
||||||
|
|
|
@ -218,8 +218,6 @@ module Instructeurs
|
||||||
end
|
end
|
||||||
|
|
||||||
def telecharger_pjs
|
def telecharger_pjs
|
||||||
return head(:forbidden) if !dossier.export_and_attachments_downloadable?
|
|
||||||
|
|
||||||
files = ActiveStorage::DownloadableFile.create_list_from_dossier(dossier)
|
files = ActiveStorage::DownloadableFile.create_list_from_dossier(dossier)
|
||||||
|
|
||||||
zipline(files, "dossier-#{dossier.id}.zip")
|
zipline(files, "dossier-#{dossier.id}.zip")
|
||||||
|
|
|
@ -56,8 +56,6 @@ class Dossier < ApplicationRecord
|
||||||
INSTRUCTION_COMMENCEE = TERMINE + [states.fetch(:en_instruction)]
|
INSTRUCTION_COMMENCEE = TERMINE + [states.fetch(:en_instruction)]
|
||||||
SOUMIS = EN_CONSTRUCTION_OU_INSTRUCTION + TERMINE
|
SOUMIS = EN_CONSTRUCTION_OU_INSTRUCTION + TERMINE
|
||||||
|
|
||||||
TAILLE_MAX_ZIP = 100.megabytes
|
|
||||||
|
|
||||||
REMAINING_DAYS_BEFORE_CLOSING = 2
|
REMAINING_DAYS_BEFORE_CLOSING = 2
|
||||||
INTERVAL_BEFORE_CLOSING = "#{REMAINING_DAYS_BEFORE_CLOSING} days"
|
INTERVAL_BEFORE_CLOSING = "#{REMAINING_DAYS_BEFORE_CLOSING} days"
|
||||||
REMAINING_WEEKS_BEFORE_EXPIRATION = 2
|
REMAINING_WEEKS_BEFORE_EXPIRATION = 2
|
||||||
|
@ -1084,10 +1082,6 @@ class Dossier < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def export_and_attachments_downloadable?
|
|
||||||
PiecesJustificativesService.pieces_justificatives_total_size(self) < Dossier::TAILLE_MAX_ZIP
|
|
||||||
end
|
|
||||||
|
|
||||||
def linked_dossiers_for(instructeur_or_expert)
|
def linked_dossiers_for(instructeur_or_expert)
|
||||||
dossier_ids = champs.filter(&:dossier_link?).filter_map(&:value)
|
dossier_ids = champs.filter(&:dossier_link?).filter_map(&:value)
|
||||||
instructeur_or_expert.dossiers.where(id: dossier_ids)
|
instructeur_or_expert.dossiers.where(id: dossier_ids)
|
||||||
|
|
|
@ -14,11 +14,6 @@ class PiecesJustificativesService
|
||||||
pjs_champs + pjs_commentaires
|
pjs_champs + pjs_commentaires
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.pieces_justificatives_total_size(dossier)
|
|
||||||
liste_pieces_justificatives(dossier)
|
|
||||||
.sum(&:byte_size)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.serialize_types_de_champ_as_type_pj(revision)
|
def self.serialize_types_de_champ_as_type_pj(revision)
|
||||||
tdcs = revision.types_de_champ.filter { |type_champ| type_champ.old_pj.present? }
|
tdcs = revision.types_de_champ.filter { |type_champ| type_champ.old_pj.present? }
|
||||||
tdcs.map.with_index do |type_champ, order_place|
|
tdcs.map.with_index do |type_champ, order_place|
|
||||||
|
|
|
@ -9,11 +9,7 @@
|
||||||
%button.button.dropdown-button.icon-only{ 'aria-expanded' => 'false', 'aria-controls' => 'print-pj-menu' }
|
%button.button.dropdown-button.icon-only{ 'aria-expanded' => 'false', 'aria-controls' => 'print-pj-menu' }
|
||||||
%span.icon.attached
|
%span.icon.attached
|
||||||
%ul#print-pj-menu.print-menu.dropdown-content
|
%ul#print-pj-menu.print-menu.dropdown-content
|
||||||
%li
|
%li= 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"
|
||||||
- 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}.
|
|
||||||
|
|
||||||
%nav.tabs
|
%nav.tabs
|
||||||
%ul
|
%ul
|
||||||
|
|
|
@ -16,11 +16,7 @@
|
||||||
%button.button.dropdown-button.icon-only{ 'aria-expanded' => 'false', 'aria-controls' => 'print-pj-menu' }
|
%button.button.dropdown-button.icon-only{ 'aria-expanded' => 'false', 'aria-controls' => 'print-pj-menu' }
|
||||||
%span.icon.attached
|
%span.icon.attached
|
||||||
%ul#print-pj-menu.print-menu.dropdown-content
|
%ul#print-pj-menu.print-menu.dropdown-content
|
||||||
%li
|
%li= link_to "Télécharger le dossier et toutes ses pièces jointes", telecharger_pjs_instructeur_dossier_path(dossier.procedure, dossier), target: "_blank", rel: "noopener", class: "menu-item menu-link"
|
||||||
- if dossier.export_and_attachments_downloadable?
|
|
||||||
= link_to "Télécharger le dossier et toutes ses pièces jointes", telecharger_pjs_instructeur_dossier_path(dossier.procedure, dossier), 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}.
|
|
||||||
|
|
||||||
= render partial: "instructeurs/procedures/dossier_actions",
|
= render partial: "instructeurs/procedures/dossier_actions",
|
||||||
locals: { procedure_id: dossier.procedure.id,
|
locals: { procedure_id: dossier.procedure.id,
|
||||||
|
|
|
@ -1190,30 +1190,6 @@ describe Dossier do
|
||||||
after { Timecop.return }
|
after { Timecop.return }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#export_and_attachments_downloadable?' do
|
|
||||||
let(:dossier) { create(:dossier, user: user) }
|
|
||||||
|
|
||||||
context "no attachments" do
|
|
||||||
it {
|
|
||||||
expect(dossier.export_and_attachments_downloadable?).to be true
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
context "with a small attachment" do
|
|
||||||
it {
|
|
||||||
expect(PiecesJustificativesService).to receive(:pieces_justificatives_total_size).and_return(4.megabytes)
|
|
||||||
expect(dossier.export_and_attachments_downloadable?).to be true
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
context "with a too large attachment" do
|
|
||||||
it {
|
|
||||||
expect(PiecesJustificativesService).to receive(:pieces_justificatives_total_size).and_return(100.megabytes)
|
|
||||||
expect(dossier.export_and_attachments_downloadable?).to be false
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#notify_draft_not_submitted' do
|
describe '#notify_draft_not_submitted' do
|
||||||
let!(:user1) { create(:user) }
|
let!(:user1) { create(:user) }
|
||||||
let!(:user2) { create(:user) }
|
let!(:user2) { create(:user) }
|
||||||
|
|
Loading…
Add table
Reference in a new issue