Register canonical procedure when demarche republished under existing path

This commit is contained in:
Paul Chavard 2019-12-04 16:58:36 +01:00
parent 04ad829e3f
commit 517ab25783
2 changed files with 50 additions and 9 deletions

View file

@ -16,6 +16,7 @@ class Procedure < ApplicationRecord
has_one :attestation_template, dependent: :destroy
belongs_to :parent_procedure, class_name: 'Procedure'
belongs_to :canonical_procedure, class_name: 'Procedure'
belongs_to :service
has_many :administrateurs_procedures
@ -129,9 +130,10 @@ class Procedure < ApplicationRecord
other_procedure = other_procedure_with_path(path)
if other_procedure.present? && administrateur.owns?(other_procedure)
other_procedure.unpublish!
publish!(other_procedure.canonical_procedure || other_procedure)
else
publish!
end
publish!
end
end
@ -615,8 +617,8 @@ class Procedure < ApplicationRecord
update!(closed_at: nil, unpublished_at: nil)
end
def after_publish
update!(published_at: Time.zone.now)
def after_publish(canonical_procedure = nil)
update!(published_at: Time.zone.now, canonical_procedure: canonical_procedure)
end
def after_close