Sha256: 5368f2064dd6404fa7fffdcfb59f6ee595fa4d4847fb19a8059976b775e6371c

Contents?: true

Size: 1.47 KB

Versions: 5

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: true
module Hyrax
  module Transactions
    module Steps
      ##
      # A `dry-transaction` step that interprets visibility/lease/embargo from
      # passed arguments.
      #
      # @since 3.0.0
      # @deprecated This is part of the legacy AF set of transaction steps for works.
      #   Transactions are not being used with AF works.  This will be removed in 4.0.
      class ApplyVisibility
        include Dry::Transaction::Operation

        ##
        # @param [Hyrax::WorkBehavior] work
        # @param [String] visibility
        # @param [String] release_date
        # @param [String] during
        # @param [String] after
        #
        # @return [Dry::Monads::Result] `Failure` if there is no
        #   `PermissionTemplate` for the input; `Success(input)`, otherwise.
        def call(work, visibility: nil, release_date: nil, during: nil, after: nil)
          return Success(work) if visibility.blank?

          intention = Hyrax::VisibilityIntention.new(visibility: visibility,
                                                     release_date: release_date,
                                                     during: during,
                                                     after: after)

          Hyrax::VisibilityIntentionApplicator.apply(intention).to(model: work)

          Success(work)
        rescue Hyrax::VisibilityIntentionApplicator::InvalidIntentionError => err
          Failure(err)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hyrax-3.6.0 lib/hyrax/transactions/steps/apply_visibility.rb
hyrax-3.5.0 lib/hyrax/transactions/steps/apply_visibility.rb
hyrax-3.4.2 lib/hyrax/transactions/steps/apply_visibility.rb
hyrax-3.4.1 lib/hyrax/transactions/steps/apply_visibility.rb
hyrax-3.4.0 lib/hyrax/transactions/steps/apply_visibility.rb