demarches-normaliennes/app/controllers/dossiers_controller.rb

69 lines
1.7 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
2015-08-17 16:27:21 +02:00
redirect_to url_for(controller: :start, action: :error_dossier)
2015-08-10 11:05:06 +02:00
end
def create
@etablissement = Etablissement.new(SIADE::EtablissementAdapter.new(siret).to_params)
@entreprise = Entreprise.new(SIADE::EntrepriseAdapter.new(siren).to_params)
@dossier = Dossier.create
2015-08-10 11:05:06 +02:00
@dossier.procedure_id
@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
2015-08-17 16:27:21 +02:00
redirect_to url_for(controller: :start, action: :error_siret)
rescue ActiveRecord::RecordNotFound
2015-08-17 16:27:21 +02:00
redirect_to url_for(controller: :start, action: :error_dossier)
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