Class: Hyrax::CustomQueries::FindModelsByAccess
- Inherits:
-
Object
- Object
- Hyrax::CustomQueries::FindModelsByAccess
- Defined in:
- app/services/hyrax/custom_queries/find_models_by_access.rb
Overview
Instance Attribute Summary collapse
-
#query_service ⇒ Object
readonly
Returns the value of attribute query_service.
Class Method Summary collapse
Instance Method Summary collapse
- #find_by_access_query ⇒ Object
- #find_models_by_access(mode:, models: nil, agent:, group: nil) ⇒ Object
- #find_models_by_access_query ⇒ Object
-
#initialize(query_service:) ⇒ FindModelsByAccess
constructor
A new instance of FindModelsByAccess.
Constructor Details
#initialize(query_service:) ⇒ FindModelsByAccess
Returns a new instance of FindModelsByAccess.
11 12 13 |
# File 'app/services/hyrax/custom_queries/find_models_by_access.rb', line 11 def initialize(query_service:) @query_service = query_service end |
Instance Attribute Details
#query_service ⇒ Object (readonly)
Returns the value of attribute query_service.
15 16 17 |
# File 'app/services/hyrax/custom_queries/find_models_by_access.rb', line 15 def query_service @query_service end |
Class Method Details
.queries ⇒ Object
7 8 9 |
# File 'app/services/hyrax/custom_queries/find_models_by_access.rb', line 7 def self.queries [:find_models_by_access] end |
Instance Method Details
#find_by_access_query ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'app/services/hyrax/custom_queries/find_models_by_access.rb', line 48 def find_by_access_query <<-SQL SELECT * FROM orm_resources WHERE id IN ( SELECT uuid(metadata::json#>'{access_to,0}'->>'id') FROM orm_resources WHERE metadata @> ? ); SQL end |
#find_models_by_access(mode:, models: nil, agent:, group: nil) ⇒ Object
Note:
this is an unoptimized default implementation of this custom query. it’s Hyrax’s policy to provide such implementations of custom queries in use for cross-compatibility of Valkyrie query services. it’s advisable to provide an optimized query for the specific adapter.
28 29 30 31 32 33 34 35 36 |
# File 'app/services/hyrax/custom_queries/find_models_by_access.rb', line 28 def find_models_by_access(mode:, models: nil, agent:, group: nil) agent = "group/#{agent}" if group.present? internal_array = "{\"permissions\": [{\"mode\": \"#{mode}\", \"agent\": \"#{agent}\"}]}" if models.present? query_service.run_query(find_models_by_access_query, internal_array, models) else query_service.run_query(find_by_access_query, internal_array) end end |
#find_models_by_access_query ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'app/services/hyrax/custom_queries/find_models_by_access.rb', line 38 def find_models_by_access_query <<-SQL SELECT * FROM orm_resources WHERE id IN ( SELECT uuid(metadata::json#>'{access_to,0}'->>'id') FROM orm_resources WHERE metadata @> ? ) AND internal_resource IN (?); SQL end |