fix(procedure): only set replaced_by if the procedure is effectively published

This commit is contained in:
Paul Chavard 2022-11-01 15:53:58 +01:00
parent c63afc7f1e
commit c9adfc3bfa

View file

@ -258,11 +258,6 @@ module Administrateurs
end end
def publish def publish
if params[:old_procedure].present?
old_procedure = current_administrateur.procedures.with_discarded.closes.find(params[:old_procedure])
old_procedure.update!(replaced_by_procedure_id: @procedure.id)
end
@procedure.assign_attributes(publish_params) @procedure.assign_attributes(publish_params)
if @procedure.draft_changed? if @procedure.draft_changed?
@ -282,6 +277,16 @@ module Administrateurs
else else
flash.alert = @procedure.errors.full_messages flash.alert = @procedure.errors.full_messages
end end
if params[:old_procedure].present? && @procedure.errors.empty?
current_administrateur
.procedures
.with_discarded
.closes
.find(params[:old_procedure])
.update!(replaced_by_procedure: @procedure)
end
redirect_to admin_procedure_path(@procedure) redirect_to admin_procedure_path(@procedure)
end end