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
- #sending_user_should_not_be_receiving_user ⇒ Object
- #should_not_be_already_part_of_a_transfer ⇒ 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
- #transfer_to_should_be_a_valid_username ⇒ 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
125 126 127 |
# File 'app/models/proxy_deposit_request.rb', line 125 def cancel! fulfill!(status: CANCELED) end |
#reject!(comment = nil) ⇒ Object
121 122 123 |
# File 'app/models/proxy_deposit_request.rb', line 121 def reject!(comment = nil) fulfill!(status: REJECTED, comment: comment) end |
#send_request_transfer_message ⇒ Object
75 76 77 78 79 80 81 |
# File 'app/models/proxy_deposit_request.rb', line 75 def if updated_at == created_at else end end |
#sending_user_should_not_be_receiving_user ⇒ Object
66 67 68 |
# File 'app/models/proxy_deposit_request.rb', line 66 def sending_user_should_not_be_receiving_user errors.add(:transfer_to, 'specify a different user to receive the work') if receiving_user && receiving_user.user_key == sending_user.user_key end |
#should_not_be_already_part_of_a_transfer ⇒ Object
70 71 72 73 |
# File 'app/models/proxy_deposit_request.rb', line 70 def should_not_be_already_part_of_a_transfer transfers = ProxyDepositRequest.where(work_id: work_id, status: PENDING) errors.add(:open_transfer, 'must close open transfer on the work before creating a new one') unless transfers.blank? || (transfers.count == 1 && transfers[0].id == id) end |
#transfer!(reset = false) ⇒ Object
115 116 117 118 |
# File 'app/models/proxy_deposit_request.rb', line 115 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 |
#transfer_to_should_be_a_valid_username ⇒ Object
62 63 64 |
# File 'app/models/proxy_deposit_request.rb', line 62 def transfer_to_should_be_a_valid_username errors.add(:transfer_to, "must be an existing user") unless receiving_user end |