Register canonical procedure when demarche republished under existing path
This commit is contained in:
parent
04ad829e3f
commit
517ab25783
2 changed files with 50 additions and 9 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue