summaryrefslogtreecommitdiff
path: root/app/models/permission.rb
blob: a7a30ed721a5aede39d1afc0dae32aecbf46dc2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
class Permission < ActiveRecord::Base
  # Validations
  validates_presence_of   :user_id, :node_id, :granted
  validates_inclusion_of  :granted, :in => [true, false]
  
  # Associations
  belongs_to :user
  belongs_to :node
  
  # Named scopes
  scope :for_node, lambda { |node| where('node_id = ?', (node.is_a?(Node) ? node.id : node)) }
  scope :for_user, lambda { |user| where('user_id = ?', (user.is_a?(User) ? user.id : user)) }
end