Class: Croods::Policy::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/croods/policy/scope.rb

Instance Method Summary collapse

Constructor Details

#initialize(tenant:, user:, scope:) ⇒ Scope

Returns a new instance of Scope.



6
7
8
9
10
# File 'lib/croods/policy/scope.rb', line 6

def initialize(tenant:, user:, scope:)
  self.user  = user
  self.scope = scope
  self.tenant = user&.tenant || tenant
end

Instance Method Details

#resolveObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/croods/policy/scope.rb', line 12

def resolve
  self.scope = tenant_scope(scope) if Croods.multi_tenancy?

  return scope if action.public

  return scope if super?

  return owner_scope(scope) if owner?

  scope
end