demarches-normaliennes/app/controllers/users/commencer_controller.rb

105 lines
3.1 KiB
Ruby
Raw Normal View History

2019-03-25 10:53:45 +01:00
module Users
2018-11-01 13:00:35 +01:00
class CommencerController < ApplicationController
include QueryParamsStoreConcern
2019-01-16 11:57:58 +01:00
layout 'procedure_context'
def commencer
@procedure = retrieve_procedure
return procedure_not_found if @procedure.blank? || @procedure.brouillon?
2019-01-16 11:57:58 +01:00
store_query_params
@revision = @procedure.published_revision
2019-01-16 11:57:58 +01:00
render 'commencer/show'
2018-11-01 13:00:35 +01:00
end
2019-01-16 11:57:58 +01:00
def commencer_test
@procedure = retrieve_procedure
2021-06-24 11:57:05 +02:00
return procedure_not_found if @procedure.blank? || (@procedure.publiee? && !@procedure.draft_changed?)
@revision = @procedure.draft_revision
2019-01-16 11:57:58 +01:00
render 'commencer/show'
end
def dossier_vide_pdf
@procedure = retrieve_procedure_with_closed
return procedure_not_found if @procedure.blank? || @procedure.brouillon?
2021-06-24 11:57:05 +02:00
generate_empty_pdf(@procedure.published_revision)
end
def dossier_vide_pdf_test
@procedure = retrieve_procedure_with_closed
return procedure_not_found if @procedure.blank?
2021-06-24 11:57:05 +02:00
generate_empty_pdf(@procedure.draft_revision)
end
2019-01-16 11:57:58 +01:00
def sign_in
@procedure = retrieve_procedure
return procedure_not_found if @procedure.blank?
store_user_location!(@procedure)
2019-01-16 11:57:58 +01:00
redirect_to new_user_session_path
end
def sign_up
@procedure = retrieve_procedure
return procedure_not_found if @procedure.blank?
store_user_location!(@procedure)
2019-01-16 11:57:58 +01:00
redirect_to new_user_registration_path
end
def france_connect
@procedure = retrieve_procedure
return procedure_not_found if @procedure.blank?
store_user_location!(@procedure)
redirect_to france_connect_particulier_path
end
def procedure_for_help
retrieve_procedure
end
2019-01-16 11:57:58 +01:00
private
def retrieve_procedure
Procedure.publiees.or(Procedure.brouillons).find_by(path: params[:path])
end
def retrieve_procedure_with_closed
Procedure.publiees.or(Procedure.brouillons).or(Procedure.closes).find_by(path: params[:path])
end
def procedure_not_found
2019-01-16 11:57:58 +01:00
procedure = Procedure.find_by(path: params[:path])
if procedure&.replaced_by_procedure
redirect_to commencer_path(path: procedure.replaced_by_procedure.path)
return
elsif procedure&.close?
flash.alert = procedure.service.presence ?
t('errors.messages.procedure_archived.with_service_and_phone_email', service_name: procedure.service.nom, service_phone_number: procedure.service.telephone, service_email: procedure.service.email) :
t('errors.messages.procedure_archived.with_organisation_only', organisation_name: procedure.organisation)
else
flash.alert = t('errors.messages.procedure_not_found')
end
redirect_to root_path
end
def store_user_location!(procedure)
store_location_for(:user, helpers.procedure_lien(procedure))
2018-11-01 13:00:35 +01:00
end
2021-06-24 11:57:05 +02:00
def generate_empty_pdf(revision)
@dossier = revision.new_dossier
data = render_to_string(template: 'dossiers/dossier_vide', formats: [:pdf])
send_data(data, filename: "#{revision.procedure.libelle}.pdf")
end
2018-11-01 13:00:35 +01:00
end
end