Add details
to error response for POST /api/v1/accounts
in REST API (#15803)
This commit is contained in:
parent
b4cb8c3c83
commit
9aa37b32c3
12 changed files with 72 additions and 23 deletions
|
@ -2,11 +2,11 @@
|
|||
|
||||
class BlacklistedEmailValidator < ActiveModel::Validator
|
||||
def validate(user)
|
||||
return if user.valid_invitation?
|
||||
return if user.valid_invitation? || user.email.blank?
|
||||
|
||||
@email = user.email
|
||||
|
||||
user.errors.add(:email, I18n.t('users.blocked_email_provider')) if blocked_email?
|
||||
user.errors.add(:email, :blocked) if blocked_email?
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -4,16 +4,19 @@ require 'resolv'
|
|||
|
||||
class EmailMxValidator < ActiveModel::Validator
|
||||
def validate(user)
|
||||
return if user.email.blank?
|
||||
|
||||
domain = get_domain(user.email)
|
||||
|
||||
if domain.nil?
|
||||
user.errors.add(:email, I18n.t('users.invalid_email'))
|
||||
if domain.blank?
|
||||
user.errors.add(:email, :invalid)
|
||||
else
|
||||
ips, hostnames = resolve_mx(domain)
|
||||
|
||||
if ips.empty?
|
||||
user.errors.add(:email, I18n.t('users.invalid_email_mx'))
|
||||
user.errors.add(:email, :unreachable)
|
||||
elsif on_blacklist?(hostnames + ips)
|
||||
user.errors.add(:email, I18n.t('users.blocked_email_provider'))
|
||||
user.errors.add(:email, :blocked)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
class NoteLengthValidator < ActiveModel::EachValidator
|
||||
def validate_each(record, attribute, value)
|
||||
record.errors.add(attribute, I18n.t('statuses.over_character_limit', max: options[:maximum])) if too_long?(value)
|
||||
record.errors.add(attribute, :too_long, message: I18n.t('statuses.over_character_limit', max: options[:maximum]), count: options[:maximum]) if too_long?(value)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
class UniqueUsernameValidator < ActiveModel::Validator
|
||||
def validate(account)
|
||||
return if account.username.nil?
|
||||
return if account.username.blank?
|
||||
|
||||
normalized_username = account.username.downcase
|
||||
normalized_domain = account.domain&.downcase
|
||||
|
|
|
@ -3,9 +3,10 @@
|
|||
class UnreservedUsernameValidator < ActiveModel::Validator
|
||||
def validate(account)
|
||||
@username = account.username
|
||||
return if @username.nil?
|
||||
|
||||
account.errors.add(:username, I18n.t('accounts.reserved_username')) if reserved_username?
|
||||
return if @username.blank?
|
||||
|
||||
account.errors.add(:username, :reserved) if reserved_username?
|
||||
end
|
||||
|
||||
private
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue