blob: f304538c64df366b6b477f08cd102456fe8152d4 (
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, ->(node) { where('node_id = ?', (node.is_a?(Node) ? node.id : node)) }
scope :for_user, ->(user) { where('user_id = ?', (user.is_a?(User) ? user.id : user)) }
end
|