From 3fb10fb4b86bad164b5517f38de96b255332b87d Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 13 Apr 2021 17:41:49 +0100 Subject: [PATCH] Set published_at on revision when publishing a procedure --- app/models/procedure.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 27ceb25c5..3a339bf71 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -248,10 +248,10 @@ class Procedure < ApplicationRecord state :close state :depubliee - event :publish, before: :before_publish, after: :after_publish do - transitions from: :brouillon, to: :publiee - transitions from: :close, to: :publiee - transitions from: :depubliee, to: :publiee + event :publish, before: :before_publish do + transitions from: :brouillon, to: :publiee, after: :after_publish + transitions from: :close, to: :publiee, after: :after_republish + transitions from: :depubliee, to: :publiee, after: :after_republish end event :close, after: :after_close do @@ -694,6 +694,11 @@ class Procedure < ApplicationRecord def after_publish(canonical_procedure = nil) update!(published_at: Time.zone.now, canonical_procedure: canonical_procedure, draft_revision: create_new_revision, published_revision: draft_revision) + published_revision.update!(published_at: Time.zone.now) + end + + def after_republish(canonical_procedure = nil) + update!(published_at: Time.zone.now) end def after_close