bug(instructeurs/dossiers#telecharger_pjs): zipline does not play well with not available active storage attachments
This commit is contained in:
parent
3aec5fe413
commit
cbe77dd2f6
5 changed files with 88 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue