FIX: Check for group name availability should skip reserved usernames.

This commit is contained in:
Guo Xiang Tan
2018-08-01 11:08:45 +08:00
parent 129268ddc6
commit 919e8db686
9 changed files with 75 additions and 5 deletions

View File

@@ -1,4 +1,7 @@
class UsernameCheckerService
def initialize(allow_reserved_username: false)
@allow_reserved_username = allow_reserved_username
end
def check_username(username, email)
if username && username.length > 0
@@ -12,7 +15,13 @@ class UsernameCheckerService
end
def check_username_availability(username, email)
if User.username_available?(username, email)
available = User.username_available?(
username,
email,
allow_reserved_username: @allow_reserved_username
)
if available
{ available: true, is_developer: is_developer?(email) }
else
{ available: false, suggestion: UserNameSuggester.suggest(username) }