From d9cb5c067f0118c493a3613c8d3f3c53a1d13d0b Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Mon, 20 Jul 2020 16:26:16 +0200 Subject: [PATCH] relance un expert --- app/controllers/instructeurs/avis_controller.rb | 12 ++++++++++++ .../instructeurs/shared/avis/_list.html.haml | 3 +++ config/routes.rb | 1 + .../instructeurs/avis_controller_spec.rb | 15 +++++++++++++++ 4 files changed, 31 insertions(+) diff --git a/app/controllers/instructeurs/avis_controller.rb b/app/controllers/instructeurs/avis_controller.rb index 322734006..7096388ab 100644 --- a/app/controllers/instructeurs/avis_controller.rb +++ b/app/controllers/instructeurs/avis_controller.rb @@ -123,6 +123,18 @@ module Instructeurs end end + def revive + avis = Avis.find(params[:id]) + if avis.answer.blank? + AvisMailer.avis_invitation(avis).deliver_later + flash.notice = "Un mail de relance a été envoyé à #{avis.email_to_display}" + redirect_back(fallback_location: avis_instructeur_dossier_path(avis.procedure, avis.dossier)) + else + flash.alert = "#{avis.email} a déjà donné son avis" + redirect_back(fallback_location: avis_instructeur_dossier_path(avis.procedure, avis.dossier)) + end + end + private def set_avis_and_dossier diff --git a/app/views/instructeurs/shared/avis/_list.html.haml b/app/views/instructeurs/shared/avis/_list.html.haml index 3d35cc920..77d3963a9 100644 --- a/app/views/instructeurs/shared/avis/_list.html.haml +++ b/app/views/instructeurs/shared/avis/_list.html.haml @@ -35,7 +35,10 @@ - else %span.waiting En attente de réponse + | + %span.waiting= link_to("Relancer l'expert", revive_instructeur_avis_path(avis.procedure, avis), data: { confirm: "Souhaitez-vous relancer #{avis.email_to_display} ?"}) - if avis.revokable_by?(current_instructeur) + | = link_to(t('revoke', scope: 'helpers.label'), revoquer_instructeur_avis_path(avis.procedure, avis), data: { confirm: "Souhaitez-vous révoquer la demande d'avis à #{avis.email_to_display} ?" }, method: :patch) - if avis.piece_justificative_file.attached? = render partial: 'shared/attachment/show', locals: { attachment: avis.piece_justificative_file.attachment } diff --git a/config/routes.rb b/config/routes.rb index 560f5e11f..7bfbea98d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -319,6 +319,7 @@ Rails.application.routes.draw do post 'commentaire' => 'avis#create_commentaire' post 'avis' => 'avis#create_avis' patch 'revoquer' + get 'revive' get 'bilans_bdf' get 'sign_up/email/:email' => 'avis#sign_up', constraints: { email: /.*/ }, as: 'sign_up' diff --git a/spec/controllers/instructeurs/avis_controller_spec.rb b/spec/controllers/instructeurs/avis_controller_spec.rb index 0e73fc559..f4baa950c 100644 --- a/spec/controllers/instructeurs/avis_controller_spec.rb +++ b/spec/controllers/instructeurs/avis_controller_spec.rb @@ -282,6 +282,21 @@ describe Instructeurs::AvisController, type: :controller do expect(flash.notice).to eq("#{avis.email} ne peut plus donner son avis sur ce dossier.") end end + + describe 'revive' do + let(:avis) { create(:avis, claimant: instructeur, email: 'expert@gouv.fr') } + let(:procedure) { avis.procedure } + + before do + allow(AvisMailer).to receive(:avis_invitation).and_return(double(deliver_later: nil)) + end + + it 'revive the expert' do + get :revive, params: { procedure_id: procedure.id, id: avis.id } + expect(AvisMailer).to have_received(:avis_invitation).once.with(avis) + expect(flash.notice).to eq("Un mail de relance a été envoyé à #{avis.email}") + end + end end context 'without a instructeur signed in' do