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.



18
19
20
# File 'app/models/proxy_deposit_request.rb', line 18

def transfer_to
  @transfer_to
end

Instance Method Details

#accepted?Boolean

Returns:

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

Returns:

  • (Boolean)


78
79
80
# File 'app/models/proxy_deposit_request.rb', line 78

def canceled?
  status == 'canceled'
end

#deleted_work?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'app/models/proxy_deposit_request.rb', line 82

def deleted_work?
  !work_relation.exists?(work_id)
end

#pending?Boolean

Returns:

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



38
39
40
41
42
43
44
45
46
47
# File 'app/models/proxy_deposit_request.rb', line 38

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 work to you. Review all <a href='#{Sufia::Engine.routes.url_helpers.transfers_path}'>transfer requests</a>"
    User.batch_user.send_message(receiving_user, message, "Ownership Change Request")
  else
    message = "Your transfer request was #{status}."
    message += " Comments: #{receiver_comment}" unless receiver_comment.blank?
    User.batch_user.send_message(sending_user, message, "Ownership Change #{status}")
  end
end

#sending_user_should_not_be_receiving_userObject



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_transferObject



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

Parameters:

  • reset (TrueClass, FalseClass) (defaults to: false)

    (false) if true, reset the access controls. This revokes edit access from the depositor



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_usernameObject



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

#workObject



86
87
88
# File 'app/models/proxy_deposit_request.rb', line 86

def work
  @work ||= work_relation.find(work_id)
end