Merge pull request #3719 from betagouv/fix-commencer-with-invalid-path

commencer: fix redirection with invalid path
This commit is contained in:
Pierre de La Morinerie 2019-04-04 14:10:22 +02:00 committed by GitHub
commit 0f1e06e19c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 14 deletions

View file

@ -4,38 +4,39 @@ module Users
def commencer def commencer
@procedure = Procedure.publiees.find_by(path: params[:path]) @procedure = Procedure.publiees.find_by(path: params[:path])
return procedure_not_found if @procedure.blank?
if @procedure.blank?
flash.alert = "La démarche est inconnue, ou la création de nouveaux dossiers pour cette démarche est terminée."
return redirect_to root_path
end
render 'commencer/show' render 'commencer/show'
end end
def commencer_test def commencer_test
@procedure = Procedure.brouillons.find_by(path: params[:path]) @procedure = Procedure.brouillons.find_by(path: params[:path])
return procedure_not_found if @procedure.blank?
if @procedure.blank?
flash.alert = "La démarche est inconnue, ou cette démarche nest maintenant plus en test."
return redirect_to root_path
end
render 'commencer/show' render 'commencer/show'
end end
def sign_in def sign_in
store_user_location! @procedure = Procedure.find_by(path: params[:path])
return procedure_not_found if @procedure.blank?
store_user_location!(@procedure)
redirect_to new_user_session_path redirect_to new_user_session_path
end end
def sign_up def sign_up
store_user_location! @procedure = Procedure.find_by(path: params[:path])
return procedure_not_found if @procedure.blank?
store_user_location!(@procedure)
redirect_to new_user_registration_path redirect_to new_user_registration_path
end end
def france_connect def france_connect
store_user_location! @procedure = Procedure.find_by(path: params[:path])
return procedure_not_found if @procedure.blank?
store_user_location!(@procedure)
redirect_to france_connect_particulier_path redirect_to france_connect_particulier_path
end end
@ -45,8 +46,21 @@ module Users
private private
def store_user_location! def procedure_not_found
procedure = Procedure.find_by(path: params[:path]) 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
end
def store_user_location!(procedure)
store_location_for(:user, helpers.procedure_lien(procedure)) store_location_for(:user, helpers.procedure_lien(procedure))
end end
end end

View file

@ -188,6 +188,7 @@ fr:
connexion: "Erreur lors de la connexion à France Connect." connexion: "Erreur lors de la connexion à France Connect."
extension_white_list_error: "Le format de fichier de la pièce jointe n'est pas valide." extension_white_list_error: "Le format de fichier de la pièce jointe n'est pas valide."
procedure_archived: "Cette démarche en ligne a été fermée, il n'est plus possible de déposer de dossier." procedure_archived: "Cette démarche en ligne a été fermée, il n'est plus possible de déposer de dossier."
procedure_not_draft: "Cette démarche nest maintenant plus en brouillon."
cadastres_empty: cadastres_empty:
one: "Aucune parcelle cadastrale sur la zone séléctionnée" one: "Aucune parcelle cadastrale sur la zone séléctionnée"
other: "Aucune parcelle cadastrale sur les zones séléctionnées" other: "Aucune parcelle cadastrale sur les zones séléctionnées"

View file

@ -87,6 +87,14 @@ describe Users::CommencerController, type: :controller do
it { expect(subject).to redirect_to(new_user_session_path) } it { expect(subject).to redirect_to(new_user_session_path) }
end end
context 'when the path doesnt exist' do
subject { get :sign_in, params: { path: 'hello' } }
it 'redirects with an error message' do
expect(subject).to redirect_to(root_path)
end
end
end end
describe '#sign_up' do describe '#sign_up' do
@ -111,6 +119,14 @@ describe Users::CommencerController, type: :controller do
it { expect(subject).to redirect_to(new_user_registration_path) } it { expect(subject).to redirect_to(new_user_registration_path) }
end end
context 'when the path doesnt exist' do
subject { get :sign_up, params: { path: 'hello' } }
it 'redirects with an error message' do
expect(subject).to redirect_to(root_path)
end
end
end end
describe '#france_connect' do describe '#france_connect' do
@ -135,5 +151,13 @@ describe Users::CommencerController, type: :controller do
it { expect(subject).to redirect_to(france_connect_particulier_path) } it { expect(subject).to redirect_to(france_connect_particulier_path) }
end end
context 'when the path doesnt exist' do
subject { get :france_connect, params: { path: 'hello' } }
it 'redirects with an error message' do
expect(subject).to redirect_to(root_path)
end
end
end end
end end