Commit 5520516a authored by Lee Tickett's avatar Lee Tickett Committed by Thong Kuah

Check if user is an int before passing to find_by_id

parent a6b7f91b
...@@ -257,7 +257,9 @@ class Member < ApplicationRecord ...@@ -257,7 +257,9 @@ class Member < ApplicationRecord
def retrieve_user(user) def retrieve_user(user)
return user if user.is_a?(User) return user if user.is_a?(User)
User.find_by(id: user) || User.find_by(email: user) || user return User.find_by(id: user) if user.is_a?(Integer)
User.find_by(email: user) || user
end end
def retrieve_member(source, user, existing_members) def retrieve_member(source, user, existing_members)
......
---
title: Fix bug inviting members whose emails start with numbers
merge_request: 27848
author: Lee Tickett
type: fixed
...@@ -342,6 +342,17 @@ describe Member do ...@@ -342,6 +342,17 @@ describe Member do
expect(source.members.invite.pluck(:invite_email)).to include('user@example.com') expect(source.members.invite.pluck(:invite_email)).to include('user@example.com')
end end
end end
context 'when called with an unknown user email starting with a number' do
it 'creates an invited member', :aggregate_failures do
email_starting_with_number = "#{user.id}_email@example.com"
described_class.add_user(source, email_starting_with_number, :maintainer)
expect(source.members.invite.pluck(:invite_email)).to include(email_starting_with_number)
expect(source.users.reload).not_to include(user)
end
end
end end
context 'when current_user can update member' do context 'when current_user can update member' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment