Fix #5143: Allow name changes with same name but changed case.

This commit is contained in:
evazion
2022-11-12 23:03:00 -06:00
parent 22f232f4e9
commit d053dc7356
3 changed files with 21 additions and 6 deletions

View File

@@ -18,9 +18,10 @@ class UserNameValidator < ActiveModel::EachValidator
def validate_each(rec, attr, name)
forbidden_characters = name.delete(ALLOWED_PUNCTUATION).chars.grep(/[[:punct:]]/).uniq
current_user = rec.is_a?(UserNameChangeRequest) ? rec.user : rec
if rec.new_record? && User.find_by_name(name).present?
rec.errors.add(attr, "already exists")
if User.without(current_user).find_by_name(name).present?
rec.errors.add(attr, "already taken")
elsif name.length <= 1
rec.errors.add(attr, "must be more than 1 character long")
elsif name.length >= 25