Class: Hyrax::VisibilityReader

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/visibility_reader.rb

Overview

Translates a set of ACLs into a visibility string.

Examples:

resource = Hyrax::Resource.new
reader   = Hyrax::VisibilityReader.new(resource: resource)
reader.read # => "restricted"

resource.read_groups = ["public"]
reader.read # => "open"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource:) ⇒ VisibilityReader

Returns a new instance of VisibilityReader.

Parameters:

  • resource (Valkyrie::Resource::AccessControls)

26
27
28
29
# File 'app/services/hyrax/visibility_reader.rb', line 26

def initialize(resource:)
  self.resource = resource
  @permission_manager = resource.permission_manager
end

Instance Attribute Details

#permission_managerObject (readonly)

Returns the value of attribute permission_manager.


21
22
23
# File 'app/services/hyrax/visibility_reader.rb', line 21

def permission_manager
  @permission_manager
end

#resourceValkyrie::Resource

Returns:

  • (Valkyrie::Resource)

21
# File 'app/services/hyrax/visibility_reader.rb', line 21

attr_reader   :permission_manager

Instance Method Details

#readString

Returns:

  • (String)

33
34
35
36
37
38
39
40
41
# File 'app/services/hyrax/visibility_reader.rb', line 33

def read
  if permission_manager.read_groups.include? Hydra::AccessControls::AccessRight::PERMISSION_TEXT_VALUE_PUBLIC
    visibility_map.visibility_for(group: Hydra::AccessControls::AccessRight::PERMISSION_TEXT_VALUE_PUBLIC)
  elsif permission_manager.read_groups.include? Hydra::AccessControls::AccessRight::PERMISSION_TEXT_VALUE_AUTHENTICATED
    visibility_map.visibility_for(group: Hydra::AccessControls::AccessRight::PERMISSION_TEXT_VALUE_AUTHENTICATED)
  else
    visibility_map.visibility_for(group: :PRIVATE)
  end
end

#visibility_mapObject


43
44
45
# File 'app/services/hyrax/visibility_reader.rb', line 43

def visibility_map
  Hyrax::VisibilityMap.instance
end