Sha256: cd772c8bacea41edb49e7365bbe87d0790a7d779f906147c64818d393c21e208

Contents?: true

Size: 1.63 KB

Versions: 16

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true
module Hyrax
  module LeaseHelper
    def assets_with_expired_leases
      @assets_with_expired_leases ||= LeaseService.assets_with_expired_leases
    end

    def assets_under_lease
      @assets_under_lease ||= LeaseService.assets_under_lease
    end

    def assets_with_deactivated_leases
      @assets_with_deactivated_leases ||= LeaseService.assets_with_deactivated_leases
    end

    ##
    # @since 3.0.0
    #
    # @param [Valkyrie::Resource, ActiveFedora::Base] resource
    #
    # @return [Boolean] whether the resource has an lease that is currently
    #   enforced (regardless of whether it has expired)
    #
    # @note Hyrax::Forms::Failedsubmissionformwrapper is a place
    #   holder until we switch to Valkyrie::ChangeSet instead of Form
    #   objects
    def lease_enforced?(resource)
      # This is a guard; from the UI rendering perspective, there's no
      # active lease enforcement until the object is saved.
      return false unless resource.persisted?

      case resource
      when Hydra::AccessControls::Embargoable
        !resource.lease_expiration_date.nil?
      when HydraEditor::Form, Hyrax::Forms::FailedSubmissionFormWrapper
        lease_enforced?(resource.model)
      when Valkyrie::ChangeSet
        Hyrax::LeaseManager.new(resource: resource.model).enforced?
      else
        Hyrax::LeaseManager.new(resource: resource).enforced?
      end
    end

    ##
    # @since 3.5.0
    #
    # @param [#lease_history, #lease] resource
    #
    # @return [Array]
    def lease_history(resource)
      resource.try(:lease_history) ||
        Array(resource.lease&.lease_history)
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
hyrax-5.1.0.pre.beta1 app/helpers/hyrax/lease_helper.rb
hyrax-5.0.4 app/helpers/hyrax/lease_helper.rb
hyrax-5.0.3 app/helpers/hyrax/lease_helper.rb
hyrax-5.0.2 app/helpers/hyrax/lease_helper.rb
hyrax-5.0.1 app/helpers/hyrax/lease_helper.rb
hyrax-5.0.0 app/helpers/hyrax/lease_helper.rb
hyrax-5.0.0.rc3 app/helpers/hyrax/lease_helper.rb
hyrax-5.0.0.rc2 app/helpers/hyrax/lease_helper.rb
hyrax-5.0.0.rc1 app/helpers/hyrax/lease_helper.rb
hyrax-3.6.0 app/helpers/hyrax/lease_helper.rb
hyrax-4.0.0 app/helpers/hyrax/lease_helper.rb
hyrax-4.0.0.rc3 app/helpers/hyrax/lease_helper.rb
hyrax-4.0.0.rc2 app/helpers/hyrax/lease_helper.rb
hyrax-4.0.0.rc1 app/helpers/hyrax/lease_helper.rb
hyrax-3.5.0 app/helpers/hyrax/lease_helper.rb
hyrax-4.0.0.beta2 app/helpers/hyrax/lease_helper.rb