Class: ProxyDepositRequest
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ProxyDepositRequest
- Includes:
- ActionView::Helpers::UrlHelper, Blacklight::SearchHelper
- Defined in:
- app/models/proxy_deposit_request.rb
Instance Attribute Summary collapse
-
#transfer_to ⇒ Object
Returns the value of attribute transfer_to.
Instance Method Summary collapse
- #accepted? ⇒ Boolean
- #cancel! ⇒ Object
- #canceled? ⇒ Boolean
- #deleted_work? ⇒ Boolean
- #pending? ⇒ Boolean
- #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_should_be_a_valid_username ⇒ Object
- #work ⇒ Object
Instance Attribute Details
#transfer_to ⇒ Object
Returns the value of attribute transfer_to.
18 19 20 |
# File 'app/models/proxy_deposit_request.rb', line 18 def transfer_to @transfer_to end |
Instance Method Details
#accepted? ⇒ Boolean
53 54 55 |
# File 'app/models/proxy_deposit_request.rb', line 53 def accepted? status == 'accepted' end |
#cancel! ⇒ Object
72 73 74 75 76 |
# File 'app/models/proxy_deposit_request.rb', line 72 def cancel! self.status = 'canceled' self.fulfillment_date = Time.current save! end |
#canceled? ⇒ Boolean
78 79 80 |
# File 'app/models/proxy_deposit_request.rb', line 78 def canceled? status == 'canceled' end |
#deleted_work? ⇒ Boolean
82 83 84 |
# File 'app/models/proxy_deposit_request.rb', line 82 def deleted_work? !work_relation.exists?(work_id) end |
#pending? ⇒ Boolean
49 50 51 |
# File 'app/models/proxy_deposit_request.rb', line 49 def pending? status == 'pending' end |
#reject!(comment = nil) ⇒ Object
65 66 67 68 69 70 |
# File 'app/models/proxy_deposit_request.rb', line 65 def reject!(comment = nil) self.receiver_comment = comment if comment self.status = 'rejected' self.fulfillment_date = Time.current save! end |
#send_request_transfer_message ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'app/models/proxy_deposit_request.rb', line 38 def if updated_at == created_at = "#{link_to(sending_user.name, Sufia::Engine.routes.url_helpers.profile_path(sending_user.user_key))} wants to transfer a work to you. Review all <a href='#{Sufia::Engine.routes.url_helpers.transfers_path}'>transfer requests</a>" User.batch_user.(receiving_user, , "Ownership Change Request") else = "Your transfer request was #{status}." += " Comments: #{receiver_comment}" unless receiver_comment.blank? User.batch_user.(sending_user, , "Ownership Change #{status}") end end |
#sending_user_should_not_be_receiving_user ⇒ Object
29 30 31 |
# File 'app/models/proxy_deposit_request.rb', line 29 def sending_user_should_not_be_receiving_user errors.add(:sending_user, 'must specify another 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
33 34 35 36 |
# File 'app/models/proxy_deposit_request.rb', line 33 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
58 59 60 61 62 63 |
# File 'app/models/proxy_deposit_request.rb', line 58 def transfer!(reset = false) ContentDepositorChangeEventJob.perform_later(work, receiving_user, reset) self.status = 'accepted' self.fulfillment_date = Time.current save! end |
#transfer_to_should_be_a_valid_username ⇒ Object
25 26 27 |
# File 'app/models/proxy_deposit_request.rb', line 25 def transfer_to_should_be_a_valid_username errors.add(:transfer_to, "must be an existing user") unless receiving_user end |
#work ⇒ Object
86 87 88 |
# File 'app/models/proxy_deposit_request.rb', line 86 def work @work ||= work_relation.find(work_id) end |