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'
- PENDING =
'pending'
- CANCELED =
'canceled'
- REJECTED =
'rejected'
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.
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
Should I skip deleted works as indicated in the .incoming_for method?
Returns 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
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_message ⇒ Object
84 85 86 87 88 89 90 |
# File 'app/models/proxy_deposit_request.rb', line 84 def if updated_at == created_at else end end |
#transfer!(reset = false) ⇒ Object
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_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.
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
The HTML form for creating a ProxyDepositRequest requires this method
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 |