demarches-normaliennes/app/models/commentaire.rb

28 lines
661 B
Ruby
Raw Normal View History

2015-08-10 11:05:06 +02:00
class Commentaire < ActiveRecord::Base
belongs_to :dossier
2016-11-14 18:00:26 +01:00
belongs_to :champ
belongs_to :piece_justificative
after_save :notify_gestionnaires
after_save :notify_user
2016-12-26 11:08:53 +01:00
def header
"#{email}, " + I18n.l(created_at.localtime, format: '%d %b %Y %H:%M')
end
2016-12-26 11:08:53 +01:00
private
def notify_gestionnaires
if email == dossier.user.email || dossier.invites_user.pluck(:email).to_a.include?(email)
NotificationService.new('commentaire', self.dossier.id).notify
end
2016-12-26 11:08:53 +01:00
end
def notify_user
2017-05-12 13:44:40 +02:00
if email != dossier.user.email && email != 'contact@tps.apientreprise.fr'
NotificationMailer.new_answer(dossier).deliver_now!
end
end
2015-08-10 11:05:06 +02:00
end