Sha256: 87cf48b81e381c8b63b7e908b5d188b11a4295d10b151cab3d88dfe5745c1359

Contents?: true

Size: 979 Bytes

Versions: 46

Compression:

Stored size: 979 Bytes

Contents

# Responsible for copying the following attributes from the work to each file in the file_sets
#
# * visibility
# * lease
# * embargo
class VisibilityCopyJob < Hyrax::ApplicationJob
  # @api public
  # @param [#file_sets, #visibility, #lease, #embargo] work - a Work model
  def perform(work)
    work.file_sets.each do |file|
      file.visibility = work.visibility # visibility must come first, because it can clear an embargo/lease
      copy_visibility_modifier(work: work, file: file, modifier: :lease)
      copy_visibility_modifier(work: work, file: file, modifier: :embargo)
      file.save!
    end
  end

  private

    def copy_visibility_modifier(work:, file:, modifier:)
      work_modifier = work.public_send(modifier)
      return unless work_modifier
      file.public_send("build_#{modifier}") unless file.public_send(modifier)
      file.public_send(modifier).attributes = work_modifier.attributes.except('id')
      file.public_send(modifier).save
    end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
hyrax-2.9.6 app/jobs/visibility_copy_job.rb
hyrax-2.9.5 app/jobs/visibility_copy_job.rb
hyrax-2.9.4 app/jobs/visibility_copy_job.rb
hyrax-2.9.3 app/jobs/visibility_copy_job.rb
hyrax-2.9.2 app/jobs/visibility_copy_job.rb
hyrax-2.9.1 app/jobs/visibility_copy_job.rb
hyrax-2.9.0 app/jobs/visibility_copy_job.rb
hyrax-2.8.0 app/jobs/visibility_copy_job.rb
hyrax-2.7.2 app/jobs/visibility_copy_job.rb
hyrax-2.7.1 app/jobs/visibility_copy_job.rb
hyrax-2.7.0 app/jobs/visibility_copy_job.rb
hyrax-2.6.0 app/jobs/visibility_copy_job.rb
hyrax-2.5.1 app/jobs/visibility_copy_job.rb
hyrax-2.5.0 app/jobs/visibility_copy_job.rb
hyrax-3.0.0.pre.beta2 app/jobs/visibility_copy_job.rb
hyrax-2.4.1 app/jobs/visibility_copy_job.rb
hyrax-3.0.0.pre.beta1 app/jobs/visibility_copy_job.rb
hyrax-2.4.0 app/jobs/visibility_copy_job.rb
hyrax-2.3.3 app/jobs/visibility_copy_job.rb
hyrax-2.3.2 app/jobs/visibility_copy_job.rb