From 99f986b815d67d22a898ad4cfa05c22b7d152801 Mon Sep 17 00:00:00 2001 From: Nicolas Bouilleaud Date: Fri, 5 Jul 2019 10:37:29 +0200 Subject: [PATCH] =?UTF-8?q?Cleanup=20Procedure=20retrieval=20in=20?= =?UTF-8?q?=E2=80=9CCommencer=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make sure to only fetch active (brouillons or published) procedures. --- app/controllers/users/commencer_controller.rb | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/app/controllers/users/commencer_controller.rb b/app/controllers/users/commencer_controller.rb index 9a16ee2aa..841acd58a 100644 --- a/app/controllers/users/commencer_controller.rb +++ b/app/controllers/users/commencer_controller.rb @@ -3,21 +3,21 @@ module Users layout 'procedure_context' def commencer - @procedure = Procedure.publiees.find_by(path: params[:path]) - return procedure_not_found if @procedure.blank? + @procedure = retrieve_procedure + return procedure_not_found if @procedure.blank? || @procedure.brouillon? render 'commencer/show' end def commencer_test - @procedure = Procedure.brouillons.find_by(path: params[:path]) - return procedure_not_found if @procedure.blank? + @procedure = retrieve_procedure + return procedure_not_found if @procedure.blank? || @procedure.publiee? render 'commencer/show' end def sign_in - @procedure = Procedure.find_by(path: params[:path]) + @procedure = retrieve_procedure return procedure_not_found if @procedure.blank? store_user_location!(@procedure) @@ -25,7 +25,7 @@ module Users end def sign_up - @procedure = Procedure.find_by(path: params[:path]) + @procedure = retrieve_procedure return procedure_not_found if @procedure.blank? store_user_location!(@procedure) @@ -33,7 +33,7 @@ module Users end def france_connect - @procedure = Procedure.find_by(path: params[:path]) + @procedure = retrieve_procedure return procedure_not_found if @procedure.blank? store_user_location!(@procedure) @@ -41,23 +41,25 @@ module Users end def procedure_for_help - Procedure.publiees.find_by(path: params[:path]) || Procedure.brouillons.find_by(path: params[:path]) + retrieve_procedure end private + def retrieve_procedure + Procedure.publiees.or(Procedure.brouillons).find_by(path: params[:path]) + end + def procedure_not_found procedure = Procedure.find_by(path: params[:path]) if procedure&.archivee? flash.alert = t('errors.messages.procedure_archived') - elsif procedure&.publiee? - flash.alert = t('errors.messages.procedure_not_draft') else flash.alert = t('errors.messages.procedure_not_found') end - return redirect_to root_path + redirect_to root_path end def store_user_location!(procedure)