1 # frozen_string_literal: true
3 # == Schema Information
7 # id :bigint not null, primary key
17 # index_acls_on_address (address inet_ops) USING gist
18 # index_acls_on_domain (domain)
19 # index_acls_on_mx (mx)
22 class Acl < ApplicationRecord
23 validates :k, :presence => true
24 validates :address, :inet => true
26 def self.match(address, options = {})
27 acls = Acl.where("address >>= ?", address)
30 labels = options[:domain].split(".")
33 acls = acls.or(Acl.where(:domain => labels.join(".")))
38 acls = acls.or(Acl.where(:mx => options[:mx])) if options[:mx]
43 def self.no_account_creation?(address, options = {})
44 match(address, options).exists?(:k => "no_account_creation")
47 def self.allow_account_creation?(address, options = {})
48 match(address, options).exists?(:k => "allow_account_creation")
51 def self.no_note_comment?(address, domain = nil)
52 match(address, :domain => domain).exists?(:k => "no_note_comment")
55 def self.no_trace_download?(address, domain = nil)
56 match(address, :domain => domain).exists?(:k => "no_trace_download")