Class: ProxyDepositRequest
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ProxyDepositRequest
- 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.
Constant Summary collapse
- ACCEPTED =
'accepted'.freeze
- PENDING =
'pending'.freeze
- CANCELED =
'canceled'.freeze
- REJECTED =
'rejected'.freeze
Class Method Summary collapse
-
.incoming_for(user:) ⇒ Enumerable
A set of requests that the given user can act upon to claim the ownership transfer.
-
.outgoing_for(user:) ⇒ Enumerable
A set of requests created by the given user.
Instance Method Summary collapse
- #cancel! ⇒ Object
- #reject!(comment = nil) ⇒ Object
- #send_request_transfer_message ⇒ Object
- #transfer!(reset = false) ⇒ Object
-
#transfer_to ⇒ nil, String
Nil if we don’t have a receiving user, otherwise it returns the receiving_user’s user_key.
- #transfer_to=(user_key) ⇒ Object
Class Method Details
.incoming_for(user:) ⇒ Enumerable
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.
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
Should I skip deleted works as indicated in the .incoming_for method?
Returns 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
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_message ⇒ Object
79 80 81 82 83 84 85 |
# File 'app/models/proxy_deposit_request.rb', line 79 def if updated_at == created_at else end end |
#transfer!(reset = false) ⇒ Object
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_to ⇒ nil, String
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.
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
The HTML form for creating a ProxyDepositRequest requires this method
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 |