Merge pull request #7401 from betagouv/US/fix-destroyed-claimant-email-access

fix(avis#instruction): avoid claiment(nil).email.
This commit is contained in:
mfo 2022-05-30 15:46:06 +02:00 committed by GitHub
commit 8eb4cf6d51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 3 deletions

View file

@ -0,0 +1,5 @@
module AvisHelper
def safe_claimant_email(claimant)
claimant&.email || "inconnu"
end
end

View file

@ -7,7 +7,7 @@
%h1.tab-title Donner votre avis
%h2.claimant
Demandeur :
%span.email= @avis.claimant.email
%span.email= safe_claimant_email(@avis.claimant)
%span.date Demande davis envoyée le #{l(@avis.created_at, format: '%d/%m/%y')}
%p.introduction= @avis.introduction

View file

@ -9,7 +9,7 @@
.width-100
%h2.claimant
= "#{t('claimant', scope: 'activerecord.attributes.avis')} :"
%span.email= (avis.claimant.email == current_expert.email) ? 'Vous' : avis.claimant.email
%span.email= (safe_claimant_email(avis.claimant) == current_expert.email) ? 'Vous' : safe_claimant_email(avis.claimant)
- if avis.confidentiel?
%span.confidentiel
= t('confidentiel', scope: 'activerecord.attributes.avis')

View file

@ -4,9 +4,10 @@ describe Experts::AvisController, type: :controller do
let(:now) { Time.zone.parse('01/02/2345') }
let(:instructeur) { create(:instructeur) }
let(:another_instructeur) { create(:instructeur) }
let(:claimant) { create(:expert) }
let(:expert) { create(:expert) }
let(:procedure) { create(:procedure, :published, instructeurs: [instructeur]) }
let(:procedure) { create(:procedure, :published, instructeurs: [instructeur, another_instructeur]) }
let(:another_procedure) { create(:procedure, :published, instructeurs: [instructeur]) }
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) }
@ -106,6 +107,17 @@ describe Experts::AvisController, type: :controller do
end
end
context 'with destroyed claimant' do
render_views
it 'does not raise' do
avis_with_merged_instructeur = create(:avis, dossier: dossier, claimant: another_instructeur, experts_procedure: experts_procedure)
another_instructeur.user.destroy
sign_in(expert.user)
get :instruction, params: { id: avis_with_merged_instructeur.id, procedure_id: procedure.id }
expect(response).to have_http_status(200)
end
end
describe '#messagerie' do
subject { get :messagerie, params: { id: avis_without_answer.id, procedure_id: procedure.id } }
context 'with valid avis' do