Merge pull request #3695 from riking/patch-10

FIX: Consider reserved usernames as not 'available'
This commit is contained in:
Robin Ward 2015-08-26 10:51:50 -04:00
commit f9717da28f
2 changed files with 7 additions and 1 deletions

View file

@ -149,7 +149,7 @@ class User < ActiveRecord::Base
def self.username_available?(username)
lower = username.downcase
User.where(username_lower: lower).blank?
User.where(username_lower: lower).blank? && !SiteSetting.reserved_usernames.split("|").include?(username)
end
def effective_locale

View file

@ -49,6 +49,12 @@ describe UserNameSuggester do
expect(UserNameSuggester.suggest("myreallylongnam")).to eq('myreallylongna1')
end
it "doesn't suggest reserved usernames" do
SiteSetting.reserved_usernames = 'admin|steve|steve1'
expect(UserNameSuggester.suggest("admin@hissite.com")).to eq('admin1')
expect(UserNameSuggester.suggest("steve")).to eq('steve2')
end
it "removes leading character if it is not alphanumeric" do
expect(UserNameSuggester.suggest("_myname")).to eq('myname')
end