Class: GraphStarter::QueryAuthorizer
- Inherits:
-
Object
- Object
- GraphStarter::QueryAuthorizer
- Defined in:
- lib/graph_starter/query_authorizer.rb
Instance Method Summary collapse
- #authorized_pluck(variable, user) ⇒ Object
- #authorized_query(variables, user) ⇒ Object
-
#initialize(query_object) ⇒ QueryAuthorizer
constructor
Can take: * a Query * a Proxy object * Anything that responds to #query where a ‘Query` is returned.
Constructor Details
#initialize(query_object) ⇒ QueryAuthorizer
Can take:
* a Query
* a Proxy object
* Anything that responds to #query where a `Query` is returned
7 8 9 10 11 |
# File 'lib/graph_starter/query_authorizer.rb', line 7 def initialize(query_object) validate_query_object!(query_object) @query_object = query_object end |
Instance Method Details
#authorized_pluck(variable, user) ⇒ Object
13 14 15 |
# File 'lib/graph_starter/query_authorizer.rb', line 13 def (variable, user) (variable, user).pluck(variable) end |
#authorized_query(variables, user) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/graph_starter/query_authorizer.rb', line 17 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 |