diff --git a/app/controllers/commentaires_controller.rb b/app/controllers/commentaires_controller.rb index a3cb762f5..cdf3cb747 100644 --- a/app/controllers/commentaires_controller.rb +++ b/app/controllers/commentaires_controller.rb @@ -51,8 +51,6 @@ class CommentairesController < ApplicationController redirect_to url_for(controller: 'backoffice/dossiers', action: :show, id: params['dossier_id']) else - NotificationService.new('commentaire', @commentaire.dossier.id).notify if saved - if current_user.email != @commentaire.dossier.user.email invite = Invite.where(dossier: @commentaire.dossier, user: current_user).first redirect_to url_for(controller: 'users/dossiers/invites', action: :show, id: invite.id) diff --git a/app/models/commentaire.rb b/app/models/commentaire.rb index 463285482..2a785da37 100644 --- a/app/models/commentaire.rb +++ b/app/models/commentaire.rb @@ -4,7 +4,15 @@ class Commentaire < ActiveRecord::Base belongs_to :piece_justificative + after_save :internal_notification + def header "#{email}, " + created_at.localtime.strftime('%d %b %Y %H:%M') end + + private + + def internal_notification + NotificationService.new('commentaire', self.dossier.id).notify + end end