feat(administrateur): when clone or preview procedure should use published revision if not the owned
This commit is contained in:
parent
e0071cf1bb
commit
616188bfe3
3 changed files with 35 additions and 15 deletions
|
@ -60,7 +60,12 @@ module Administrateurs
|
|||
end
|
||||
|
||||
def apercu
|
||||
@dossier = procedure_without_control.draft_revision.dossier_for_preview(current_user)
|
||||
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)
|
||||
@tab = apercu_tab
|
||||
end
|
||||
|
||||
|
@ -172,13 +177,8 @@ 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
|
||||
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
|
||||
flash.alert = new_procedure.errors.full_messages
|
||||
redirect_back(fallback_location: admin_procedures_path)
|
||||
end
|
||||
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
|
|
|
@ -520,12 +520,16 @@ class Procedure < ApplicationRecord
|
|||
is_different_admin = !admin.owns?(self)
|
||||
|
||||
populate_champ_stable_ids
|
||||
include_list = {
|
||||
attestation_template: [],
|
||||
draft_revision: {
|
||||
revision_types_de_champ: [:type_de_champ],
|
||||
dossier_submitted_message: []
|
||||
}
|
||||
|
||||
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[:groupe_instructeurs] = :instructeurs if !is_different_admin
|
||||
procedure = self.deep_clone(include: include_list) do |original, kopy|
|
||||
|
@ -544,8 +548,12 @@ class Procedure < ApplicationRecord
|
|||
procedure.max_duree_conservation_dossiers_dans_ds = NEW_MAX_DUREE_CONSERVATION
|
||||
end
|
||||
procedure.estimated_dossiers_count = 0
|
||||
procedure.published_revision = nil
|
||||
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
|
||||
|
||||
if is_different_admin
|
||||
procedure.administrateurs = [admin]
|
||||
|
|
|
@ -669,6 +669,18 @@ 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
|
||||
|
|
Loading…
Reference in a new issue