From 9cf87d606389e7aa22f1f1b4522f77e8e1524ad6 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 17 May 2018 15:38:49 +0200 Subject: [PATCH] procedure AASM states and events --- app/models/procedure.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 5b4dc03fc..78078fdc6 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -45,6 +45,29 @@ class Procedure < ApplicationRecord validates :libelle, presence: true, allow_blank: false, allow_nil: false validates :description, presence: true, allow_blank: false, allow_nil: false + include AASM + + aasm whiny_persistence: true do + state :brouillon, initial: true + state :publiee + state :archivee + state :hidden + + event :publish, after: :after_publish, guard: :can_publish? do + transitions from: :brouillon, to: :publiee + transitions from: :archivee, to: :publiee + end + + event :archive, after: :after_archive do + transitions from: :publiee, to: :archivee + end + + event :hide, after: :after_hide do + transitions from: :brouillon, to: :hidden + transitions from: :publiee, to: :hidden + transitions from: :archivee, to: :hidden + end + end # Warning: dossier after_save build_default_champs must be removed # to save a dossier created from this method def new_dossier