]> git.openstreetmap.org Git - rails.git/blob - app/models/acl.rb
Keep the behaviour backwards-compatible
[rails.git] / app / models / acl.rb
1 # == Schema Information
2 #
3 # Table name: acls
4 #
5 #  id      :bigint(8)        not null, primary key
6 #  address :inet
7 #  k       :string           not null
8 #  v       :string
9 #  domain  :string
10 #  mx      :string
11 #
12 # Indexes
13 #
14 #  acls_k_idx             (k)
15 #  index_acls_on_address  (address) USING gist
16 #  index_acls_on_domain   (domain)
17 #  index_acls_on_mx       (mx)
18 #
19
20 class Acl < ActiveRecord::Base
21   validates :k, :presence => true
22
23   def self.match(address, options = {})
24     acls = Acl.where("address >>= ?", address)
25
26     acls = acls.or(Acl.where(:domain => options[:domain])) if options[:domain]
27     acls = acls.or(Acl.where(:mx => options[:mx])) if options[:mx]
28
29     acls
30   end
31
32   def self.no_account_creation(address, options = {})
33     match(address, options).where(:k => "no_account_creation").exists?
34   end
35
36   def self.no_note_comment(address, domain = nil)
37     match(address, :domain => domain).where(:k => "no_note_comment").exists?
38   end
39
40   def self.no_trace_download(address, domain = nil)
41     match(address, :domain => domain).where(:k => "no_trace_download").exists?
42   end
43 end