FIX: Don't try to rename group when username is taken

FIX: Always rename groups with the default locale instead of using the user's locale
This commit is contained in:
Gerhard Schlager
2019-02-19 22:31:03 +01:00
parent dbcf05d62c
commit 5d75bd4831
3 changed files with 24 additions and 26 deletions

View File

@@ -220,7 +220,7 @@ class User < ActiveRecord::Base
def self.username_available?(username, email = nil, allow_reserved_username: false)
lower = username.downcase
return false if !allow_reserved_username && reserved_username?(lower)
return true if DB.exec(User::USERNAME_EXISTS_SQL, username: lower) == 0
return true if !username_exists?(lower)
# 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 })
@@ -1271,6 +1271,10 @@ class User < ActiveRecord::Base
WHERE lower(groups.name) = :username)
SQL
def self.username_exists?(username_lower)
DB.exec(User::USERNAME_EXISTS_SQL, username: username_lower) > 0
end
def username_validator
username_format_validator || begin
lower = username.downcase