Class: Hyrax::VisibilityWriter

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

Overview

Sets ACLs from a visibility string

Examples:

resource = Hyrax::Resource.new
writer   = Hyrax::VisibilityWriter.new(resource: resource)
resource.read_groups # => []

writer.assign_access_for(visibility: 'open')
resource.read_groups # => ["public"]

writer.assign_access_for(visibility: 'authenticated')
resource.read_groups # => ["registered"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource:) ⇒ VisibilityWriter

Returns a new instance of VisibilityWriter.

Parameters:

  • resource (Valkyrie::Resource)


29
30
31
32
# File 'app/services/hyrax/visibility_writer.rb', line 29

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

Instance Attribute Details

#permission_managerHyrax::PermissionManager (readonly)



24
# File 'app/services/hyrax/visibility_writer.rb', line 24

attr_accessor :resource

#resourceValkyrie::Resource

Returns:

  • (Valkyrie::Resource)


24
25
26
# File 'app/services/hyrax/visibility_writer.rb', line 24

def resource
  @resource
end

Instance Method Details

#assign_access_for(visibility:) ⇒ void

This method returns an undefined value.

Parameters:

  • visibility (String)


38
39
40
41
42
43
44
# File 'app/services/hyrax/visibility_writer.rb', line 38

def assign_access_for(visibility:)
  permission_manager.read_groups =
    permission_manager.read_groups.to_a - visibility_map.deletions_for(visibility: visibility)

  permission_manager.read_groups =
    permission_manager.read_groups.to_a + visibility_map.additions_for(visibility: visibility)
end

#visibility_mapObject



46
47
48
# File 'app/services/hyrax/visibility_writer.rb', line 46

def visibility_map
  Hyrax.config.visibility_map
end