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
- #deleted_file? ⇒ 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
- #title ⇒ Object
- #transfer!(reset = false) ⇒ Object
- #transfer_to_should_be_a_valid_username ⇒ Object
Instance Attribute Details
#transfer_to ⇒ Object
Returns the value of attribute transfer_to.
15 16 17 |
# File 'app/models/proxy_deposit_request.rb', line 15 def transfer_to @transfer_to end |
Instance Method Details
#accepted? ⇒ Boolean
50 51 52 |
# File 'app/models/proxy_deposit_request.rb', line 50 def accepted? status == 'accepted' end |
#cancel! ⇒ Object
69 70 71 72 73 |
# File 'app/models/proxy_deposit_request.rb', line 69 def cancel! self.status = 'canceled' self.fulfillment_date = Time.now save! end |
#deleted_file? ⇒ Boolean
75 76 77 |
# File 'app/models/proxy_deposit_request.rb', line 75 def deleted_file? !GenericFile.exists?(generic_file_id) end |
#pending? ⇒ Boolean
46 47 48 |
# File 'app/models/proxy_deposit_request.rb', line 46 def pending? status == 'pending' end |
#reject!(comment = nil) ⇒ Object
62 63 64 65 66 67 |
# File 'app/models/proxy_deposit_request.rb', line 62 def reject!(comment = nil) self.receiver_comment = comment if comment self.status = 'rejected' self.fulfillment_date = Time.now save! end |
#send_request_transfer_message ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'app/models/proxy_deposit_request.rb', line 35 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 file to you. Review all <a href='#{Sufia::Engine.routes.url_helpers.transfers_path}'>transfer requests</a>" User.batchuser.(receiving_user, , "Ownership Change Request") else = "Your transfer request was #{status}." += " Comments: #{receiver_comment}" unless receiver_comment.blank? User.batchuser.(sending_user, , "Ownership Change #{status}") end end |
#sending_user_should_not_be_receiving_user ⇒ Object
26 27 28 |
# File 'app/models/proxy_deposit_request.rb', line 26 def sending_user_should_not_be_receiving_user errors.add(:sending_user, 'must specify another user to receive the file') if receiving_user && receiving_user.user_key == sending_user.user_key end |
#should_not_be_already_part_of_a_transfer ⇒ Object
30 31 32 33 |
# File 'app/models/proxy_deposit_request.rb', line 30 def should_not_be_already_part_of_a_transfer transfers = ProxyDepositRequest.where(generic_file_id: generic_file_id, status: 'pending') errors.add(:open_transfer, 'must close open transfer on the file before creating a new one') unless transfers.blank? || (transfers.count == 1 && transfers[0].id == id) end |
#title ⇒ Object
79 80 81 82 83 84 |
# File 'app/models/proxy_deposit_request.rb', line 79 def title return 'file not found' if deleted_file? query = ActiveFedora::SolrQueryBuilder.construct_query_for_ids([generic_file_id]) solr_response = ActiveFedora::SolrService.query(query, raw: true) SolrDocument.new(solr_response['response']['docs'].first, solr_response).title end |
#transfer!(reset = false) ⇒ Object
55 56 57 58 59 60 |
# File 'app/models/proxy_deposit_request.rb', line 55 def transfer!(reset = false) Sufia.queue.push(ContentDepositorChangeEventJob.new(generic_file_id, receiving_user.user_key, reset)) self.status = 'accepted' self.fulfillment_date = Time.now save! end |
#transfer_to_should_be_a_valid_username ⇒ Object
22 23 24 |
# File 'app/models/proxy_deposit_request.rb', line 22 def transfer_to_should_be_a_valid_username errors.add(:transfer_to, "must be an existing user") unless receiving_user end |