Class: Accessly::Query
Overview
Accessly::Query is the interface that hides the implementation of the data layer. Ask Accessly::Query whether an actor has permission on a record, ask it for a list of permitted records for the record type, and ask it whether an actor has a general permission not related to any certain record or record type.
Instance Method Summary collapse
-
#can?(action_id, object_type, object_id = nil) ⇒ Boolean
Check whether an actor has a given permission.
-
#initialize(actors) ⇒ Query
constructor
Create an instance of Accessly::Query.
-
#list(action_id, namespace) ⇒ ActiveRecord::Relation
Returns an ActiveRecord::Relation of ids in the namespace for which the actor has permission to perform action_id.
Methods inherited from Base
Constructor Details
#initialize(actors) ⇒ Query
Create an instance of Accessly::Query. Lookups are cached in inherited object(s) to prevent redundant calls to the database. Pass in a Hash or ActiveRecord::Base for actors if the actor(s) inherit some permissions from other actors in the system. This may happen when you have a user in one or more groups or organizations with their own access control permissions.
26 27 28 |
# File 'lib/accessly/query.rb', line 26 def initialize(actors) super(actors) end |
Instance Method Details
#can?(action_id, namespace) ⇒ Boolean #can?(action_id, object_type, object_id) ⇒ Boolean
Check whether an actor has a given permission.
81 82 83 84 85 86 87 |
# File 'lib/accessly/query.rb', line 81 def can?(action_id, object_type, object_id = nil) if object_id.nil? permitted_action_query.can?(action_id, object_type) else permitted_action_on_object_query.can?(action_id, object_type, object_id) end end |
#list(action_id, namespace) ⇒ ActiveRecord::Relation
Returns an ActiveRecord::Relation of ids in the namespace for which the actor has permission to perform action_id.
108 109 110 |
# File 'lib/accessly/query.rb', line 108 def list(action_id, namespace) permitted_action_on_object_query.list(action_id, namespace) end |