]> git.openstreetmap.org Git - rails.git/blob - app/models/acl.rb
Merge remote-tracking branch 'upstream/pull/2239'
[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 #
11 # Indexes
12 #
13 #  acls_k_idx             (k)
14 #  index_acls_on_address  (address) USING gist
15 #  index_acls_on_domain   (domain)
16 #
17
18 class Acl < ActiveRecord::Base
19   validates :k, :presence => true
20
21   def self.match(address, domain = nil)
22     if domain
23       Acl.where("address >>= ? OR domain = ?", address, domain)
24     else
25       Acl.where("address >>= ?", address)
26     end
27   end
28
29   def self.no_account_creation(address, domain = nil)
30     match(address, domain).where(:k => "no_account_creation").exists?
31   end
32
33   def self.no_note_comment(address, domain = nil)
34     match(address, domain).where(:k => "no_note_comment").exists?
35   end
36
37   def self.no_trace_download(address, domain = nil)
38     match(address, domain).where(:k => "no_trace_download").exists?
39   end
40 end