2017-04-25 17:02:54 +02:00
|
|
|
class Backoffice::AvisController < ApplicationController
|
|
|
|
|
2017-05-02 16:20:16 +02:00
|
|
|
before_action :authenticate_gestionnaire!
|
|
|
|
|
2017-04-25 17:02:54 +02:00
|
|
|
def create
|
|
|
|
avis = Avis.new(create_params)
|
|
|
|
avis.dossier = dossier
|
2017-05-02 16:20:16 +02:00
|
|
|
|
|
|
|
gestionnaire = Gestionnaire.find_by(email: create_params[:email])
|
|
|
|
if gestionnaire
|
|
|
|
avis.gestionnaire = gestionnaire
|
|
|
|
avis.email = nil
|
|
|
|
end
|
|
|
|
|
2017-04-25 17:02:54 +02:00
|
|
|
avis.save
|
|
|
|
|
|
|
|
redirect_to backoffice_dossier_path(dossier)
|
|
|
|
end
|
|
|
|
|
2017-05-24 18:45:31 +02:00
|
|
|
def update
|
|
|
|
if avis.update(update_params)
|
|
|
|
flash[:notice] = 'Merci, votre avis a été enregistré.'
|
|
|
|
end
|
|
|
|
|
|
|
|
redirect_to backoffice_dossier_path(avis.dossier_id)
|
|
|
|
end
|
|
|
|
|
2017-04-25 17:02:54 +02:00
|
|
|
private
|
|
|
|
|
|
|
|
def dossier
|
|
|
|
current_gestionnaire.dossiers.find(params[:dossier_id])
|
|
|
|
end
|
|
|
|
|
2017-05-24 18:45:31 +02:00
|
|
|
def avis
|
|
|
|
current_gestionnaire.avis.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2017-04-25 17:02:54 +02:00
|
|
|
def create_params
|
|
|
|
params.require(:avis).permit(:email, :introduction)
|
|
|
|
end
|
|
|
|
|
2017-05-24 18:45:31 +02:00
|
|
|
def update_params
|
|
|
|
params.require(:avis).permit(:answer)
|
|
|
|
end
|
|
|
|
|
2017-04-25 17:02:54 +02:00
|
|
|
end
|