commencer: redirect to the procedure page after sign-in and sign-up

This commit is contained in:
Pierre de La Morinerie 2019-01-16 15:16:15 +00:00
parent 016e5f2e6f
commit bb753ce23e
11 changed files with 62 additions and 27 deletions

View file

@ -5,8 +5,8 @@ module ProcedureContextConcern
include Devise::StoreLocationExtension
def restore_procedure_context
if stored_procedure_id.present?
@procedure = Procedure.publiees.find_by(id: stored_procedure_id)
if has_stored_procedure_path?
@procedure = find_procedure_in_context
if @procedure.blank?
invalid_procedure_context
@ -16,11 +16,18 @@ module ProcedureContextConcern
private
def stored_procedure_id
stored_location = get_stored_location_for(:user)
def has_stored_procedure_path?
get_stored_location_for(:user)&.start_with?('/commencer/')
end
if stored_location.present? && stored_location.include?('procedure_id=')
stored_location.split('procedure_id=').second
def find_procedure_in_context
uri = URI(get_stored_location_for(:user))
path_components = uri.path.split('/')
if uri.path.start_with?('/commencer/test/')
Procedure.brouillon.find_by(path: path_components[3])
elsif uri.path.start_with?('/commencer/')
Procedure.publiee.find_by(path: path_components[2])
else
nil
end

View file

@ -38,7 +38,7 @@ module NewUser
def store_user_location!
procedure = Procedure.find_by(path: params[:path])
store_location_for(:user, new_dossier_path(procedure_id: procedure.id))
store_location_for(:user, commencer_path(path: procedure.path))
end
end
end