Make aasm related methods private

This commit is contained in:
Paul Chavard 2018-09-07 17:36:31 +01:00
parent de908ef4be
commit 7a322266fa

View file

@ -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