blob: 1383a4b8787d789ef50e7c1bb585e8ea33bd23f0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
|
class Permission < ApplicationRecord
# 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
|