Add Commentaire.is_sent_by_system? and .is_sent_by(someone)
And use it in CommentaireHelper and in the _message_icon and _message_issuer partials
This commit is contained in:
parent
2abd93d360
commit
3f439ac07a
5 changed files with 30 additions and 18 deletions
|
@ -1,12 +1,12 @@
|
|||
module CommentaireHelper
|
||||
def commentaire_is_from_me_class(commentaire, connected_user)
|
||||
if commentaire_is_from_me(commentaire, connected_user)
|
||||
if commentaire.sent_by?(connected_user)
|
||||
"from-me"
|
||||
end
|
||||
end
|
||||
|
||||
def commentaire_answer_action(commentaire, connected_user)
|
||||
if commentaire_is_from_me(commentaire, connected_user)
|
||||
if commentaire.sent_by?(connected_user)
|
||||
"Envoyer un message à l’instructeur"
|
||||
else
|
||||
"Répondre dans la messagerie"
|
||||
|
@ -22,10 +22,4 @@ module CommentaireHelper
|
|||
template = is_current_year ? :message_date : :message_date_with_year
|
||||
I18n.l(commentaire.created_at, format: template)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def commentaire_is_from_me(commentaire, connected_user)
|
||||
commentaire.email == connected_user.email
|
||||
end
|
||||
end
|
||||
|
|
|
@ -36,6 +36,15 @@ class Commentaire < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def sent_by_system?
|
||||
[CONTACT_EMAIL, OLD_CONTACT_EMAIL].include?(email) &&
|
||||
user.nil? && gestionnaire.nil?
|
||||
end
|
||||
|
||||
def sent_by?(someone)
|
||||
email == someone.email
|
||||
end
|
||||
|
||||
def file_url
|
||||
if Flipflop.remote_storage?
|
||||
RemoteDownloader.new(file.path).url
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
- case commentaire.email
|
||||
- when connected_user.email
|
||||
= image_tag('icons/account-circle.svg', class: 'person-icon')
|
||||
- when OLD_CONTACT_EMAIL
|
||||
- when CONTACT_EMAIL
|
||||
- if commentaire.sent_by_system?
|
||||
= image_tag('icons/mail.svg', class: 'person-icon')
|
||||
- elsif commentaire.sent_by?(connected_user)
|
||||
= image_tag('icons/account-circle.svg', class: 'person-icon')
|
||||
- else
|
||||
= image_tag('icons/blue-person.svg', class: 'person-icon')
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
- case commentaire.email
|
||||
- when connected_user.email
|
||||
Vous
|
||||
- when OLD_CONTACT_EMAIL
|
||||
- when CONTACT_EMAIL
|
||||
- if commentaire.sent_by_system?
|
||||
Email automatique
|
||||
- elsif commentaire.sent_by?(connected_user)
|
||||
Vous
|
||||
- else
|
||||
= commentaire.redacted_email
|
||||
|
|
|
@ -7,6 +7,18 @@ describe Commentaire do
|
|||
it { is_expected.to have_db_column(:updated_at) }
|
||||
it { is_expected.to belong_to(:dossier) }
|
||||
|
||||
describe "#is_sent_by_system?" do
|
||||
subject { commentaire.is_sent_by_system? }
|
||||
|
||||
let(:commentaire) { build :commentaire, email: email }
|
||||
|
||||
context 'with a commentaire created by the DS system' do
|
||||
let(:email) { CONTACT_EMAIL }
|
||||
|
||||
it { is_expected.to be_truthy }
|
||||
end
|
||||
end
|
||||
|
||||
describe "#redacted_email" do
|
||||
subject { commentaire.redacted_email }
|
||||
|
||||
|
|
Loading…
Reference in a new issue