Enable test revisions
This commit is contained in:
parent
f288528e07
commit
280e54b59d
12 changed files with 36 additions and 44 deletions
|
@ -27,7 +27,7 @@ module NewAdministrateur
|
|||
end
|
||||
|
||||
def reset_procedure
|
||||
if @procedure.brouillon?
|
||||
if @procedure.brouillon? || @procedure.draft_changed?
|
||||
@procedure.reset!
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 <strong>#{time_ago_in_words(dossier.created_at)}</strong>,
|
||||
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 <strong>#{time_ago_in_words(dossier.en_construction_at)}</strong>,
|
||||
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,
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
%p
|
||||
Cette démarche est actuellement <strong>en test</strong>,
|
||||
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.
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue