fix(invitation): when dossier is not visible anymore

https://sentry.io/organizations/demarches-simplifiees/issues/3422144920/
This commit is contained in:
Colin Darie 2022-10-17 19:09:51 +02:00
parent fe81b73052
commit 45994ff567
4 changed files with 17 additions and 2 deletions

View file

@ -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) :

View file

@ -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.'

View file

@ -367,7 +367,7 @@ fr:
saml_not_authorized: "Vous nêtes pas autorisé à accéder à ce service."
dossier_not_found: "Le dossier nexiste pas ou vous ny avez pas accès."
# dossier_map_not_activated: "Le dossier na 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 nexiste pas"
siret_unknown: 'Désolé, nous navons pas trouvé détablissement enregistré correspondant à ce numéro SIRET.'

View file

@ -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