Class: ApplicationPolicy::Scope
- Inherits:
-
Object
- Object
- ApplicationPolicy::Scope
- Defined in:
- app/policies/application_policy.rb
Direct Known Subclasses
OwnerScope, UpdateScope, Federails::ActorPolicy::Scope, Federails::FollowingPolicy::Scope, Federails::Moderation::DomainBlockPolicy::Scope, Federails::Moderation::ReportPolicy::Scope, ModelFilePolicy::Scope, ModelPolicy::Scope, ProblemPolicy::Scope
Instance Method Summary collapse
-
#initialize(user, scope) ⇒ Scope
constructor
A new instance of Scope.
- #resolve ⇒ Object
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 |