Class: Wings::CustomQueries::FindAccessControl

Inherits:
Object
  • Object
show all
Defined in:
lib/wings/services/custom_queries/find_access_control.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query_service:) ⇒ FindAccessControl

Returns a new instance of FindAccessControl.


16
17
18
# File 'lib/wings/services/custom_queries/find_access_control.rb', line 16

def initialize(query_service:)
  @query_service = query_service
end

Instance Attribute Details

#query_serviceObject (readonly)

Returns the value of attribute query_service


13
14
15
# File 'lib/wings/services/custom_queries/find_access_control.rb', line 13

def query_service
  @query_service
end

Class Method Details

.queriesObject

Custom query override specific to Wings Use:

Hyrax.custom_queries.find_access_control_for(resource: resource)

9
10
11
# File 'lib/wings/services/custom_queries/find_access_control.rb', line 9

def self.queries
  [:find_access_control_for]
end

Instance Method Details

#find_access_control_for(resource:) ⇒ Valkyrie::Resource

Wings needs special handling for this query, since `Hydra::AccessControl` relationship direction is inverted from the `Hyrax::AccessControl`. We need to query from the `access_control_id` stored on the resource, instead of doing an `inverse_references_by` lookup.

Parameters:

  • resource (Valkyrie::Resource)

    find access control for this resource

Returns:

  • (Valkyrie::Resource)

    the access control resource

Raises:

  • (Valkyrie::Persistence::ObjectNotFoundError)

29
30
31
32
33
34
35
36
37
38
39
# File 'lib/wings/services/custom_queries/find_access_control.rb', line 29

def find_access_control_for(resource:)
  if resource.respond_to?(:access_control_id)
    raise ::Valkyrie::Persistence::ObjectNotFoundError if resource.access_control_id.blank?
    result = query_service.find_by(id: resource.access_control_id)
    result.access_to = resource.id # access_to won't be set in wings if there are no permissions
    result
  else
    raise ::Valkyrie::Persistence::ObjectNotFoundError,
          "#{resource.internal_resource} is not a `Hydra::AccessControls::Permissions` implementer"
  end
end