fix(invitation): don't fail when dossier is hidden & user signed on another account
Suite de 45994ff567
Cf https://sentry.io/organizations/demarches-simplifiees/issues/3422144920/events/e1c83ea74dbc410ea22aa17ef29fb329/?project=1429550
This commit is contained in:
parent
9ac8c85b28
commit
9f2fa5ee1c
2 changed files with 18 additions and 6 deletions
|
@ -25,7 +25,8 @@ class TargetedUserLink < ApplicationRecord
|
||||||
when 'avis'
|
when 'avis'
|
||||||
user.email
|
user.email
|
||||||
when 'invite'
|
when 'invite'
|
||||||
target_model.user&.email || target_model.email
|
invite = find_invite!
|
||||||
|
invite.user&.email || invite.email
|
||||||
else
|
else
|
||||||
raise 'invalid target_context'
|
raise 'invalid target_context'
|
||||||
end
|
end
|
||||||
|
@ -34,14 +35,12 @@ class TargetedUserLink < ApplicationRecord
|
||||||
def redirect_url(url_helper)
|
def redirect_url(url_helper)
|
||||||
case target_context
|
case target_context
|
||||||
when "invite"
|
when "invite"
|
||||||
invite = target_model
|
invite = find_invite!
|
||||||
|
|
||||||
fail ActiveRecord::RecordNotFound if invite.nil?
|
|
||||||
|
|
||||||
user = User.find_by(email: target_email)
|
user = User.find_by(email: target_email)
|
||||||
user&.active? ?
|
user&.active? ?
|
||||||
url_helper.invite_path(invite) :
|
url_helper.invite_path(invite) :
|
||||||
url_helper.invite_path(invite, params: { email: invite.email })
|
url_helper.invite_path(invite, params: { email: invite.email })
|
||||||
when "avis"
|
when "avis"
|
||||||
avis = target_model
|
avis = target_model
|
||||||
avis.expert.user.active? ?
|
avis.expert.user.active? ?
|
||||||
|
@ -49,4 +48,10 @@ class TargetedUserLink < ApplicationRecord
|
||||||
url_helper.sign_up_expert_avis_path(avis.procedure, avis, email: avis.expert.email)
|
url_helper.sign_up_expert_avis_path(avis.procedure, avis, email: avis.expert.email)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def find_invite!
|
||||||
|
target_model || (fail ActiveRecord::RecordNotFound.new("Could not find Invite with id `#{target_model_id}`"))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -102,6 +102,13 @@ describe TargetedUserLinksController, type: :controller do
|
||||||
expect(response).to redirect_to(root_path)
|
expect(response).to redirect_to(root_path)
|
||||||
expect(flash[:error]).to match(/dossier n'est plus accessible/)
|
expect(flash[:error]).to match(/dossier n'est plus accessible/)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'redirect nicely also when user is signed on another account' do
|
||||||
|
sign_in(create(:expert).user)
|
||||||
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue