From eda5f75ec3107588798d87af66764386e1dd0b14 Mon Sep 17 00:00:00 2001 From: Kara Diaby Date: Thu, 17 Mar 2022 11:21:35 +0100 Subject: [PATCH 1/4] modify dossier model --- app/models/dossier.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index a93ea6a6a..095b47c07 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -528,7 +528,7 @@ class Dossier < ApplicationRecord end def messagerie_available? - !brouillon? && !user_deleted? && !archived + visible_by_administration? && !hidden_by_user? && !user_deleted? && !archived end def expirable? From 4bfcf4f9d9c4e03c2994bafa1143b78df32a25cf Mon Sep 17 00:00:00 2001 From: Kara Diaby Date: Thu, 17 Mar 2022 11:21:45 +0100 Subject: [PATCH 2/4] tests --- .../instructeurs/dossiers_controller_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spec/controllers/instructeurs/dossiers_controller_spec.rb b/spec/controllers/instructeurs/dossiers_controller_spec.rb index b5cd1e38c..e8a2a838e 100644 --- a/spec/controllers/instructeurs/dossiers_controller_spec.rb +++ b/spec/controllers/instructeurs/dossiers_controller_spec.rb @@ -457,6 +457,20 @@ describe Instructeurs::DossiersController, type: :controller do expect(flash.notice).to be_present end end + + context "when the dossier is deleted by user" do + let(:dossier) { create(:dossier, :accepte, procedure: procedure) } + + before do + dossier.update!(hidden_by_user_at: 1.hour.ago) + subject + end + + it "does not create a commentaire" do + expect { subject }.to change(Commentaire, :count).by(0) + expect(flash.alert).to be_present + end + end end describe "#create_avis" do From 8bcdf597787ba99f0d7eea9c16a75db1a3094e9d Mon Sep 17 00:00:00 2001 From: Kara Diaby Date: Thu, 17 Mar 2022 13:53:33 +0100 Subject: [PATCH 3/4] change commentaire model --- app/models/commentaire.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/commentaire.rb b/app/models/commentaire.rb index b98cc70c3..76cb151cf 100644 --- a/app/models/commentaire.rb +++ b/app/models/commentaire.rb @@ -111,7 +111,7 @@ class Commentaire < ApplicationRecord def messagerie_available? return if sent_by_system? if dossier.present? && !dossier.messagerie_available? - errors.add(:dossier, "Il n’est pas possible d’envoyer un message sur un dossier archivé ou en brouillon") + errors.add(:dossier, "Il n’est pas possible d’envoyer un message sur un dossier supprimé, archivé ou en brouillon") end end end From 31d52d24834ceac6b04df54db14108ddbcb8bc70 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 17 Mar 2022 22:33:38 +0100 Subject: [PATCH 4/4] do not open all fd at once --- app/lib/download_manager/parallel_download_queue.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/lib/download_manager/parallel_download_queue.rb b/app/lib/download_manager/parallel_download_queue.rb index f7c693200..724821606 100644 --- a/app/lib/download_manager/parallel_download_queue.rb +++ b/app/lib/download_manager/parallel_download_queue.rb @@ -26,7 +26,6 @@ module DownloadManager hydra.run end - # rubocop:disable Style/AutoResourceCleanup # can't be used with typhoeus, otherwise block is closed before the request is run by hydra def download_one(attachment:, path_in_download_dir:, http_client:) attachment_path = File.join(destination, path_in_download_dir) @@ -37,12 +36,10 @@ module DownloadManager File.write(attachment_path, attachment.file.read, mode: 'wb') else request = Typhoeus::Request.new(attachment.url) - fd = File.open(attachment_path, mode: 'wb') request.on_body do |chunk| - fd.write(chunk) + File.write(attachment_path, chunk, mode: 'a+b') end request.on_complete do |response| - fd.close unless response.success? File.delete(attachment_path) if File.exist?(attachment_path) # -> case of retries failed, must cleanup partialy downloaded file on_error.call(attachment, path_in_download_dir, response.code) @@ -51,6 +48,5 @@ module DownloadManager http_client.queue(request) end end - # rubocop:enable Style/AutoResourceCleanup end end