From fac365e01d1843c8ba4e6407107a817a9dabfe1b Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 12 Dec 2023 15:25:22 +0100 Subject: [PATCH] feat(file retrieval): ensure agent connect is used --- app/controllers/recoveries_controller.rb | 8 ++++++++ app/views/recoveries/support.html.haml | 11 +++++++++++ spec/controllers/recoveries_controller_spec.rb | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/app/controllers/recoveries_controller.rb b/app/controllers/recoveries_controller.rb index 488f3947a..5fbc0ffb4 100644 --- a/app/controllers/recoveries_controller.rb +++ b/app/controllers/recoveries_controller.rb @@ -1,4 +1,6 @@ class RecoveriesController < ApplicationController + before_action :ensure_agent_connect_is_used, except: [:nature, :post_nature, :support] + def nature end @@ -33,4 +35,10 @@ class RecoveriesController < ApplicationController private def nature_params = params[:nature] + + def ensure_agent_connect_is_used + if current_instructeur&.agent_connect_information.nil? + redirect_to support_recovery_path(error: :must_use_agent_connect) + end + end end diff --git a/app/views/recoveries/support.html.haml b/app/views/recoveries/support.html.haml index bc21d3b9d..e196e8ab9 100644 --- a/app/views/recoveries/support.html.haml +++ b/app/views/recoveries/support.html.haml @@ -11,3 +11,14 @@ 'Contactez le support', subject: 'Récupération de dossiers', class: 'fr-btn') + + - when 'must_use_agent_connect' + %p Vous devez utiliser le portail AgentConnect pour récupérer vos dossiers. + + = link_to(agent_connect_login_path, class: "fr-btn fr-connect") do + %span.fr-connect__login + = t('signin_with', scope: [:agent_connect, :agent, :index]) + %span.fr-connect__brand AgentConnect + + %p Vous n'avez pas encore de compte AgentConnect ? Vous pouvez en créer un en utilisant MonComptePro. + = link_to 'MonComptePro', 'https://moncomptepro.beta.gouv.fr', class: 'fr-btn' diff --git a/spec/controllers/recoveries_controller_spec.rb b/spec/controllers/recoveries_controller_spec.rb index f5ddc577c..2301805fb 100644 --- a/spec/controllers/recoveries_controller_spec.rb +++ b/spec/controllers/recoveries_controller_spec.rb @@ -26,4 +26,22 @@ describe RecoveriesController, type: :controller do it { is_expected.to have_http_status(:success) } end + + describe 'ensure_agent_connect_is_used' do + subject { post :selection } + + context 'when agent connect is used' do + let(:instructeur) { create(:instructeur, :with_agent_connect_information) } + + before do + allow(controller).to receive(:current_instructeur).and_return(instructeur) + end + + it { is_expected.to have_http_status(:success) } + end + + context 'when agent connect is not used' do + it { is_expected.to redirect_to(support_recovery_path(error: :must_use_agent_connect)) } + end + end end