discourse/lib/validators/max_username_length_validator.rb
Sam Saffron 30990006a9 DEV: enable frozen string literal on all files
This reduces chances of errors where consumers of strings mutate inputs
and reduces memory usage of the app.

Test suite passes now, but there may be some stuff left, so we will run
a few sites on a branch prior to merging
2019-05-13 09:31:32 +08:00

22 lines
530 B
Ruby

# frozen_string_literal: true
class MaxUsernameLengthValidator
def initialize(opts = {})
@opts = opts
end
def valid_value?(value)
return false if value < SiteSetting.min_username_length
@username = User.where('length(username) > ?', value).pluck(:username).first
@username.blank?
end
def error_message
if @username.blank?
I18n.t("site_settings.errors.max_username_length_range")
else
I18n.t("site_settings.errors.max_username_length_exists", username: @username)
end
end
end