Class: Hyrax::Transactions::Steps::ApplyWorkflowOnAdminSetChange

Inherits:
Object
  • Object
show all
Defined in:
lib/hyrax/transactions/steps/apply_workflow_on_admin_set_change.rb

Overview

A dry-transaction step that moves a work's Sipity::Entity to the new admin set's active workflow when the admin set has changed during an update and both the old and new admin sets use workflow management.

The entity's workflow_state is preserved by matching on state name: the new workflow's state with the same name is used when one exists, and the new workflow's initial state is used as a fallback (with a warning) when it does not.

The depositor's existing EntitySpecificResponsibility is re-created against the new workflow's depositing role so it is not orphaned to a WorkflowRole from the prior workflow.

No-ops when:

  • the admin set has not changed,
  • the new admin set has no active workflow (the entity is left in place, pointing at the prior workflow), or
  • the work has no Sipity::Entity yet (the prior admin set was not workflow-managed).

Since:

  • 2.4.0

Instance Method Summary collapse

Instance Method Details

#call(object) ⇒ Dry::Monads::Result

Parameters:

Returns:

  • (Dry::Monads::Result)

Since:

  • 2.4.0



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/hyrax/transactions/steps/apply_workflow_on_admin_set_change.rb', line 32

def call(object)
  return Success(object) unless object.respond_to?(:previous_admin_set_id)

  entity = Sipity::Entity.find_by(proxy_for_global_id: Hyrax::GlobalID(object).to_s)
  return Success(object) if entity.nil?

  new_workflow = active_workflow_for(object.admin_set_id)
  return Success(object) if new_workflow.nil?

  move_entity_to_workflow(entity: entity, new_workflow: new_workflow, object: object)
  reassign_depositor_responsibility(entity: entity, new_workflow: new_workflow, object: object)

  Success(object)
end