Sha256: 000643503d9c4ceedcd2474763fd317b2480ae5be7d6124b986376236331f0dc

Contents?: true

Size: 1.61 KB

Versions: 8

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true

module Hyrax
  ##
  # Propagates visibility from a valkyrie Work to its FileSets
  class ResourceVisibilityPropagator
    ##
    # @!attribute [rw] source
    #   @return [#visibility]
    attr_accessor :source

    ##
    # @!attribute [r] embargo_manager
    #   @return [Hyrax::EmbargoManager]
    # @!attribute [r] lease_manager
    #   @return [Hyrax::LeaseManager]
    # @!attribute [r] persister
    #   @return [#save]
    # @!attribute [r] queries
    #   @return [Valkyrie::Persistence::CustomQueryContainer]
    attr_reader :embargo_manager, :lease_manager, :persister, :queries

    ##
    # @param source [#visibility] the object to propagate visibility from
    def initialize(source:,
                   embargo_manager: Hyrax::EmbargoManager,
                   lease_manager:   Hyrax::LeaseManager,
                   persister:       Hyrax.persister,
                   queries:         Hyrax.custom_queries)
      @persister       = persister
      @queries         = queries
      self.source      = source
      @embargo_manager = embargo_manager.new(resource: source)
      @lease_manager   = lease_manager.new(resource: source)
    end

    ##
    # @return [void]
    #
    # @raise [RuntimeError] if visibility propagation fails
    def propagate
      queries.find_child_filesets(resource: source).each do |file_set|
        file_set.visibility = source.visibility
        embargo_manager.copy_embargo_to(target: file_set)
        lease_manager.copy_lease_to(target: file_set)

        file_set.permission_manager.acl.save
        persister.save(resource: file_set)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
hyrax-3.3.0 app/services/hyrax/resource_visibility_propagator.rb
hyrax-3.2.0 app/services/hyrax/resource_visibility_propagator.rb
hyrax-3.1.0 app/services/hyrax/resource_visibility_propagator.rb
hyrax-3.0.2 app/services/hyrax/resource_visibility_propagator.rb
hyrax-3.0.1 app/services/hyrax/resource_visibility_propagator.rb
hyrax-3.0.0 app/services/hyrax/resource_visibility_propagator.rb
hyrax-3.0.0.pre.rc4 app/services/hyrax/resource_visibility_propagator.rb
hyrax-3.0.0.pre.rc3 app/services/hyrax/resource_visibility_propagator.rb