Check reserved domain on create #2565

This commit is contained in:
Martin Lensment 2015-07-08 16:04:56 +03:00
parent 8ef8147b06
commit 647d074b8b
5 changed files with 35 additions and 4 deletions

View file

@ -6,8 +6,8 @@ class DomainNameValidator < ActiveModel::EachValidator
record.errors[attribute] << (options[:message] || record.errors.generate_message(attribute, :invalid))
elsif !self.class.validate_blocked(value)
record.errors.add(attribute, (options[:message] || record.errors.generate_message(attribute, :blocked)))
elsif !self.class.validate_reservation(value)
record.errors.add(attribute, (options[:message] || record.errors.generate_message(attribute, :reserved)))
# elsif !self.class.validate_reservation(value)
# record.errors.add(attribute, (options[:message] || record.errors.generate_message(attribute, :reserved)))
end
end
# rubocop: enable Metrics/PerceivedComplexity
@ -42,8 +42,9 @@ class DomainNameValidator < ActiveModel::EachValidator
BlockedDomain.where("names @> ?::varchar[]", "{#{value}}").count == 0
end
def validate_reservation(value)
def validate_reservation(record, value)
return true unless value
return true if record.reserved_pw == record.auth_info
!ReservedDomain.exists?(name: value.mb_chars.downcase.strip)
end
end