Class: ProxyDepositRequest

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActionView::Helpers::UrlHelper, Blacklight::SearchHelper
Defined in:
app/models/proxy_deposit_request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#transfer_toObject

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

Returns:

  • (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

Returns:

  • (Boolean)


75
76
77
# File 'app/models/proxy_deposit_request.rb', line 75

def deleted_file?
  !GenericFile.exists?(generic_file_id)
end

#pending?Boolean

Returns:

  • (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_messageObject



35
36
37
38
39
40
41
42
43
44
# File 'app/models/proxy_deposit_request.rb', line 35

def send_request_transfer_message
  if updated_at == created_at
    message = "#{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.send_message(receiving_user, message, "Ownership Change Request")
  else
    message = "Your transfer request was #{status}."
    message += " Comments: #{receiver_comment}" unless receiver_comment.blank?
    User.batchuser.send_message(sending_user, message, "Ownership Change #{status}")
  end
end

#sending_user_should_not_be_receiving_userObject



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_transferObject



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

#titleObject



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

Parameters:

  • reset (Boolean) (defaults to: false)

    (false) should the access controls be reset. This means revoking edit access from the depositor



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_usernameObject



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