Class: Vert::Authorization::DynamicPolicy::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/vert/authorization/dynamic_policy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, scope, context = {}) ⇒ Scope

Returns a new instance of Scope.



69
70
71
72
73
# File 'lib/vert/authorization/dynamic_policy.rb', line 69

def initialize(user, scope, context = {})
  @user = user
  @scope = scope
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



67
68
69
# File 'lib/vert/authorization/dynamic_policy.rb', line 67

def context
  @context
end

#scopeObject (readonly)

Returns the value of attribute scope.



67
68
69
# File 'lib/vert/authorization/dynamic_policy.rb', line 67

def scope
  @scope
end

#userObject (readonly)

Returns the value of attribute user.



67
68
69
# File 'lib/vert/authorization/dynamic_policy.rb', line 67

def user
  @user
end

Instance Method Details

#resolveObject



75
76
77
78
79
80
81
# File 'lib/vert/authorization/dynamic_policy.rb', line 75

def resolve
  if PermissionResolver.has_permission?(user, "#{resource_name}.list", context)
    own_records_only? ? scope.where(created_by: user.id) : scope.all
  else
    scope.none
  end
end