Class: Hyrax::Transactions::Steps::ApplyCollectionPermissionTemplate

Inherits:
Object
  • Object
show all
Includes:
Dry::Transaction::Operation
Defined in:
lib/hyrax/transactions/steps/apply_collection_permission_template.rb

Overview

A `dry-transcation` step that applies permission templates for a set of collections on a given work.

Since:

  • 3.0.0

Instance Method Summary collapse

Instance Method Details

#call(work, collections: []) ⇒ Dry::Monads::Result

Parameters:

  • work (Hyrax::WorkBehavior)
  • collections (Array<#permision_template>) (defaults to: [])

    a list of collections for which permission templates should be applied

Returns:

  • (Dry::Monads::Result)

Since:

  • 3.0.0


19
20
21
22
23
24
25
26
27
28
# File 'lib/hyrax/transactions/steps/apply_collection_permission_template.rb', line 19

def call(work, collections: [])
  collections.each do |collection|
    template = Hyrax::PermissionTemplate.find_by!(source_id: collection.id)
    Hyrax::PermissionTemplateApplicator.apply(template).to(model: work)
  end

  Success(work)
rescue ActiveRecord::RecordNotFound => err
  Failure(err)
end