Revert "Merge pull request #9002 from tchak/feat-procedure-clone-preview-published"

This reverts commit 7a6f46a8ad, reversing
changes made to 4513c52213.
This commit is contained in:
simon lehericey 2023-05-12 11:29:11 +02:00
parent 6033792669
commit 6148f24387
3 changed files with 15 additions and 35 deletions

View file

@ -60,12 +60,7 @@ module Administrateurs
end
def apercu
revision = if current_administrateur.owns?(procedure_without_control)
procedure_without_control.draft_revision
else
procedure_without_control.active_revision
end
@dossier = revision.dossier_for_preview(current_user)
@dossier = procedure_without_control.draft_revision.dossier_for_preview(current_user)
@tab = apercu_tab
end
@ -177,8 +172,13 @@ module Administrateurs
flash.notice = 'Démarche clonée, pensez a vérifier la Présentation et choisir le service a laquelle cette procédure est associé.'
redirect_to admin_procedure_path(id: new_procedure.id)
else
flash.alert = new_procedure.errors.full_messages
redirect_back(fallback_location: admin_procedures_path)
if cloned_from_library?
flash.alert = new_procedure.errors.full_messages
redirect_to new_from_existing_admin_procedures_path
else
flash.alert = new_procedure.errors.full_messages
redirect_to admin_procedures_path
end
end
rescue ActiveRecord::RecordNotFound

View file

@ -521,16 +521,12 @@ class Procedure < ApplicationRecord
is_different_admin = !admin.owns?(self)
populate_champ_stable_ids
revision_to_clone = if is_different_admin && published_revision_id.present?
:published_revision
else
:draft_revision
end
include_list = { attestation_template: [] }
include_list[revision_to_clone] = {
revision_types_de_champ: [:type_de_champ],
dossier_submitted_message: []
include_list = {
attestation_template: [],
draft_revision: {
revision_types_de_champ: [:type_de_champ],
dossier_submitted_message: []
}
}
include_list[:groupe_instructeurs] = :instructeurs if !is_different_admin
procedure = self.deep_clone(include: include_list) do |original, kopy|
@ -549,12 +545,8 @@ class Procedure < ApplicationRecord
procedure.max_duree_conservation_dossiers_dans_ds = NEW_MAX_DUREE_CONSERVATION
end
procedure.estimated_dossiers_count = 0
if procedure.published_revision.present?
procedure.draft_revision = procedure.published_revision
end
procedure.draft_revision.procedure = procedure
procedure.draft_revision.published_at = nil
procedure.published_revision = nil
procedure.draft_revision.procedure = procedure
if is_different_admin
procedure.administrateurs = [admin]

View file

@ -675,18 +675,6 @@ describe Procedure do
expect(subject.groupe_instructeurs.first.label).to eq(GroupeInstructeur::DEFAUT_LABEL)
expect(subject.groupe_instructeurs.first.instructeurs.size).to eq(0)
end
context 'when published' do
before { procedure.publish! }
it 'should clone published revision as draft' do
expect(procedure.revisions.size).to eq(2)
expect(procedure.published_revision).not_to be_nil
expect(subject.published_revision).to be_nil
expect(subject.draft_revision.published_at).to be_nil
expect(subject.draft_revision.types_de_champ.first.stable_id).to eq(procedure.published_revision.types_de_champ.first.stable_id)
end
end
end
it 'should duplicate existing mail_templates' do