Add glue record requirement validation

#661
This commit is contained in:
Artur Beljajev 2018-02-22 08:57:20 +02:00
parent b0ef967ff8
commit 1b22e17a94
3 changed files with 46 additions and 0 deletions

View file

@ -8,6 +8,7 @@ class Nameserver < ActiveRecord::Base
validates :hostname, presence: true, format: { with: /\A(([a-zA-Z0-9]|[a-zA-ZäöüõšžÄÖÜÕŠŽ0-9][a-zA-ZäöüõšžÄÖÜÕŠŽ0-9\-]*[a-zA-ZäöüõšžÄÖÜÕŠŽ0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])\z/ }
validate :val_ipv4
validate :val_ipv6
validate :require_ip, if: :glue_record_required?
# rubocop: enable Metrics/LineLength
before_validation :normalize_attributes
@ -86,4 +87,15 @@ class Nameserver < ActiveRecord::Base
pluck(:hostname)
end
end
private
def require_ip
errors.add(:base, :ip_required) if ipv4.blank? && ipv6.blank?
end
def glue_record_required?
return unless hostname? && domain
hostname.end_with?(domain.name)
end
end