mirror of https://github.com/mastodon/mastodon
Correct validators so that existing error messages would look correct (#3668)
parent
1a065fb146
commit
cdff1da901
@ -0,0 +1,15 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class UnreservedUsernameValidator < ActiveModel::Validator
|
||||||
|
def validate(account)
|
||||||
|
return if account.username.nil?
|
||||||
|
account.errors.add(:username, I18n.t('accounts.reserved_username')) if reserved_username?(account.username)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def reserved_username?(value)
|
||||||
|
return false unless Setting.reserved_usernames
|
||||||
|
Setting.reserved_usernames.include?(value.downcase)
|
||||||
|
end
|
||||||
|
end
|
@ -1,15 +0,0 @@
|
|||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
class UnreservedValidator < ActiveModel::EachValidator
|
|
||||||
def validate_each(record, attribute, value)
|
|
||||||
return if value.nil?
|
|
||||||
record.errors.add(attribute, I18n.t('accounts.reserved_username')) if reserved_username?(value)
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def reserved_username?(value)
|
|
||||||
return false unless Setting.reserved_usernames
|
|
||||||
Setting.reserved_usernames.include?(value.downcase)
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Reference in New Issue