Merge pull request #7954 from colinux/fix-invitation-when-already-signed
fix(invitation): don't fail when dossier is hidden & user signed on another account
This commit is contained in:
commit
3b5256c05c
2 changed files with 18 additions and 6 deletions
|
@ -25,7 +25,8 @@ class TargetedUserLink < ApplicationRecord
|
|||
when 'avis'
|
||||
user.email
|
||||
when 'invite'
|
||||
target_model.user&.email || target_model.email
|
||||
invite = find_invite!
|
||||
invite.user&.email || invite.email
|
||||
else
|
||||
raise 'invalid target_context'
|
||||
end
|
||||
|
@ -34,14 +35,12 @@ class TargetedUserLink < ApplicationRecord
|
|||
def redirect_url(url_helper)
|
||||
case target_context
|
||||
when "invite"
|
||||
invite = target_model
|
||||
|
||||
fail ActiveRecord::RecordNotFound if invite.nil?
|
||||
invite = find_invite!
|
||||
|
||||
user = User.find_by(email: target_email)
|
||||
user&.active? ?
|
||||
url_helper.invite_path(invite) :
|
||||
url_helper.invite_path(invite, params: { email: invite.email })
|
||||
url_helper.invite_path(invite) :
|
||||
url_helper.invite_path(invite, params: { email: invite.email })
|
||||
when "avis"
|
||||
avis = target_model
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_invite!
|
||||
target_model || (fail ActiveRecord::RecordNotFound.new("Could not find Invite with id `#{target_model_id}`"))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -102,6 +102,13 @@ describe TargetedUserLinksController, type: :controller do
|
|||
expect(response).to redirect_to(root_path)
|
||||
expect(flash[:error]).to match(/dossier n'est plus accessible/)
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue