Sha256: 8fb09a658f3870fc87093c7aa99d3bbd84e4a58937e504c5ab08d5baae8f4bca

Contents?: true

Size: 943 Bytes

Versions: 2

Compression:

Stored size: 943 Bytes

Contents

# frozen_string_literal: true
module Hyrax
  module Actors
    class LeaseActor
      attr_reader :work

      # @param [Hydra::Works::Work] work
      def initialize(work)
        @work = work
      end

      # Update the visibility of the work to match the correct state of the lease, then clear the lease date, etc.
      # Saves the lease and the work
      def destroy
        case work
        when Valkyrie::Resource
          lease_manager = Hyrax::LeaseManager.new(resource: work)
          return if lease_manager.lease.lease_expiration_date.blank?

          lease_manager.deactivate!
          work.lease = Hyrax.persister.save(resource: lease_manager.lease)
          Hyrax::AccessControlList(work).save
        else
          work.lease_visibility! # If the lease has lapsed, update the current visibility.
          work.deactivate_lease!
          work.lease.save!
          work.save!
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hyrax-5.0.0.rc2 app/actors/hyrax/actors/lease_actor.rb
hyrax-5.0.0.rc1 app/actors/hyrax/actors/lease_actor.rb