commit
1a997fb0ad
4 changed files with 34 additions and 4 deletions
|
@ -22,7 +22,7 @@ module ProcedureHelper
|
|||
{
|
||||
isAnnotation: false,
|
||||
typeDeChampsTypes: TypeDeChamp.type_de_champ_types_for(procedure, current_user),
|
||||
typeDeChamps: procedure.types_de_champ.as_json_for_editor,
|
||||
typeDeChamps: (procedure.draft_revision ? procedure.draft_revision : procedure).types_de_champ.as_json_for_editor,
|
||||
baseUrl: admin_procedure_types_de_champ_path(procedure),
|
||||
directUploadUrl: rails_direct_uploads_url
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ module ProcedureHelper
|
|||
{
|
||||
isAnnotation: true,
|
||||
typeDeChampsTypes: TypeDeChamp.type_de_champ_types_for(procedure, current_user),
|
||||
typeDeChamps: procedure.types_de_champ_private.as_json_for_editor,
|
||||
typeDeChamps: (procedure.draft_revision ? procedure.draft_revision : procedure).types_de_champ_private.as_json_for_editor,
|
||||
baseUrl: admin_procedure_types_de_champ_path(procedure),
|
||||
directUploadUrl: rails_direct_uploads_url
|
||||
}
|
||||
|
|
|
@ -299,6 +299,7 @@ class Procedure < ApplicationRecord
|
|||
procedure.unpublished_at = nil
|
||||
procedure.published_at = nil
|
||||
procedure.lien_notice = nil
|
||||
procedure.published_revision = nil
|
||||
procedure.draft_revision.procedure = procedure
|
||||
|
||||
if is_different_admin
|
||||
|
@ -326,6 +327,8 @@ class Procedure < ApplicationRecord
|
|||
end
|
||||
|
||||
procedure.save
|
||||
procedure.draft_revision.types_de_champ.update_all(revision_id: procedure.draft_revision.id)
|
||||
procedure.draft_revision.types_de_champ_private.update_all(revision_id: procedure.draft_revision.id)
|
||||
|
||||
# FIXUP: needed during transition to revisions
|
||||
procedure.draft_revision.types_de_champ.each do |type_de_champ|
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
namespace :after_party do
|
||||
desc 'Deployment task: fix_cloned_revisions'
|
||||
task fix_cloned_revisions: :environment do
|
||||
puts "Running deploy task 'fix_cloned_revisions'"
|
||||
|
||||
Procedure.with_discarded.where(aasm_state: :brouillon).where.not(published_revision_id: nil).update_all(published_revision_id: nil)
|
||||
|
||||
types_de_champ = TypeDeChamp.joins(:revision).where('types_de_champ.procedure_id != procedure_revisions.procedure_id')
|
||||
progress = ProgressReport.new(types_de_champ.count)
|
||||
|
||||
types_de_champ.find_each do |type_de_champ|
|
||||
procedure = type_de_champ.procedure ? type_de_champ.procedure : Procedure.with_discarded.find(type_de_champ.procedure_id)
|
||||
revision_id = procedure.published_revision_id || procedure.draft_revision_id
|
||||
type_de_champ.update_column(:revision_id, revision_id)
|
||||
progress.inc
|
||||
end
|
||||
|
||||
progress.finish
|
||||
|
||||
# Update task as completed. If you remove the line below, the task will
|
||||
# run with every deploy (or every time you call after_party:run).
|
||||
AfterParty::TaskRecord
|
||||
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
|
||||
end
|
||||
end
|
|
@ -387,14 +387,16 @@ describe Procedure do
|
|||
expect(subject.draft_revision.types_de_champ_private.size).to eq(procedure.draft_revision.types_de_champ_private.size)
|
||||
|
||||
procedure.types_de_champ.zip(subject.types_de_champ).each do |ptc, stc|
|
||||
expect(stc).to have_same_attributes_as(ptc)
|
||||
expect(stc).to have_same_attributes_as(ptc, except: ["revision_id"])
|
||||
expect(stc.revision).to eq(subject.draft_revision)
|
||||
end
|
||||
procedure.types_de_champ.zip(procedure.draft_revision.types_de_champ).each do |ptc, rtc|
|
||||
expect(ptc).to eq(rtc)
|
||||
end
|
||||
|
||||
subject.types_de_champ_private.zip(procedure.types_de_champ_private).each do |stc, ptc|
|
||||
expect(stc).to have_same_attributes_as(ptc)
|
||||
expect(stc).to have_same_attributes_as(ptc, except: ["revision_id"])
|
||||
expect(stc.revision).to eq(subject.draft_revision)
|
||||
end
|
||||
procedure.types_de_champ_private.zip(procedure.draft_revision.types_de_champ_private).each do |ptc, rtc|
|
||||
expect(ptc).to eq(rtc)
|
||||
|
|
Loading…
Reference in a new issue