Validate messagerie_available? when creating a new Commentaire
Commentaires bu Users and Gestionnaire need the messagerie to be available; Automatic system Commentaires can be created anytime. This reintroduces Commentaire validation that was introduced in #3979 and disabled in #4018
This commit is contained in:
parent
3f439ac07a
commit
930fd345de
2 changed files with 35 additions and 3 deletions
|
@ -7,6 +7,7 @@ class Commentaire < ApplicationRecord
|
|||
mount_uploader :file, CommentaireFileUploader
|
||||
validates :file, file_size: { maximum: 20.megabytes, message: "La taille du fichier doit être inférieure à 20 Mo" }
|
||||
validate :is_virus_free?
|
||||
validate :messagerie_available?, on: :create
|
||||
validates :body, presence: { message: "Votre message ne peut être vide" }
|
||||
|
||||
default_scope { order(created_at: :asc) }
|
||||
|
@ -78,4 +79,11 @@ class Commentaire < ApplicationRecord
|
|||
errors.add(:file, "Virus détecté dans le fichier joint, merci de changer de fichier")
|
||||
end
|
||||
end
|
||||
|
||||
def messagerie_available?
|
||||
return if sent_by_system?
|
||||
if dossier.present? && !dossier.messagerie_available?
|
||||
errors.add(:dossier, "Il n’est pas possible d’envoyer un message sur un dossier archivé ou en brouillon")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue