bug(instructeurs/dossiers#telecharger_pjs): zipline does not play well with not available active storage attachments

This commit is contained in:
Martin 2022-09-05 11:20:30 +02:00
parent 3aec5fe413
commit cbe77dd2f6
5 changed files with 88 additions and 2 deletions

View file

@ -132,8 +132,9 @@ module Experts
def telecharger_pjs
files = ActiveStorage::DownloadableFile.create_list_from_dossiers(Dossier.where(id: @dossier.id), true)
cleaned_files = ActiveStorage::DownloadableFile.cleanup_list_from_dossier(files)
zipline(files, "dossier-#{@dossier.id}.zip")
zipline(cleaned_files, "dossier-#{@dossier.id}.zip")
end
private

View file

@ -228,8 +228,9 @@ module Instructeurs
def telecharger_pjs
files = ActiveStorage::DownloadableFile.create_list_from_dossiers(Dossier.where(id: dossier.id))
cleaned_files = ActiveStorage::DownloadableFile.cleanup_list_from_dossier(files)
zipline(files, "dossier-#{dossier.id}.zip")
zipline(cleaned_files, "dossier-#{dossier.id}.zip")
end
def destroy

View file

@ -4,6 +4,27 @@ class ActiveStorage::DownloadableFile
PiecesJustificativesService.liste_documents(dossiers, for_expert)
end
def self.cleanup_list_from_dossier(files)
if Rails.application.config.active_storage.service != :openstack
return files
end
files.filter do |file, _filename|
if file.is_a?(PiecesJustificativesService::FakeAttachment)
true
else
service = file.blob.service
client = service.client
begin
client.head_object(service.container, file.blob.key)
true
rescue Fog::OpenStack::Storage::NotFound
false
end
end
end
end
private
def self.bill_and_path(bill)