Merge pull request #5427 from betagouv/dev

2020-07-28-02
This commit is contained in:
Paul Chavard 2020-07-28 18:51:08 +02:00 committed by GitHub
commit 1a997fb0ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 4 deletions

View file

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

View file

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

View file

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

View file

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