Added validation for one only IP

This commit is contained in:
Sergei Tsoganov 2023-05-30 14:42:56 +03:00
parent bf3d971d7c
commit 18cd6f5046
2 changed files with 8 additions and 0 deletions

View file

@ -5,6 +5,7 @@ class WhiteIp < ApplicationRecord
validate :valid_ipv4?
validate :valid_ipv6?
validate :validate_ipv4_and_ipv6
validate :validate_only_one_ip
before_save :normalize_blank_values
def normalize_blank_values
@ -17,6 +18,12 @@ class WhiteIp < ApplicationRecord
errors.add(:base, I18n.t(:ipv4_or_ipv6_must_be_present))
end
def validate_only_one_ip
return unless ipv4.present? && ipv6.present?
errors.add(:base, I18n.t(:ip_must_be_one))
end
def valid_ipv4?
return if ipv4.blank?

View file

@ -545,6 +545,7 @@ en:
upload_crt: 'Upload CRT'
crt_or_csr_must_be_present: 'CRT or CSR must be present'
ipv4_or_ipv6_must_be_present: 'IPv4 or IPv6 must be present'
ip_must_be_one: 'Please enter only one IP address'
white_ip: 'White IP'
edit_white_ip: 'Edit white IP'
confirm_domain_delete: 'Confirm domain delete'