From 1586886bf9d0a544c0a1e4f54602f4829fb1019f Mon Sep 17 00:00:00 2001 From: Kane York Date: Tue, 25 Aug 2015 13:33:50 -0700 Subject: [PATCH] FIX: Consider reserved usernames as not 'available' https://meta.discourse.org/t/reserved-usernames-ignored-by-invites/32490 --- app/models/user.rb | 2 +- spec/components/user_name_suggester_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 0edd01a97..19a728bf6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/spec/components/user_name_suggester_spec.rb b/spec/components/user_name_suggester_spec.rb index b16bfee4b..8f63ba1b2 100644 --- a/spec/components/user_name_suggester_spec.rb +++ b/spec/components/user_name_suggester_spec.rb @@ -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