Class: Hyrax::ChangeDepositorService

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/change_depositor_service.rb

Class Method Summary collapse

Class Method Details

.call(work, user, reset) ⇒ Object

Set the given ‘user` as the depositor of the given `work`; If `reset` is true, first remove all previous permissions.

Used to transfer a an existing work, and to set depositor / proxy_depositor on a work newly deposited on_behalf_of another user

Parameters:

  • work (ActiveFedora::Base, Valkyrie::Resource)

    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

Returns:

  • work, updated if necessary



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/services/hyrax/change_depositor_service.rb', line 20

def self.call(work, user, reset)
  # user_key is nil when there was no `on_behalf_of` in the form
  return work unless user&.user_key
  # Don't transfer to self
  return work if user.user_key == work.depositor

  work = case work
         when ActiveFedora::Base
           call_af(work, user, reset)
         when Valkyrie::Resource
           call_valkyrie(work, user, reset)
         end
  ChangeDepositorEventJob.perform_later(work)
  work
end