mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 10:52:45 +08:00
FIX: don't suggest a username that's already taken, even if hub finds a match
This commit is contained in:
parent
97cb9e1545
commit
69cc1dd689
|
@ -11,7 +11,12 @@ class UsernameCheckerService
|
|||
check_username_with_hub_server(username, email)
|
||||
end
|
||||
elsif email and SiteSetting.call_discourse_hub?
|
||||
{suggestion: DiscourseHub.nickname_for_email(email)}
|
||||
username_from_hub = DiscourseHub.nickname_for_email(email)
|
||||
if username_from_hub && User.username_available?(username_from_hub)
|
||||
{suggestion: username_from_hub}
|
||||
else
|
||||
{suggestion: nil}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -95,6 +95,14 @@ describe UsernameCheckerService do
|
|||
DiscourseHub.stubs(:nickname_for_email).returns('vincent')
|
||||
result.should == {suggestion: 'vincent'}
|
||||
end
|
||||
|
||||
it 'match found for email, but username is taken' do
|
||||
# This case can happen when you've already signed up on the site,
|
||||
# or enforce_global_nicknames used to be disabled.
|
||||
DiscourseHub.stubs(:nickname_for_email).returns('taken')
|
||||
User.stubs(:username_available?).with('taken').returns(false)
|
||||
result.should == {suggestion: nil}
|
||||
end
|
||||
end
|
||||
|
||||
context 'username is nil' do
|
||||
|
|
Loading…
Reference in New Issue
Block a user