fix(sentry/3422144920): old email using TargetUserLink creates confusing errors

This commit is contained in:
Martin 2022-10-04 11:41:32 +02:00
parent ca8755330a
commit 54a47fadae
5 changed files with 30 additions and 7 deletions

View file

@ -1,16 +1,17 @@
class TargetedUserLinksController < ApplicationController
before_action :set_targeted_user_link, only: [:show]
def show
if @targeted_user_link.invalid_signed_in_user?(current_user)
if targeted_user_link.invalid_signed_in_user?(current_user)
render
else
redirect_to @targeted_user_link.redirect_url(Rails.application.routes.url_helpers)
redirect_to targeted_user_link.redirect_url(Rails.application.routes.url_helpers)
end
rescue ActiveRecord::RecordNotFound
redirect_to root_path, flash: { error: t('errors.messages.targeted_user_link_expired') }
end
private
def set_targeted_user_link
@targeted_user_link = TargetedUserLink.find(params[:id])
def targeted_user_link
@targeted_user_link ||= TargetedUserLink.find(params[:id])
end
end

View file

@ -362,6 +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."
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

@ -365,6 +365,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."
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

@ -1,8 +1,8 @@
describe TargetedUserLinksController, type: :controller do
describe '#show' do
let!(:targeted_user_link) { create(:targeted_user_link, target_context: target_context, target_model: target_model, user: user) }
context 'avis' do
let!(:targeted_user_link) { create(:targeted_user_link, target_context: target_context, target_model: target_model, user: user) }
let(:target_context) { :avis }
let!(:expert) { create(:expert, user: user) }
let!(:target_model) { create(:avis, experts_procedure: expert_procedure) }
@ -56,6 +56,8 @@ describe TargetedUserLinksController, type: :controller do
end
context 'with invite having user' do
let!(:targeted_user_link) { create(:targeted_user_link, target_context: target_context, target_model: target_model, user: user) }
let(:target_context) { 'invite' }
let(:target_model) { create(:invite, user: user) }
@ -93,6 +95,7 @@ describe TargetedUserLinksController, type: :controller do
end
context 'with invite not having user' do
let!(:targeted_user_link) { create(:targeted_user_link, target_context: target_context, target_model: target_model, user: user) }
let(:target_context) { 'invite' }
let(:user_email) { 'not_yet_registered@a.com' }
let(:target_model) { create(:invite, user: nil, email: user_email) }
@ -129,5 +132,14 @@ describe TargetedUserLinksController, type: :controller do
end
end
end
context 'not found' do
it 'redirect nicely' do
sign_in(create(:user))
get :show, params: { id: "asldjiasld" }
expect(response).to redirect_to(root_path)
expect(flash[:error]).to be_present
end
end
end
end

View file

@ -55,6 +55,14 @@ describe Invite do
end
end
describe 'association' do
let!(:invite) { create(:invite, email: "email@totor.com") }
let!(:target_user_link) { create(:targeted_user_link, target_model: invite, target_context: 'invite') }
it 'destroy target_user_link' do
expect { invite.destroy! }.to change { TargetedUserLink.count }.from(1).to(0)
end
end
describe "#default_scope" do
let!(:dossier) { create(:dossier, hidden_by_user_at: hidden_by_user_at) }
let!(:invite) { create(:invite, email: "email@totor.com", dossier: dossier) }