diff --git a/app/controllers/new_administrateur/administrateur_controller.rb b/app/controllers/new_administrateur/administrateur_controller.rb
index 7c5f4cdda..f4c4a1b0f 100644
--- a/app/controllers/new_administrateur/administrateur_controller.rb
+++ b/app/controllers/new_administrateur/administrateur_controller.rb
@@ -27,7 +27,7 @@ module NewAdministrateur
end
def reset_procedure
- if @procedure.brouillon?
+ if @procedure.brouillon? || @procedure.draft_changed?
@procedure.reset!
end
end
diff --git a/app/controllers/new_administrateur/procedures_controller.rb b/app/controllers/new_administrateur/procedures_controller.rb
index d5a99c579..1e5a07877 100644
--- a/app/controllers/new_administrateur/procedures_controller.rb
+++ b/app/controllers/new_administrateur/procedures_controller.rb
@@ -55,11 +55,8 @@ module NewAdministrateur
def show
@procedure = current_administrateur.procedures.find(params[:id])
@current_administrateur = current_administrateur
- if @procedure.brouillon?
- @procedure_lien = commencer_test_url(path: @procedure.path)
- else
- @procedure_lien = commencer_url(path: @procedure.path)
- end
+ @procedure_lien = commencer_url(path: @procedure.path)
+ @procedure_lien_test = commencer_test_url(path: @procedure.path)
end
def edit
@@ -142,11 +139,8 @@ module NewAdministrateur
end
def publication
- if @procedure.brouillon?
- @procedure_lien = commencer_test_url(path: @procedure.path)
- else
- @procedure_lien = commencer_url(path: @procedure.path)
- end
+ @procedure_lien = commencer_url(path: @procedure.path)
+ @procedure_lien_test = commencer_test_url(path: @procedure.path)
@procedure.path = @procedure.suggested_path(current_administrateur)
@current_administrateur = current_administrateur
end
diff --git a/app/controllers/users/commencer_controller.rb b/app/controllers/users/commencer_controller.rb
index cd22a0664..5d29d07c4 100644
--- a/app/controllers/users/commencer_controller.rb
+++ b/app/controllers/users/commencer_controller.rb
@@ -5,13 +5,15 @@ module Users
def commencer
@procedure = retrieve_procedure
return procedure_not_found if @procedure.blank? || @procedure.brouillon?
+ @revision = @procedure.published_revision
render 'commencer/show'
end
def commencer_test
@procedure = retrieve_procedure
- return procedure_not_found if @procedure.blank? || @procedure.publiee?
+ return procedure_not_found if @procedure.blank? || (@procedure.publiee? && !@procedure.draft_changed?)
+ @revision = @procedure.draft_revision
render 'commencer/show'
end
@@ -20,14 +22,14 @@ module Users
@procedure = retrieve_procedure
return procedure_not_found if @procedure.blank? || @procedure.brouillon?
- generate_empty_pdf(@procedure)
+ generate_empty_pdf(@procedure.published_revision)
end
def dossier_vide_pdf_test
@procedure = retrieve_procedure
- return procedure_not_found if @procedure.blank? || @procedure.publiee?
+ return procedure_not_found if @procedure.blank? || (@procedure.publiee? && !@procedure.draft_changed?)
- generate_empty_pdf(@procedure)
+ generate_empty_pdf(@procedure.draft_revision)
end
def sign_in
@@ -80,10 +82,10 @@ module Users
store_location_for(:user, helpers.procedure_lien(procedure))
end
- def generate_empty_pdf(procedure)
- @dossier = procedure.active_revision.new_dossier
+ def generate_empty_pdf(revision)
+ @dossier = revision.new_dossier
s = render_to_string(template: 'dossiers/dossier_vide', formats: [:pdf])
- send_data(s, :filename => "#{procedure.libelle}.pdf")
+ send_data(s, :filename => "#{revision.procedure.libelle}.pdf")
end
end
end
diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb
index daf8d0387..bafdd8777 100644
--- a/app/controllers/users/dossiers_controller.rb
+++ b/app/controllers/users/dossiers_controller.rb
@@ -242,18 +242,18 @@ module Users
erase_user_location!
begin
- if params[:brouillon]
- procedure = Procedure.brouillon.find(params[:procedure_id])
+ procedure = if params[:brouillon]
+ Procedure.publiees.or(Procedure.brouillons).find(params[:procedure_id])
else
- procedure = Procedure.publiees.find(params[:procedure_id])
+ Procedure.publiees.find(params[:procedure_id])
end
rescue ActiveRecord::RecordNotFound
flash.alert = t('errors.messages.procedure_not_found')
- return redirect_to url_for dossiers_path
+ return redirect_to dossiers_path
end
dossier = Dossier.new(
- revision: procedure.active_revision,
+ revision: params[:brouillon] ? procedure.draft_revision : procedure.active_revision,
groupe_instructeur: procedure.defaut_groupe_instructeur_for_new_dossier,
user: current_user,
state: Dossier.states.fetch(:brouillon)
@@ -303,7 +303,7 @@ module Users
end
def show_demarche_en_test_banner
- if @dossier.present? && @dossier.procedure.brouillon?
+ if @dossier.present? && @dossier.revision.draft?
flash.now.alert = "Ce dossier est déposé sur une démarche en test. Toute modification de la démarche par l'administrateur (ajout d’un champ, publication de la démarche...) entraînera sa suppression."
end
end
diff --git a/app/helpers/dossier_helper.rb b/app/helpers/dossier_helper.rb
index 06827d1f9..1891b8485 100644
--- a/app/helpers/dossier_helper.rb
+++ b/app/helpers/dossier_helper.rb
@@ -25,12 +25,8 @@ module DossierHelper
end
end
- def url_for_new_dossier(procedure)
- if procedure.brouillon?
- new_dossier_url(procedure_id: procedure.id, brouillon: true)
- else
- new_dossier_url(procedure_id: procedure.id)
- end
+ def url_for_new_dossier(revision)
+ new_dossier_url(procedure_id: revision.procedure.id, brouillon: revision.draft? ? true : nil)
end
def dossier_form_class(dossier)
diff --git a/app/models/procedure.rb b/app/models/procedure.rb
index 589f2d741..7601f8269 100644
--- a/app/models/procedure.rb
+++ b/app/models/procedure.rb
@@ -307,9 +307,7 @@ class Procedure < ApplicationRecord
end
def reset!
- if locked?
- raise "Can not reset a locked procedure."
- else
+ if !locked? || draft_changed?
draft_revision.dossiers.destroy_all
end
end
diff --git a/app/views/commencer/show.html.haml b/app/views/commencer/show.html.haml
index 7abafdd4a..ccd867332 100644
--- a/app/views/commencer/show.html.haml
+++ b/app/views/commencer/show.html.haml
@@ -11,12 +11,12 @@
= link_to 'J’ai déjà un compte', commencer_sign_in_path(path: @procedure.path), class: ['button large expand']
- else
- - dossiers = current_user.dossiers.where(revision: @procedure.revisions)
+ - dossiers = current_user.dossiers.where(revision: @revision.draft? ? @revision : @procedure.revisions.where.not(id: @procedure.draft_revision_id))
- drafts = dossiers.merge(Dossier.state_brouillon)
- not_drafts = dossiers.merge(Dossier.state_not_brouillon)
- if dossiers.count == 0
- = link_to 'Commencer la démarche', url_for_new_dossier(@procedure), class: ['button large expand primary']
+ = link_to 'Commencer la démarche', url_for_new_dossier(@revision), class: ['button large expand primary']
- elsif drafts.count == 1 && not_drafts.count == 0
- dossier = drafts.first
@@ -25,7 +25,7 @@
Il y a #{time_ago_in_words(dossier.created_at)},
vous avez commencé à remplir un dossier sur la démarche « #{dossier.procedure.libelle} ».
= link_to 'Continuer à remplir mon dossier', brouillon_dossier_path(dossier), class: ['button large expand primary']
- = link_to 'Commencer un nouveau dossier', url_for_new_dossier(@procedure), class: ['button large expand']
+ = link_to 'Commencer un nouveau dossier', url_for_new_dossier(@revision), class: ['button large expand']
- elsif not_drafts.count == 1
- dossier = not_drafts.first
@@ -34,17 +34,15 @@
Il y a #{time_ago_in_words(dossier.en_construction_at)},
vous avez déposé un dossier sur la démarche « #{dossier.procedure.libelle} ».
= link_to 'Voir mon dossier déposé', dossier_path(dossier), class: ['button large expand primary']
- = link_to 'Commencer un nouveau dossier', url_for_new_dossier(@procedure), class: ['button large expand']
+ = link_to 'Commencer un nouveau dossier', url_for_new_dossier(@revision), class: ['button large expand']
- else
%h2.huge-title Vous avez déjà des dossiers pour cette démarche
= link_to 'Voir mes dossiers en cours', dossiers_path, class: ['button large expand primary']
- = link_to 'Commencer un nouveau dossier', url_for_new_dossier(@procedure), class: ['button large expand']
+ = link_to 'Commencer un nouveau dossier', url_for_new_dossier(@revision), class: ['button large expand']
- if @procedure.feature_enabled?(:dossier_pdf_vide)
- - pdf_link = commencer_dossier_vide_path(path: @procedure.path)
- - if @procedure.brouillon?
- - pdf_link = commencer_dossier_vide_test_path(path: @procedure.path)
+ - pdf_link = @revision.draft? ? commencer_dossier_vide_test_path(path: @procedure.path) : commencer_dossier_vide_path(path: @procedure.path)
%hr
%p
Vous souhaitez effectuer une demande par papier ? Vous pouvez télécharger un dossier vide au format PDF,
diff --git a/app/views/new_administrateur/procedures/publication.html.haml b/app/views/new_administrateur/procedures/publication.html.haml
index 4b07fd278..281966184 100644
--- a/app/views/new_administrateur/procedures/publication.html.haml
+++ b/app/views/new_administrateur/procedures/publication.html.haml
@@ -28,7 +28,7 @@
%p
Cette démarche est actuellement en test,
pour y accéder vous pouvez utiliser le lien :
- = link_to @procedure_lien, sanitize_url(@procedure_lien), target: :blank, rel: :noopener
+ = link_to @procedure_lien_test, sanitize_url(@procedure_lien_test), target: :blank, rel: :noopener
%p.mb-4
Toute personne ayant la connaissance de ce lien pourra ainsi remplir des dossiers de test sur votre démarche.
diff --git a/app/views/new_administrateur/procedures/show.html.haml b/app/views/new_administrateur/procedures/show.html.haml
index 9182af12f..f747f03f6 100644
--- a/app/views/new_administrateur/procedures/show.html.haml
+++ b/app/views/new_administrateur/procedures/show.html.haml
@@ -8,8 +8,8 @@
%span.icon.preview
Prévisualiser
- - if @procedure.brouillon?
- = link_to sanitize_url(@procedure_lien), target: :blank, rel: :noopener, class: 'button' do
+ - if @procedure.brouillon? || @procedure.draft_changed?
+ = link_to sanitize_url(@procedure_lien_test), target: :blank, rel: :noopener, class: 'button' do
%span.icon.in-progress
Tester
diff --git a/spec/controllers/users/commencer_controller_spec.rb b/spec/controllers/users/commencer_controller_spec.rb
index bf80703e8..39730b912 100644
--- a/spec/controllers/users/commencer_controller_spec.rb
+++ b/spec/controllers/users/commencer_controller_spec.rb
@@ -13,6 +13,7 @@ describe Users::CommencerController, type: :controller do
expect(subject.status).to eq(200)
expect(subject).to render_template('show')
expect(assigns(:procedure)).to eq published_procedure
+ expect(assigns(:revision)).to eq published_procedure.published_revision
end
end
@@ -43,6 +44,7 @@ describe Users::CommencerController, type: :controller do
expect(subject.status).to eq(200)
expect(subject).to render_template('show')
expect(assigns(:procedure)).to eq draft_procedure
+ expect(assigns(:revision)).to eq draft_procedure.draft_revision
end
end
diff --git a/spec/views/commencer/show.html.haml_spec.rb b/spec/views/commencer/show.html.haml_spec.rb
index faedd3bcf..40010ea92 100644
--- a/spec/views/commencer/show.html.haml_spec.rb
+++ b/spec/views/commencer/show.html.haml_spec.rb
@@ -5,6 +5,7 @@ RSpec.describe 'commencer/show.html.haml', type: :view do
before do
assign(:procedure, procedure)
+ assign(:revision, procedure.published_revision)
if user
sign_in user
end
diff --git a/spec/views/new_administrateur/procedures/show.html.haml_spec.rb b/spec/views/new_administrateur/procedures/show.html.haml_spec.rb
index 9ce7a8dd9..7901c610c 100644
--- a/spec/views/new_administrateur/procedures/show.html.haml_spec.rb
+++ b/spec/views/new_administrateur/procedures/show.html.haml_spec.rb
@@ -5,6 +5,7 @@ describe 'new_administrateur/procedures/show.html.haml', type: :view do
before do
assign(:procedure, procedure)
assign(:procedure_lien, commencer_url(path: procedure.path))
+ assign(:procedure_lien_test, commencer_test_url(path: procedure.path))
allow(view).to receive(:current_administrateur).and_return(procedure.administrateurs.first)
end