Class: GraphStarter::QueryAuthorizer
- Inherits:
-
Object
- Object
- GraphStarter::QueryAuthorizer
- Defined in:
- lib/graph_starter/query_authorizer.rb
Class Method Summary collapse
Instance Method Summary collapse
- #authorized_pluck(variable, user) ⇒ Object
- #authorized_query(variables, user) ⇒ Object
-
#initialize(query_object, filter = nil) ⇒ QueryAuthorizer
constructor
Can take: * a Query * a Proxy object * Anything that responds to #query where a
Queryis returned.
Constructor Details
#initialize(query_object, filter = nil) ⇒ QueryAuthorizer
Can take:
* a Query
* a Proxy object
* Anything that responds to #query where a `Query` is returned
7 8 9 10 11 12 |
# File 'lib/graph_starter/query_authorizer.rb', line 7 def initialize(query_object, filter = nil) validate_query_object!(query_object) @query_object = query_object @filter = filter end |
Class Method Details
.queryish?(query_object) ⇒ Boolean
42 43 44 45 46 47 48 49 |
# File 'lib/graph_starter/query_authorizer.rb', line 42 def self.queryish?(query_object) query_object.is_a?(::Neo4j::Core::Query) || # Working around these two classes for new. They should return `true` # for `respond_to(:query)` query_object.is_a?(::Neo4j::ActiveNode::HasN::AssociationProxy) || query_object.is_a?(::Neo4j::ActiveNode::Query::QueryProxy) || query_object.respond_to?(:query) end |
Instance Method Details
#authorized_pluck(variable, user) ⇒ Object
14 15 16 |
# File 'lib/graph_starter/query_authorizer.rb', line 14 def (variable, user) (variable, user).pluck(variable) end |
#authorized_query(variables, user) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/graph_starter/query_authorizer.rb', line 18 def (variables, user) variables = Array(variables) result_query = query.with(*variables) result_query = (result_query, user, variables) # Collapse 2D array of all possible levels into one column of levels result_query .unwind(level_collection: :level_collections) .unwind(level: :level_collection).break .with(:level, *variables).where_not(level: nil) .with('collect(level) AS levels', *variables) .with("CASE WHEN 'write' IN levels THEN 'write' ELSE 'read' END AS level", *variables) end |