Class: Hyrax::Transactions::Steps::ApplyPermissionTemplateOnUpdate

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

Overview

A dry-transaction step that applies a permission template to a work when its admin set has changed during an update.

Removes grants from the old admin set's permission template that are not present in the new template, then applies the new template's grants. Manually added permissions and the depositor's access are preserved.

Since:

  • 5.1.0

Instance Method Summary collapse

Instance Method Details

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

Parameters:

Returns:

  • (Dry::Monads::Result)

Since:

  • 5.1.0



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/hyrax/transactions/steps/apply_permission_template_on_update.rb', line 21

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

  old_template = Hyrax::PermissionTemplate.find_by(source_id: object.previous_admin_set_id)
  new_template = Hyrax::PermissionTemplate.find_by(source_id: object.admin_set_id)

  remove_old_grants(object, old_template, new_template) if old_template

  if new_template
    Hyrax::PermissionTemplateApplicator.apply(new_template).to(model: object)
  else
    Hyrax.logger.warn("At update time, #{object} doesn't have a " \
                      "PermissionTemplate for new AdministrativeSet " \
                      "#{object.admin_set_id}. Continuing without " \
                      "applying permissions.")
  end

  Success(object)
end