about summary refs log tree commit diff
path: root/app/validators
diff options
context:
space:
mode:
authorabcang <abcang1015@gmail.com>2020-02-01 23:42:24 +0900
committerGitHub <noreply@github.com>2020-02-01 15:42:24 +0100
commit61a7390b666dc40beda291da426436a9d36f4288 (patch)
tree2ac9ca1ded989119d958e6009dba3dfb66905dc7 /app/validators
parent37dc12dd5387935defcf625125a441dd161cc571 (diff)
Search account domain in lowercase (#13016)
* Search account domain in lowercase

* fix rubocop error

* fix spec/models/account_spec.rb
Diffstat (limited to 'app/validators')
-rw-r--r--app/validators/unique_username_validator.rb3
1 files changed, 2 insertions, 1 deletions
diff --git a/app/validators/unique_username_validator.rb b/app/validators/unique_username_validator.rb
index 4e24e3f5f..f87eb06ba 100644
--- a/app/validators/unique_username_validator.rb
+++ b/app/validators/unique_username_validator.rb
@@ -7,8 +7,9 @@ class UniqueUsernameValidator < ActiveModel::Validator
     return if account.username.nil?
 
     normalized_username = account.username.downcase
+    normalized_domain = account.domain&.downcase
 
-    scope = Account.where(domain: nil).where('lower(username) = ?', normalized_username)
+    scope = Account.where(Account.arel_table[:username].lower.eq normalized_username).where(Account.arel_table[:domain].lower.eq normalized_domain)
     scope = scope.where.not(id: account.id) if account.persisted?
 
     account.errors.add(:username, :taken) if scope.exists?