diff --git a/app/helpers/commentaire_helper.rb b/app/helpers/commentaire_helper.rb index a39c9e736..f22163a07 100644 --- a/app/helpers/commentaire_helper.rb +++ b/app/helpers/commentaire_helper.rb @@ -5,6 +5,10 @@ module CommentaireHelper end end + def commentaire_is_from_guest(commentaire) + commentaire.dossier.invites.map(&:email).include?(commentaire.email) + end + def commentaire_date(commentaire) is_current_year = (commentaire.created_at.year == Date.current.year) template = is_current_year ? :message_date : :message_date_with_year diff --git a/app/views/shared/dossiers/messages/_message.html.haml b/app/views/shared/dossiers/messages/_message.html.haml index 218c0870b..b49e88abb 100644 --- a/app/views/shared/dossiers/messages/_message.html.haml +++ b/app/views/shared/dossiers/messages/_message.html.haml @@ -4,7 +4,7 @@ %h2 %span.mail = render partial: 'shared/dossiers/messages/message_issuer', locals: { commentaire: commentaire, user_email: user_email } - - if ![user_email, commentaire.dossier.user.email, OLD_CONTACT_EMAIL, CONTACT_EMAIL].include?(commentaire.email) + - if commentaire_is_from_guest(commentaire) %span.guest Invité %span.date{ class: highlight_if_unseen_class(messagerie_seen_at, commentaire.created_at) } = commentaire_date(commentaire) diff --git a/spec/helpers/commentaire_helper_spec.rb b/spec/helpers/commentaire_helper_spec.rb index f96f03d99..9f0bd998b 100644 --- a/spec/helpers/commentaire_helper_spec.rb +++ b/spec/helpers/commentaire_helper_spec.rb @@ -19,6 +19,23 @@ RSpec.describe CommentaireHelper, type: :helper do end end + describe '.commentaire_is_from_guest' do + let(:dossier) { create(:dossier) } + let!(:guest) { create(:invite_user, dossier: dossier) } + + subject { commentaire_is_from_guest(commentaire) } + + context 'when the commentaire sender is not a guest' do + let(:commentaire) { create(:commentaire, dossier: dossier, email: "michel@pref.fr") } + it { is_expected.to be false } + end + + context 'when the commentaire sender is a guest on this dossier' do + let(:commentaire) { create(:commentaire, dossier: dossier, email: guest.email) } + it { is_expected.to be true } + end + end + describe '.commentaire_date' do let(:present_date) { Time.local(2018, 9, 2, 10, 5, 0) } let(:creation_date) { present_date }