Merge pull request #7055 from betagouv/feat/7054

ETQ Instructeur, lorsque l'usager a supprimé le dossier de son interface, je ne peux plus lui envoyer de messages
This commit is contained in:
Kara Diaby 2022-03-17 16:46:43 +01:00 committed by GitHub
commit b72de3c64d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 2 deletions

View file

@ -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 nest pas possible denvoyer un message sur un dossier archivé ou en brouillon")
errors.add(:dossier, "Il nest pas possible denvoyer un message sur un dossier supprimé, archivé ou en brouillon")
end
end
end

View file

@ -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?

View file

@ -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