Class: Accessly::PermittedActions::OnObjectQuery
- Defined in:
- lib/accessly/permitted_actions/on_object_query.rb
Instance Method Summary collapse
-
#can?(action_id, object_type, object_id) ⇒ Boolean
Ask whether the actor has permission to perform action_id on a given record.
-
#initialize(actors, segment_id) ⇒ OnObjectQuery
constructor
A new instance of OnObjectQuery.
-
#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.
Constructor Details
#initialize(actors, segment_id) ⇒ OnObjectQuery
Returns a new instance of OnObjectQuery.
5 6 7 |
# File 'lib/accessly/permitted_actions/on_object_query.rb', line 5 def initialize(actors, segment_id) super(actors, segment_id) end |
Instance Method Details
#can?(action_id, object_type, object_id) ⇒ Boolean
Ask whether the actor has permission to perform action_id on a given record.
Lookups are cached in the object to prevent redundant database calls.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/accessly/permitted_actions/on_object_query.rb', line 24 def can?(action_id, object_type, object_id) find_or_set_value(action_id, object_type, object_id) do Accessly::QueryBuilder.with_actors(Accessly::PermittedActionOnObject, @actors) .where( segment_id: @segment_id, action: action_id, object_type: String(object_type), object_id: object_id ).exists? 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.
55 56 57 58 59 60 61 62 |
# File 'lib/accessly/permitted_actions/on_object_query.rb', line 55 def list(action_id, namespace) Accessly::QueryBuilder.with_actors(Accessly::PermittedActionOnObject, @actors) .where( segment_id: @segment_id, action: Integer(action_id), object_type: String(namespace), ).select(:object_id) end |