Display the full User email in Commentaires

* Only redact gestionnaires’ emails
* Also, rename Commentaire.sender to Commentaire.redacted_email
This commit is contained in:
Nicolas Bouilleaud 2019-07-01 18:14:02 +02:00 committed by Pierre de La Morinerie
parent 3bf19de124
commit 2abd93d360
3 changed files with 25 additions and 5 deletions

View file

@ -25,12 +25,14 @@ class Commentaire < ApplicationRecord
end
def header
"#{sender}, #{I18n.l(created_at, format: '%d %b %Y %H:%M')}"
"#{redacted_email}, #{I18n.l(created_at, format: '%d %b %Y %H:%M')}"
end
def sender
if email.present?
email.split('@').first
def redacted_email
if gestionnaire.present?
gestionnaire.email.split('@').first
else
email
end
end

View file

@ -5,4 +5,4 @@
- when CONTACT_EMAIL
Email automatique
- else
= commentaire.sender
= commentaire.redacted_email

View file

@ -7,6 +7,24 @@ describe Commentaire do
it { is_expected.to have_db_column(:updated_at) }
it { is_expected.to belong_to(:dossier) }
describe "#redacted_email" do
subject { commentaire.redacted_email }
context 'with a commentaire created by a gestionnaire' do
let(:commentaire) { build :commentaire, gestionnaire: gestionnaire }
let(:gestionnaire) { build :gestionnaire, email: 'some_user@exemple.fr' }
it { is_expected.to eq 'some_user' }
end
context 'with a commentaire created by a user' do
let(:commentaire) { build :commentaire, user: user }
let(:user) { build :user, email: 'some_user@exemple.fr' }
it { is_expected.to eq 'some_user@exemple.fr' }
end
end
describe "#notify" do
let(:procedure) { create(:procedure) }
let(:gestionnaire) { create(:gestionnaire) }