Class: InheritPermissionsJob

Inherits:
Hyrax::ApplicationJob show all
Defined in:
app/jobs/inherit_permissions_job.rb

Overview

A job to apply work permissions to all contained files set

Instance Method Summary collapse

Instance Method Details

#perform(work) ⇒ Object

Perform the copy from the work to the contained filesets

Parameters:

  • work

    containing access level and filesets



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/jobs/inherit_permissions_job.rb', line 7

def perform(work)
  work.file_sets.each do |file|
    attribute_map = work.permissions.map(&:to_hash)

    # copy and removed access to the new access with the delete flag
    file.permissions.map(&:to_hash).each do |perm|
      unless attribute_map.include?(perm)
        perm[:_destroy] = true
        attribute_map << perm
      end
    end

    # apply the new and deleted attributes
    file.permissions_attributes = attribute_map
    file.save!
  end
end