2019-03-25 10:53:45 +01:00
|
|
|
module Users
|
2018-11-01 13:00:35 +01:00
|
|
|
class CommencerController < ApplicationController
|
2022-12-15 10:58:17 +01:00
|
|
|
include QueryParamsStoreConcern
|
|
|
|
|
2019-01-16 11:57:58 +01:00
|
|
|
layout 'procedure_context'
|
|
|
|
|
2023-01-03 14:46:10 +01:00
|
|
|
before_action :retrieve_prefilled_dossier, if: -> { params[:prefill_token].present? }, only: :commencer
|
|
|
|
before_action :set_prefilled_dossier_ownership, if: -> { user_signed_in? && @prefilled_dossier&.orphan? }, only: :commencer
|
|
|
|
before_action :check_prefilled_dossier_ownership, if: -> { user_signed_in? && @prefilled_dossier }, only: :commencer
|
|
|
|
|
2019-01-16 11:57:58 +01:00
|
|
|
def commencer
|
2019-07-05 10:37:29 +02:00
|
|
|
@procedure = retrieve_procedure
|
|
|
|
return procedure_not_found if @procedure.blank? || @procedure.brouillon?
|
2019-01-16 11:57:58 +01:00
|
|
|
|
2022-12-15 10:58:17 +01:00
|
|
|
store_query_params
|
|
|
|
|
2022-07-29 10:44:30 +02:00
|
|
|
@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
|
2019-07-05 10:37:29 +02:00
|
|
|
@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
|
|
|
|
|
2020-02-27 17:39:11 +01:00
|
|
|
def dossier_vide_pdf
|
2022-08-05 15:45:13 +02:00
|
|
|
@procedure = retrieve_procedure_with_closed
|
2020-02-27 17:39:11 +01:00
|
|
|
return procedure_not_found if @procedure.blank? || @procedure.brouillon?
|
|
|
|
|
2021-06-24 11:57:05 +02:00
|
|
|
generate_empty_pdf(@procedure.published_revision)
|
2020-02-27 17:39:11 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def dossier_vide_pdf_test
|
2022-08-05 15:45:13 +02:00
|
|
|
@procedure = retrieve_procedure_with_closed
|
2022-12-01 13:29:08 +01:00
|
|
|
return procedure_not_found if @procedure.blank?
|
2020-02-27 17:39:11 +01:00
|
|
|
|
2021-06-24 11:57:05 +02:00
|
|
|
generate_empty_pdf(@procedure.draft_revision)
|
2020-02-27 17:39:11 +01:00
|
|
|
end
|
|
|
|
|
2019-01-16 11:57:58 +01:00
|
|
|
def sign_in
|
2019-07-05 10:37:29 +02:00
|
|
|
@procedure = retrieve_procedure
|
2019-04-04 14:03:03 +02:00
|
|
|
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
|
2019-07-05 10:37:29 +02:00
|
|
|
@procedure = retrieve_procedure
|
2019-04-04 14:03:03 +02:00
|
|
|
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
|
|
|
|
|
2019-04-02 15:03:35 +02:00
|
|
|
def france_connect
|
2019-07-05 10:37:29 +02:00
|
|
|
@procedure = retrieve_procedure
|
2019-04-04 14:03:03 +02:00
|
|
|
return procedure_not_found if @procedure.blank?
|
|
|
|
|
|
|
|
store_user_location!(@procedure)
|
2019-04-02 15:03:35 +02:00
|
|
|
redirect_to france_connect_particulier_path
|
|
|
|
end
|
|
|
|
|
2019-03-28 11:14:01 +01:00
|
|
|
def procedure_for_help
|
2019-07-05 10:37:29 +02:00
|
|
|
retrieve_procedure
|
2019-03-28 11:14:01 +01:00
|
|
|
end
|
|
|
|
|
2019-01-16 11:57:58 +01:00
|
|
|
private
|
|
|
|
|
2019-07-05 10:37:29 +02:00
|
|
|
def retrieve_procedure
|
|
|
|
Procedure.publiees.or(Procedure.brouillons).find_by(path: params[:path])
|
|
|
|
end
|
|
|
|
|
2022-08-05 15:45:13 +02:00
|
|
|
def retrieve_procedure_with_closed
|
|
|
|
Procedure.publiees.or(Procedure.brouillons).or(Procedure.closes).find_by(path: params[:path])
|
|
|
|
end
|
|
|
|
|
2023-01-03 14:46:10 +01:00
|
|
|
def retrieve_prefilled_dossier
|
|
|
|
@prefilled_dossier = Dossier.state_brouillon.prefilled.find_by!(prefill_token: params[:prefill_token])
|
|
|
|
end
|
|
|
|
|
|
|
|
# The prefilled dossier is not owned yet, and the user is signed in: they become the new owner
|
|
|
|
def set_prefilled_dossier_ownership
|
|
|
|
@prefilled_dossier.update!(user: current_user)
|
|
|
|
DossierMailer.with(dossier: @prefilled_dossier).notify_new_draft.deliver_later
|
|
|
|
end
|
|
|
|
|
|
|
|
# The prefilled dossier is owned by another user: raise an exception
|
|
|
|
def check_prefilled_dossier_ownership
|
|
|
|
raise ActiveRecord::RecordNotFound unless @prefilled_dossier.owned_by?(current_user)
|
|
|
|
end
|
|
|
|
|
2019-04-04 14:03:03 +02:00
|
|
|
def procedure_not_found
|
2019-01-16 11:57:58 +01:00
|
|
|
procedure = Procedure.find_by(path: params[:path])
|
2019-04-04 14:03:03 +02:00
|
|
|
|
2022-07-29 10:44:30 +02:00
|
|
|
if procedure&.replaced_by_procedure
|
|
|
|
redirect_to commencer_path(path: procedure.replaced_by_procedure.path)
|
|
|
|
return
|
|
|
|
elsif procedure&.close?
|
2022-05-12 15:32:42 +02:00
|
|
|
flash.alert = procedure.service.presence ?
|
2022-06-01 15:10:26 +02:00
|
|
|
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) :
|
2022-05-13 13:15:31 +02:00
|
|
|
t('errors.messages.procedure_archived.with_organisation_only', organisation_name: procedure.organisation)
|
2019-04-04 14:03:03 +02:00
|
|
|
else
|
|
|
|
flash.alert = t('errors.messages.procedure_not_found')
|
|
|
|
end
|
|
|
|
|
2019-07-05 10:37:29 +02:00
|
|
|
redirect_to root_path
|
2019-04-04 14:03:03 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def store_user_location!(procedure)
|
2023-01-03 14:46:10 +01:00
|
|
|
store_location_for(:user, helpers.procedure_lien(procedure, prefill_token: params[:prefill_token]))
|
2018-11-01 13:00:35 +01:00
|
|
|
end
|
2020-03-17 14:51:27 +01:00
|
|
|
|
2021-06-24 11:57:05 +02:00
|
|
|
def generate_empty_pdf(revision)
|
|
|
|
@dossier = revision.new_dossier
|
2022-04-28 13:57:19 +02:00
|
|
|
data = render_to_string(template: 'dossiers/dossier_vide', formats: [:pdf])
|
2022-04-28 13:59:23 +02:00
|
|
|
send_data(data, filename: "#{revision.procedure.libelle}.pdf")
|
2020-03-17 14:51:27 +01:00
|
|
|
end
|
2018-11-01 13:00:35 +01:00
|
|
|
end
|
|
|
|
end
|