Sha256: 3a05d6dae15d6dc2c6f708168f21a74b5ed304407ab646af3066a5954581af29

Contents?: true

Size: 1.06 KB

Versions: 16

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true
require 'dry/monads'

module Hyrax
  module Transactions
    module Steps
      ##
      # Add a given `::User` as the `#depositor`
      # Move the previous value of that property to `#proxy_depositor`
      #
      #
      # If no user is given, simply passes as a `Success`.
      #
      # @since 3.4.0
      class ChangeDepositor
        include Dry::Monads[:result]

        ##
        # @param [Hyrax::Work] obj
        # @param user [User] the user that will "become" the depositor of
        #             the given work
        #
        # @return [Dry::Monads::Result]
        def call(obj, user: NullUser.new, reset: false)
          return Success(obj) unless user&.user_key

          obj = Hyrax::ChangeDepositorService.call(obj, user, reset)

          Success(obj)
        rescue StandardError => err
          Failure([err.message, obj])
        end

        ##
        # @api private
        class NullUser
          ##
          # @return [nil]
          def user_key
            nil
          end
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
hyrax-5.0.1 lib/hyrax/transactions/steps/change_depositor.rb
hyrax-5.0.0 lib/hyrax/transactions/steps/change_depositor.rb
hyrax-5.0.0.rc3 lib/hyrax/transactions/steps/change_depositor.rb
hyrax-5.0.0.rc2 lib/hyrax/transactions/steps/change_depositor.rb
hyrax-5.0.0.rc1 lib/hyrax/transactions/steps/change_depositor.rb
hyrax-3.6.0 lib/hyrax/transactions/steps/change_depositor.rb
hyrax-4.0.0 lib/hyrax/transactions/steps/change_depositor.rb
hyrax-4.0.0.rc3 lib/hyrax/transactions/steps/change_depositor.rb
hyrax-4.0.0.rc2 lib/hyrax/transactions/steps/change_depositor.rb
hyrax-4.0.0.rc1 lib/hyrax/transactions/steps/change_depositor.rb
hyrax-3.5.0 lib/hyrax/transactions/steps/change_depositor.rb
hyrax-4.0.0.beta2 lib/hyrax/transactions/steps/change_depositor.rb
hyrax-3.4.2 lib/hyrax/transactions/steps/change_depositor.rb
hyrax-4.0.0.beta1 lib/hyrax/transactions/steps/change_depositor.rb
hyrax-3.4.1 lib/hyrax/transactions/steps/change_depositor.rb
hyrax-3.4.0 lib/hyrax/transactions/steps/change_depositor.rb