Class: Hyrax::PropagateChangeDepositorJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/hyrax/propagate_change_depositor_job.rb

Overview

updates depositor on file sets and resets permissions if flagged. Used by ChangeDepositorService to background changes to lots of file sets

Instance Method Summary collapse

Instance Method Details

#apply_depositor_metadata(resource, depositor) ⇒ Object



26
27
28
29
30
# File 'app/jobs/hyrax/propagate_change_depositor_job.rb', line 26

def (resource, depositor)
  depositor_id = depositor.respond_to?(:user_key) ? depositor.user_key : depositor
  resource.depositor = depositor_id if resource.respond_to? :depositor=
  Hyrax::AccessControlList.new(resource: resource).grant(:edit).to(::User.find_by_user_key(depositor_id)).save
end

#perform(work_id, user, reset) ⇒ Object

Parameters:

  • work_id (Valkyrie::Id, String)

    the id of the work that is receiving a change of depositor

  • user (User)

    the user that will “become” the depositor of the given work

  • reset (TrueClass, FalseClass)

    when true, first clear permissions for the given work and contained file sets; regardless of true/false make the given user the depositor of the given work



14
15
16
17
18
19
20
21
22
23
24
# File 'app/jobs/hyrax/propagate_change_depositor_job.rb', line 14

def perform(work_id, user, reset)
  work = Hyrax.query_service.find_by(id: work_id)
  Hyrax.custom_queries.find_child_file_sets(resource: work).each do |f|
    if reset
      f.permission_manager.acl.permissions = []
      f.permission_manager.acl.save
    end
    (f, user)
    Hyrax.persister.save(resource: f)
  end
end