Sha256: 3d9ae16b5fa62a9ab202cc6d5feac71834882fd582b36b689f4ccaebe18c3d0f

Contents?: true

Size: 1.43 KB

Versions: 16

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true
module Hyrax
  # updates depositor on file sets and resets permissions if flagged. Used by
  # ChangeDepositorService to background changes to lots of file sets
  class PropagateChangeDepositorJob < ApplicationJob
    # @param work_id [Valkyrie::Id, String] the id of the work
    #             that is receiving a change of depositor
    # @param user [User] the user that will "become" the depositor of
    #             the given work
    # @param 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
    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
        apply_depositor_metadata(f, user)
        Hyrax.persister.save(resource: f)
      end
    end

    def apply_depositor_metadata(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
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
hyrax-5.0.1 app/jobs/hyrax/propagate_change_depositor_job.rb
hyrax-5.0.0 app/jobs/hyrax/propagate_change_depositor_job.rb
hyrax-5.0.0.rc3 app/jobs/hyrax/propagate_change_depositor_job.rb
hyrax-5.0.0.rc2 app/jobs/hyrax/propagate_change_depositor_job.rb
hyrax-5.0.0.rc1 app/jobs/hyrax/propagate_change_depositor_job.rb
hyrax-3.6.0 app/jobs/hyrax/propagate_change_depositor_job.rb
hyrax-4.0.0 app/jobs/hyrax/propagate_change_depositor_job.rb
hyrax-4.0.0.rc3 app/jobs/hyrax/propagate_change_depositor_job.rb
hyrax-4.0.0.rc2 app/jobs/hyrax/propagate_change_depositor_job.rb
hyrax-4.0.0.rc1 app/jobs/hyrax/propagate_change_depositor_job.rb
hyrax-3.5.0 app/jobs/hyrax/propagate_change_depositor_job.rb
hyrax-4.0.0.beta2 app/jobs/hyrax/propagate_change_depositor_job.rb
hyrax-3.4.2 app/jobs/hyrax/propagate_change_depositor_job.rb
hyrax-4.0.0.beta1 app/jobs/hyrax/propagate_change_depositor_job.rb
hyrax-3.4.1 app/jobs/hyrax/propagate_change_depositor_job.rb
hyrax-3.4.0 app/jobs/hyrax/propagate_change_depositor_job.rb