From 7a322266fa10c2a439047c3520e4f9a2b05661c7 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 7 Sep 2018 17:36:31 +0100 Subject: [PATCH] Make aasm related methods private --- app/models/procedure.rb | 72 ++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index d508e64fa..8c1089591 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -84,33 +84,6 @@ class Procedure < ApplicationRecord end end - def after_publish(path) - now = Time.now - update( - test_started_at: now, - archived_at: nil, - published_at: now - ) - procedure_path = ProcedurePath.find_by(path: path) - - if procedure_path.present? - procedure_path.publish!(self) - else - ProcedurePath.create(procedure: self, administrateur: administrateur, path: path) - end - end - - def after_archive - update(archived_at: Time.now) - end - - def after_hide - now = Time.now - update(hidden_at: now) - procedure_path&.hide! - dossiers.update_all(hidden_at: now) - end - def reset! if locked? raise "Can not reset a locked procedure." @@ -132,15 +105,6 @@ class Procedure < ApplicationRecord publiee? || archivee? end - def can_publish?(path) - procedure_path = ProcedurePath.find_by(path: path) - if procedure_path.present? - administrateur.owns?(procedure_path) - else - true - end - end - # Warning: dossier after_save build_default_champs must be removed # to save a dossier created from this method def new_dossier @@ -372,6 +336,42 @@ class Procedure < ApplicationRecord private + def can_publish?(path) + procedure_path = ProcedurePath.find_by(path: path) + if procedure_path.present? + administrateur.owns?(procedure_path) + else + true + end + end + + def after_publish(path) + now = Time.now + update( + test_started_at: now, + archived_at: nil, + published_at: now + ) + procedure_path = ProcedurePath.find_by(path: path) + + if procedure_path.present? + procedure_path.publish!(self) + else + ProcedurePath.create(procedure: self, administrateur: administrateur, path: path) + end + end + + def after_archive + update(archived_at: Time.now) + end + + def after_hide + now = Time.now + update(hidden_at: now) + procedure_path&.hide! + dossiers.update_all(hidden_at: now) + end + def update_juridique_required self.juridique_required ||= (cadre_juridique.present? || deliberation.attached?) true