Class: ContentDepositorChangeEventJob

Inherits:
EventJob
  • Object
show all
Defined in:
app/jobs/content_depositor_change_event_job.rb

Instance Attribute Summary collapse

Attributes inherited from EventJob

#depositor_id, #generic_file_id

Instance Method Summary collapse

Methods included from Sufia::SufiaHelperBehavior

#current_search_parameters, #display_user_name, #error_messages_for, #has_collection_search_parameters?, #iconify_auto_link, #link_back_to_dashboard, #link_to_dashboard_query, #link_to_facet, #link_to_facet_list, #link_to_field, #link_to_profile, #link_to_telephone, #linkify_chat_id, #number_of_deposits, #render_visibility_label, #render_visibility_link, #search_form_action, #show_transfer_request_title, #sufia_thumbnail_tag

Methods included from Sufia::BlacklightOverride

#render_bookmarks_control?, #render_constraints_query, #url_for_document

Constructor Details

#initialize(pid, login, reset = false) ⇒ ContentDepositorChangeEventJob

Returns a new instance of ContentDepositorChangeEventJob.

Parameters:

  • pid (String)

    identifier of the file to be transfered

  • login (String)

    the user key of the user the file is being transfered to.

  • reset (Boolean) (defaults to: false)

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



12
13
14
15
16
# File 'app/jobs/content_depositor_change_event_job.rb', line 12

def initialize(pid, , reset=false)
  self.pid = pid
  self. = 
  self.reset = reset
end

Instance Attribute Details

#loginObject

Returns the value of attribute login.



7
8
9
# File 'app/jobs/content_depositor_change_event_job.rb', line 7

def 
  @login
end

#pidObject

Returns the value of attribute pid.



7
8
9
# File 'app/jobs/content_depositor_change_event_job.rb', line 7

def pid
  @pid
end

#resetObject

Returns the value of attribute reset.



7
8
9
# File 'app/jobs/content_depositor_change_event_job.rb', line 7

def reset
  @reset
end

Instance Method Details

#log_depositor_event(event, depositor, gf) ⇒ Object



42
43
44
45
46
47
48
49
# File 'app/jobs/content_depositor_change_event_job.rb', line 42

def log_depositor_event(event, depositor, gf)
  # Log the event to the depositor's profile stream
  depositor.log_profile_event(event)
  # Fan out the event to all followers who have access
  depositor.followers.select { |user| user.can? :read, gf }.each do |follower|
    follower.log_event(event)
  end
end

#queue_nameObject



3
4
5
# File 'app/jobs/content_depositor_change_event_job.rb', line 3

def queue_name
  :proxy_deposit
end

#runObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/jobs/content_depositor_change_event_job.rb', line 18

def run
  # TODO: This should be in its own job, not this event job
  file = ::GenericFile.find(pid)
  file.proxy_depositor = file.depositor
  file..clear_permissions! if reset
  file.()
  file.save!

  action = "User #{link_to_profile file.proxy_depositor} has transferred #{link_to file.title.first, Sufia::Engine.routes.url_helpers.generic_file_path(file.noid)} to User #{link_to_profile }"
  timestamp = Time.now.to_i
  depositor = ::User.find_by_user_key(file.depositor)
  proxy_depositor = ::User.find_by_user_key(file.proxy_depositor)
  # Create the event
  event = proxy_depositor.create_event(action, timestamp)
  # Log the event to the GF's stream
  file.log_event(event)

  #log the event to the depositor
  log_depositor_event(event, depositor, file)

  #log the event to the proxy_depositor
  log_depositor_event(event, proxy_depositor, file)
end