Class: ApplicationPolicy::Scope

Inherits:
Object
  • Object
show all
Defined in:
app/policies/application_policy.rb

Instance Method Summary collapse

Constructor Details

#initialize(user, scope) ⇒ Scope

Returns a new instance of Scope.



64
65
66
67
# File 'app/policies/application_policy.rb', line 64

def initialize(user, scope)
  @user = user
  @scope = scope
end

Instance Method Details

#resolve ⇒ Object



69
70
71
72
73
74
75
76
# File 'app/policies/application_policy.rb', line 69

def resolve
  return scope if user&.is_moderator? || !scope.respond_to?(:granted_to)

  result = scope.granted_to(STANDARD_VIEW_PERMISSIONS, [user, nil])
  result = result.or(scope.granted_to(STANDARD_VIEW_PERMISSIONS, user.roles)) if user
  result = result.or(scope.granted_to(STANDARD_VIEW_PERMISSIONS, user.groups)) if user
  result
end