Class: AttachFilesToWorkJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
app/jobs/attach_files_to_work_job.rb

Overview

Converts UploadedFiles into FileSets and attaches them to works.

Instance Method Summary collapse

Instance Method Details

#perform(work, uploaded_files) ⇒ Object

Parameters:

  • the (ActiveFedora::Base)

    work class

  • an (Array<UploadedFile>)

    array of files to attach



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/jobs/attach_files_to_work_job.rb', line 7

def perform(work, uploaded_files)
  uploaded_files.each do |uploaded_file|
    file_set = FileSet.new
    user = User.find_by_user_key(work.depositor)
    actor = CurationConcerns::Actors::FileSetActor.new(file_set, user)
    actor.(work, visibility: work.visibility) do |file|
      file.permissions_attributes = work.permissions.map(&:to_hash)
    end

    attach_content(actor, uploaded_file.file)
    uploaded_file.update(file_set_uri: file_set.uri)
  end
end