Fix the build.

This commit is contained in:
Guo Xiang Tan 2018-04-03 00:44:12 +08:00
parent 2498403bc3
commit 00d879ec63
1 changed files with 8 additions and 10 deletions

View File

@ -1122,30 +1122,28 @@ class User < ActiveRecord::Base
end end
USERNAME_EXISTS_SQL = <<~SQL USERNAME_EXISTS_SQL = <<~SQL
(SELECT 1 FROM users (SELECT users.id AS user_id FROM users
WHERE users.username_lower = :username) WHERE users.username_lower = :username)
UNION ALL UNION ALL
(SELECT 1 FROM groups (SELECT groups.id AS group_id FROM groups
WHERE lower(groups.name) = :username) WHERE lower(groups.name) = :username)
SQL SQL
def username_validator def username_validator
username_format_validator || begin username_format_validator || begin
if will_save_change_to_username?
lower = username.downcase lower = username.downcase
existing = User.exec_sql( existing = User.exec_sql(
USERNAME_EXISTS_SQL, username: lower USERNAME_EXISTS_SQL, username: lower
).values.present? ).to_a.first
if existing if will_save_change_to_username? && existing.present? && existing["user_id"] != self.id
errors.add(:username, I18n.t(:'user.username.unique')) errors.add(:username, I18n.t(:'user.username.unique'))
end end
end end
end end
end
def send_approval_email def send_approval_email
if SiteSetting.must_approve_users if SiteSetting.must_approve_users