mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
Create blocked domains #2564
This commit is contained in:
parent
cd277c25ed
commit
d93d43e75c
13 changed files with 254 additions and 80 deletions
|
@ -1,11 +1,17 @@
|
|||
class DomainNameValidator < ActiveModel::EachValidator
|
||||
# rubocop: disable Metrics/PerceivedComplexity
|
||||
# rubocop: disable Metrics/CyclomaticComplexity
|
||||
def validate_each(record, attribute, value)
|
||||
if !self.class.validate_format(value)
|
||||
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)))
|
||||
end
|
||||
end
|
||||
# rubocop: enable Metrics/PerceivedComplexity
|
||||
# rubocop: enable Metrics/CyclomaticComplexity
|
||||
|
||||
class << self
|
||||
def validate_format(value)
|
||||
|
@ -31,6 +37,11 @@ class DomainNameValidator < ActiveModel::EachValidator
|
|||
# rubocop: enable Style/DoubleNegation
|
||||
end
|
||||
|
||||
def validate_blocked(value)
|
||||
return true unless value
|
||||
BlockedDomain.where("names @> ?::varchar[]", "{#{value}}").count == 0
|
||||
end
|
||||
|
||||
def validate_reservation(value)
|
||||
return true unless value
|
||||
!ReservedDomain.exists?(name: value.mb_chars.downcase.strip)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue