mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
Screened ip address can be edited, deleted, and changed to allow or block.
This commit is contained in:
11
lib/validators/ip_address_format_validator.rb
Normal file
11
lib/validators/ip_address_format_validator.rb
Normal file
@ -0,0 +1,11 @@
|
||||
# Allows unique IP address (10.0.1.20), and IP addresses with a mask (10.0.0.0/8).
|
||||
# Useful when storing in a Postgresql inet column.
|
||||
class IpAddressFormatValidator < ActiveModel::EachValidator
|
||||
|
||||
def validate_each(record, attribute, value)
|
||||
unless record.ip_address.nil? or record.ip_address.split('/').first =~ Resolv::AddressRegex
|
||||
record.errors.add(attribute, :invalid)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Reference in New Issue
Block a user