mirror of
https://github.com/internetee/registry.git
synced 2025-07-21 02:05:57 +02:00
Restructure white ip interfaces #2713
This commit is contained in:
parent
cc32312328
commit
c6073c7e87
9 changed files with 32 additions and 23 deletions
|
@ -17,19 +17,17 @@ class WhiteIp < ActiveRecord::Base
|
|||
REGISTRAR = 'registrar'
|
||||
INTERFACES = [API, REGISTRAR]
|
||||
|
||||
scope :api, -> { where(interface: API) }
|
||||
scope :registrar, -> { where(interface: REGISTRAR) }
|
||||
scope :api, -> { where("interfaces @> ?::varchar[]", "{#{API}}") }
|
||||
scope :registrar, -> { where("interfaces @> ?::varchar[]", "{#{REGISTRAR}}") }
|
||||
|
||||
def interfaces=(interfaces)
|
||||
super(interfaces.reject(&:blank?))
|
||||
end
|
||||
|
||||
class << self
|
||||
def registrar_ip_white?(ip)
|
||||
return true unless Setting.registrar_ip_whitelist_enabled
|
||||
|
||||
at = WhiteIp.arel_table
|
||||
WhiteIp.where(
|
||||
at[:interface].eq(REGISTRAR).and(
|
||||
at[:ipv4].eq(ip)
|
||||
)
|
||||
).any?
|
||||
WhiteIp.where(ipv4: ip).registrar.any?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue