Class: ProxyDepositRequest

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActionView::Helpers::UrlHelper
Defined in:
app/models/proxy_deposit_request.rb

Overview

Responsible for persisting the ownership transfer requests and the state of each request.

See Also:

Constant Summary collapse

ACCEPTED =
'accepted'
PENDING =
'pending'
CANCELED =
'canceled'
REJECTED =
'rejected'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.incoming_for(user:) ⇒ Enumerable

Note:

We are iterating through the found objects and querying SOLR each time. Assuming we are rendering this result in a view, this is reasonable. In the view we will render the #to_s of the associated work. So we may as well preload the SOLR document.

Returns a set of requests that the given user can act upon to claim the ownership transfer.

Parameters:

  • user (User)
    • the person who needs to take action on the ownership transfer request

Returns:

  • (Enumerable)

    a set of requests that the given user can act upon to claim the ownership transfer



29
30
31
# File 'app/models/proxy_deposit_request.rb', line 29

def self.incoming_for(user:)
  where(receiving_user: user).reject(&:deleted_work?)
end

.outgoing_for(user:) ⇒ Enumerable

TODO:

Should I skip deleted works as indicated in the .incoming_for method?

Returns a set of requests created by the given user.

Parameters:

  • user (User)
    • the person who requested that a work be transfer to someone else

Returns:

  • (Enumerable)

    a set of requests created by the given user



36
37
38
# File 'app/models/proxy_deposit_request.rb', line 36

def self.outgoing_for(user:)
  where(sending_user: user)
end

Instance Method Details

#cancel!Object



141
142
143
# File 'app/models/proxy_deposit_request.rb', line 141

def cancel!
  fulfill!(status: CANCELED)
end

#reject!(comment = nil) ⇒ Object

Parameters:

  • comment (String, nil) (defaults to: nil)
    • A given reason by the rejecting user



137
138
139
# File 'app/models/proxy_deposit_request.rb', line 137

def reject!(comment = nil)
  fulfill!(status: REJECTED, comment: comment)
end

#send_request_transfer_messageObject



84
85
86
87
88
89
90
# File 'app/models/proxy_deposit_request.rb', line 84

def send_request_transfer_message
  if updated_at == created_at
    send_request_transfer_message_as_part_of_create
  else
    send_request_transfer_message_as_part_of_update
  end
end

#transfer!(reset = false) ⇒ Object

Parameters:

  • reset (TrueClass, FalseClass) (defaults to: false)

    (false) if true, reset the access controls. This revokes edit access from the depositor



131
132
133
134
# File 'app/models/proxy_deposit_request.rb', line 131

def transfer!(reset = false)
  Hyrax::ChangeDepositorService.call(work, receiving_user, reset)
  fulfill!(status: ACCEPTED)
end

#transfer_tonil, String

Note:

The HTML form for creating a ProxyDepositRequest requires this method

Returns nil if we don’t have a receiving user, otherwise it returns the receiving_user’s user_key.

Returns:

  • (nil, String)

    nil if we don’t have a receiving user, otherwise it returns the receiving_user’s user_key

See Also:

  • User#user_key


59
60
61
# File 'app/models/proxy_deposit_request.rb', line 59

def transfer_to
  receiving_user.try(:user_key)
end

#transfer_to=(user_key) ⇒ Object

Note:

The HTML form for creating a ProxyDepositRequest requires this method

Parameters:

  • user_key (String)
    • The key of the user that will receive the transfer



52
53
54
# File 'app/models/proxy_deposit_request.rb', line 52

def transfer_to=(user_key)
  self.receiving_user = User.find_by_user_key(user_key)
end