demarches-normaliennes/app/services/commentaire_service.rb
Nicolas Bouilleaud bd47bf2691 Disable Messagerie in archived Dossiers and procedures
* Use the existing Dossier#messagerie_available? method
* Raise when attempting to build a Commentaire if not messagerie_available?
* Disable the Messagerie form if not messagerie_available?
* Add tests :)
* Tweak the Horaires formatting while we’re here.
2019-07-01 09:39:39 +02:00

22 lines
592 B
Ruby

class CommentaireService
class << self
def build(sender, dossier, params)
case sender
when User
params[:user] = sender
when Gestionnaire
params[:gestionnaire] = sender
end
build_with_email(sender.email, dossier, params)
end
def build_with_email(email, dossier, params)
if !dossier.messagerie_available?
raise ArgumentError, "Commentaires cannot be added to brouillons or archived Dossiers"
end
attributes = params.merge(email: email, dossier: dossier)
Commentaire.new(attributes)
end
end
end