Merge pull request #7556 from mfo/fix-targeted-user-link-on-invite-without-user
fix(targeted_user_link): on invite without user
This commit is contained in:
commit
86212a7320
2 changed files with 42 additions and 3 deletions
|
@ -17,7 +17,7 @@ class TargetedUserLink < ApplicationRecord
|
|||
enum target_context: { avis: 'avis', invite: 'invite' }
|
||||
|
||||
def invalid_signed_in_user?(signed_in_user)
|
||||
signed_in_user && signed_in_user != self.user
|
||||
signed_in_user && signed_in_user.email != target_email
|
||||
end
|
||||
|
||||
def target_email
|
||||
|
@ -35,7 +35,8 @@ class TargetedUserLink < ApplicationRecord
|
|||
case target_context
|
||||
when "invite"
|
||||
invite = target_model
|
||||
invite.user&.active? ?
|
||||
user = User.find_by(email: target_email)
|
||||
user&.active? ?
|
||||
url_helper.invite_path(invite) :
|
||||
url_helper.invite_path(invite, params: { email: invite.email })
|
||||
when "avis"
|
||||
|
|
|
@ -55,7 +55,7 @@ describe TargetedUserLinksController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
context 'with invite' do
|
||||
context 'with invite having user' do
|
||||
let(:target_context) { 'invite' }
|
||||
let(:target_model) { create(:invite, user: user) }
|
||||
|
||||
|
@ -91,5 +91,43 @@ describe TargetedUserLinksController, type: :controller do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with invite not having user' do
|
||||
let(:target_context) { 'invite' }
|
||||
let(:user_email) { 'not_yet_registered@a.com' }
|
||||
let(:target_model) { create(:invite, user: nil, email: user_email) }
|
||||
|
||||
context 'connected with expected user' do
|
||||
let(:user) { create(:user, email: user_email, last_sign_in_at: 2.days.ago) }
|
||||
before do
|
||||
sign_in(user)
|
||||
get :show, params: { id: targeted_user_link.id }
|
||||
end
|
||||
it 'works' do
|
||||
expect(response).to redirect_to(invite_path(target_model))
|
||||
end
|
||||
end
|
||||
|
||||
context 'connected as different user' do
|
||||
let(:user) { create(:user, last_sign_in_at: 2.days.ago) }
|
||||
|
||||
before do
|
||||
sign_in(create(:expert).user)
|
||||
get :show, params: { id: targeted_user_link.id }
|
||||
end
|
||||
|
||||
it 'renders error page ' do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when invite user does not exists' do
|
||||
let(:user) { nil }
|
||||
before { get :show, params: { id: targeted_user_link.id } }
|
||||
it 'works' do
|
||||
expect(response).to redirect_to(invite_path(target_model, email: target_model.email))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue