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'.freeze
PENDING =
'pending'.freeze
CANCELED =
'canceled'.freeze
REJECTED =
'rejected'.freeze

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



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

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



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

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

Instance Method Details

#cancel!Object



129
130
131
# File 'app/models/proxy_deposit_request.rb', line 129

def cancel!
  fulfill!(status: CANCELED)
end

#reject!(comment = nil) ⇒ Object

Parameters:

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



125
126
127
# File 'app/models/proxy_deposit_request.rb', line 125

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

#send_request_transfer_messageObject



79
80
81
82
83
84
85
# File 'app/models/proxy_deposit_request.rb', line 79

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



119
120
121
122
# File 'app/models/proxy_deposit_request.rb', line 119

def transfer!(reset = false)
  ContentDepositorChangeEventJob.perform_later(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


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

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



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

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