demarches-normaliennes/app/controllers/dossiers_controller.rb

74 lines
2 KiB
Ruby
Raw Normal View History

2015-08-10 11:05:06 +02:00
class DossiersController < ApplicationController
def show
@dossier = Dossier.find(params[:id])
@etablissement = @dossier.etablissement
2015-08-10 11:05:06 +02:00
@entreprise = @dossier.entreprise.decorate
rescue ActiveRecord::RecordNotFound
flash.alert = t('errors.messages.dossier_not_found')
redirect_to url_for(controller: :siret)
2015-08-10 11:05:06 +02:00
end
def create
procedure = Procedure.find(params['procedure_id'])
@etablissement = Etablissement.new(SIADE::EtablissementAdapter.new(siret).to_params)
@entreprise = Entreprise.new(SIADE::EntrepriseAdapter.new(siren).to_params)
@dossier = Dossier.create
@dossier.draft!
2015-08-10 11:05:06 +02:00
@dossier.procedure = procedure
@dossier.save
@entreprise.dossier = @dossier
@entreprise.save
2015-08-10 11:05:06 +02:00
@etablissement.dossier = @dossier
@etablissement.entreprise = @entreprise
@etablissement.save
2015-08-10 11:05:06 +02:00
redirect_to url_for(controller: :dossiers, action: :show, id: @dossier.id)
rescue RestClient::ResourceNotFound
flash.alert = t('errors.messages.invalid_siret')
redirect_to url_for(controller: :siret, procedure_id: params['procedure_id'])
rescue ActiveRecord::RecordNotFound
flash.alert = t('errors.messages.dossier_not_found')
redirect_to url_for(controller: :siret)
2015-08-10 11:05:06 +02:00
end
def update
@dossier = Dossier.find(params[:id])
2015-08-17 16:27:21 +02:00
if checked_autorisation_donnees?
@dossier.update_attributes(update_params)
redirect_to url_for(controller: :description, action: :show, dossier_id: @dossier.id)
2015-08-10 11:05:06 +02:00
else
@etablissement = @dossier.etablissement
2015-08-10 11:05:06 +02:00
@entreprise = @dossier.entreprise.decorate
2015-08-17 16:27:21 +02:00
flash.now.alert = 'Les conditions sont obligatoires.'
render 'show'
2015-08-10 11:05:06 +02:00
end
end
2015-08-11 15:22:07 +02:00
private
def update_params
params.require(:dossier).permit(:autorisation_donnees)
end
2015-08-11 15:22:07 +02:00
def dossier_id_is_present?
2015-08-20 16:37:40 +02:00
@dossier_id != ''
2015-08-17 16:27:21 +02:00
end
2015-08-11 15:22:07 +02:00
2015-08-17 16:27:21 +02:00
def checked_autorisation_donnees?
update_params[:autorisation_donnees] == '1'
2015-08-11 15:22:07 +02:00
end
def siret
params[:siret]
end
def siren
siret[0..8]
end
2015-08-10 11:05:06 +02:00
end