From 9424d020bcd0565325bd198dbd27b07d23f078f5 Mon Sep 17 00:00:00 2001 From: Kara Diaby Date: Fri, 15 Mar 2024 16:42:41 +0000 Subject: [PATCH] controller --- app/controllers/experts/avis_controller.rb | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/app/controllers/experts/avis_controller.rb b/app/controllers/experts/avis_controller.rb index c9e4592d3..0f94a3bd4 100644 --- a/app/controllers/experts/avis_controller.rb +++ b/app/controllers/experts/avis_controller.rb @@ -4,10 +4,11 @@ module Experts include Zipline before_action :authenticate_expert!, except: [:sign_up, :update_expert] - before_action :check_if_avis_revoked, except: [:index, :procedure] + before_action :check_if_avis_revoked, except: [:index, :procedure, :notification_settings, :update_notification_settings] before_action :redirect_if_no_sign_up_needed, only: [:sign_up, :update_expert] before_action :set_avis_and_dossier, only: [:show, :instruction, :avis_list, :avis_new, :messagerie, :create_commentaire, :delete_commentaire, :update, :telecharger_pjs] before_action :check_messaging_allowed, only: [:messagerie, :create_commentaire] + before_action :set_procedure, only: [:notification_settings, :update_notification_settings] A_DONNER_STATUS = 'a-donner' DONNES_STATUS = 'donnes' @@ -66,6 +67,20 @@ module Experts def avis_list end + def expert_procedure + ExpertsProcedure.find_by(expert_id: current_expert.id, procedure_id: @procedure.id) + end + + def notification_settings + @expert_procedure = expert_procedure + end + + def update_notification_settings + expert_procedure.update!(expert_procedure_params) + flash.notice = 'Vos notifications sont enregistrées.' + redirect_to procedure_expert_avis_index_path(@procedure) + end + def avis_new @new_avis = Avis.new if @dossier.procedure.experts_require_administrateur_invitation? @@ -167,6 +182,15 @@ module Experts private + def expert_procedure_params + params.require(:experts_procedure) + .permit(:notify_on_new_avis, :notify_on_new_message) + end + + def set_procedure + @procedure = current_expert.procedures.find_by(id: params[:procedure_id]) + end + def check_messaging_allowed if !@avis.procedure.allow_expert_messaging flash[:alert] = "Vous n'êtes pas autorisé à acceder à la messagerie"