From 45994ff567ca7d316e7b2b2cd5046e07f63d8c8a Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Mon, 17 Oct 2022 19:09:51 +0200 Subject: [PATCH] fix(invitation): when dossier is not visible anymore https://sentry.io/organizations/demarches-simplifiees/issues/3422144920/ --- app/models/targeted_user_link.rb | 3 +++ config/locales/en.yml | 2 +- config/locales/fr.yml | 2 +- .../targeted_user_links_controller_spec.rb | 12 ++++++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/models/targeted_user_link.rb b/app/models/targeted_user_link.rb index 129a6ca07..f5e02084c 100644 --- a/app/models/targeted_user_link.rb +++ b/app/models/targeted_user_link.rb @@ -35,6 +35,9 @@ class TargetedUserLink < ApplicationRecord case target_context when "invite" invite = target_model + + fail ActiveRecord::RecordNotFound if invite.nil? + user = User.find_by(email: target_email) user&.active? ? url_helper.invite_path(invite) : diff --git a/config/locales/en.yml b/config/locales/en.yml index bb726a245..6ca5e5189 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -362,7 +362,7 @@ en: messages: dossier_not_found: "The file does not exist or you do not have access to it." # # dossier_map_not_activated: "The file does not have access to the map." - targeted_user_link_expired: "This invitation link is not more accessible." + targeted_user_link_expired: "This invitation link or the file is no longer available." invalid_siret: "The SIRET is incorrect" procedure_not_found: "The procedure does not exist" siret_unknown: 'Sorry, we did not find any establishment registered under this SIRET number.' diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 770c8413e..6e5fa52a7 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -367,7 +367,7 @@ fr: saml_not_authorized: "Vous n’êtes pas autorisé à accéder à ce service." dossier_not_found: "Le dossier n’existe pas ou vous n’y avez pas accès." # dossier_map_not_activated: "Le dossier n’a pas accès à la cartographie." - targeted_user_link_expired: "Ce lien d'invitation n'est plus valable." + targeted_user_link_expired: "Ce lien d'invitation n'est plus valable ou le dossier n'est plus accessible." invalid_siret: "Le siret est incorrect" procedure_not_found: "La démarche n’existe pas" siret_unknown: 'Désolé, nous n’avons pas trouvé d’établissement enregistré correspondant à ce numéro SIRET.' diff --git a/spec/controllers/targeted_user_links_controller_spec.rb b/spec/controllers/targeted_user_links_controller_spec.rb index 958efd9eb..6ddc3fc8b 100644 --- a/spec/controllers/targeted_user_links_controller_spec.rb +++ b/spec/controllers/targeted_user_links_controller_spec.rb @@ -92,6 +92,17 @@ describe TargetedUserLinksController, type: :controller do expect(response).to redirect_to(invite_path(target_model, email: target_model.email)) end end + + context 'when there is no dossier visible anymore' do + let(:user) { nil } + let(:target_model) { create(:invite, user: user, dossier: create(:dossier, hidden_by_user_at: 1.day.ago)) } + + it 'redirect nicely' do + get :show, params: { id: targeted_user_link.id } + expect(response).to redirect_to(root_path) + expect(flash[:error]).to match(/dossier n'est plus accessible/) + end + end end context 'with invite not having user' do @@ -139,6 +150,7 @@ describe TargetedUserLinksController, type: :controller do get :show, params: { id: "asldjiasld" } expect(response).to redirect_to(root_path) expect(flash[:error]).to be_present + expect(flash[:error]).to match(/invitation n'est plus valable/) end end end