mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 18:30:26 -06:00
FIX: Check group names when checking username availability
This commit is contained in:
parent
d19d491d65
commit
beed676b04
@ -208,7 +208,8 @@ class User < ActiveRecord::Base
|
||||
def self.username_available?(username, email = nil)
|
||||
lower = username.downcase
|
||||
return false if reserved_username?(lower)
|
||||
return true if !User.exists?(username_lower: lower)
|
||||
return true if User.exec_sql(User::USERNAME_EXISTS_SQL, username: lower).count == 0
|
||||
|
||||
# staged users can use the same username since they will take over the account
|
||||
email.present? && User.joins(:user_emails).exists?(staged: true, username_lower: lower, user_emails: { primary: true, email: email })
|
||||
end
|
||||
|
@ -554,6 +554,11 @@ describe User do
|
||||
user = Fabricate(:user, email: "bar@foo.com")
|
||||
expect(User.username_available?(user.username, user.primary_email.email)).to eq(false)
|
||||
end
|
||||
|
||||
it 'returns false when a username equals an existing group name' do
|
||||
Fabricate(:group, name: 'foo')
|
||||
expect(User.username_available?('Foo')).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.reserved_username?' do
|
||||
|
Loading…
Reference in New Issue
Block a user