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

90 lines
2.3 KiB
Ruby
Raw Normal View History

2015-09-23 19:20:03 +02:00
class Users::DossiersController < UsersController
2016-01-08 11:39:04 +01:00
include SmartListing::Helper::ControllerExtensions
helper SmartListing::Helper
SESSION_USER_RETURN_LOCATION = 'user_return_to'
before_action :store_user_location!, only: :new
2018-08-14 11:47:47 +02:00
before_action :authenticate_user!, except: [:commencer, :commencer_test]
2016-01-26 15:52:05 +01:00
before_action only: [:show] do
authorized_routes? self.class
end
def commencer_test
procedure_path = ProcedurePath.find_by(path: params[:procedure_path])
2018-08-14 11:47:47 +02:00
procedure = procedure_path&.procedure
2017-01-10 15:27:40 +01:00
if procedure&.brouillon? && procedure&.path.present?
2018-08-14 11:47:47 +02:00
redirect_to new_users_dossier_path(procedure_id: procedure.id, brouillon: true)
else
2018-09-05 14:48:42 +02:00
flash.alert = "La démarche est inconnue."
redirect_to root_path
end
end
def commencer
procedure_path = ProcedurePath.find_by(path: params[:procedure_path])
2018-05-23 15:36:50 +02:00
procedure = procedure_path&.procedure
2016-11-07 17:08:33 +01:00
if procedure.present?
if procedure.archivee?
@dossier = Dossier.new(procedure: procedure)
2016-11-07 17:08:33 +01:00
render 'commencer/archived'
else
redirect_to new_users_dossier_path(procedure_id: procedure.id)
end
else
2018-09-05 14:48:42 +02:00
flash.alert = "La démarche est inconnue, ou la création de nouveaux dossiers pour cette démarche est terminée."
redirect_to root_path
2016-11-07 17:08:33 +01:00
end
end
def new
erase_user_location!
2018-08-14 11:47:47 +02:00
if params[:brouillon]
procedure = Procedure.brouillon.find(params[:procedure_id])
else
procedure = Procedure.publiees.find(params[:procedure_id])
end
dossier = Dossier.create!(procedure: procedure, user: current_user, state: Dossier.states.fetch(:brouillon))
if dossier.procedure.for_individual
redirect_to identite_dossier_path(dossier)
else
redirect_to siret_dossier_path(id: dossier.id)
end
rescue ActiveRecord::RecordNotFound
error_procedure
end
2016-01-26 15:52:05 +01:00
def self.route_authorization
{
2018-08-28 14:12:48 +02:00
states: [Dossier.states.fetch(:brouillon)]
2016-01-26 15:52:05 +01:00
}
end
2015-09-23 19:20:03 +02:00
private
def error_procedure
2015-12-24 15:22:30 +01:00
flash.alert = t('errors.messages.procedure_not_found')
redirect_to url_for dossiers_path
end
def facade(id = params[:id])
DossierFacades.new id, current_user.email
end
def store_user_location!
store_location_for(:user, request.fullpath)
end
def erase_user_location!
session.delete(SESSION_USER_RETURN_LOCATION)
end
end