diff options
Diffstat (limited to 'app/models/ip_block.rb')
-rw-r--r-- | app/models/ip_block.rb | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/app/models/ip_block.rb b/app/models/ip_block.rb index e1ab59806..31343f0e1 100644 --- a/app/models/ip_block.rb +++ b/app/models/ip_block.rb @@ -16,6 +16,7 @@ class IpBlock < ApplicationRecord CACHE_KEY = 'blocked_ips' include Expireable + include Paginable enum severity: { sign_up_requires_approval: 5000, @@ -24,9 +25,14 @@ class IpBlock < ApplicationRecord } validates :ip, :severity, presence: true + validates :ip, uniqueness: true after_commit :reset_cache + def to_log_human_identifier + "#{ip}/#{ip.prefix}" + end + class << self def blocked?(remote_ip) blocked_ips_map = Rails.cache.fetch(CACHE_KEY) { FastIpMap.new(IpBlock.where(severity: :no_access).pluck(:ip)) } |