]> git.openstreetmap.org Git - rails.git/blob - app/models/acl.rb
Update to released version 0.4.0 of gd2-ffij
[rails.git] / app / models / acl.rb
1 # == Schema Information
2 #
3 # Table name: acls
4 #
5 #  id      :integer          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 #
15
16 class Acl < ActiveRecord::Base
17   validates :k, :presence => true
18
19   def self.match(address, domain = nil)
20     if domain
21       Acl.where("address >>= ? OR domain = ?", address, domain)
22     else
23       Acl.where("address >>= ?", address)
24     end
25   end
26
27   def self.no_account_creation(address, domain = nil)
28     match(address, domain).where(:k => "no_account_creation").exists?
29   end
30
31   def self.no_note_comment(address, domain = nil)
32     match(address, domain).where(:k => "no_note_comment").exists?
33   end
34
35   def self.no_trace_download(address, domain = nil)
36     match(address, domain).where(:k => "no_trace_download").exists?
37   end
38 end