Skip to content

Commit

Permalink
Refactoring to unify a subsystem of Event behavior
Browse files Browse the repository at this point in the history
Prior to this commit, the descendants of ContentEventJob each
approached writing their `action` string differently. With this
change, I've normalized that behavior. There is still work to be done
to get a handle on the whole event ecosystem.

Relates to: #4193
  • Loading branch information
jeremyf committed May 12, 2020
1 parent 49ac3e9 commit 4946f4e
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 29 deletions.
2 changes: 1 addition & 1 deletion app/jobs/content_deposit_event_job.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Log a concern deposit to activity streams
class ContentDepositEventJob < ContentEventJob
def action
"User #{link_to_profile depositor} has deposited #{link_to repo_object.title.first, polymorphic_path(repo_object)}"
"User #{link_to_profile depositor} has deposited #{polymorphic_link_to(repo_object)}"
end
end
9 changes: 1 addition & 8 deletions app/jobs/content_depositor_change_event_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
#
# @attr [Boolean] reset (false) should the access controls be reset. This means revoking edit access from the depositor
class ContentDepositorChangeEventJob < ContentEventJob
include Rails.application.routes.url_helpers
include ActionDispatch::Routing::PolymorphicRoutes

attr_accessor :reset

# @param [ActiveFedora::Base] work the work to be transfered
Expand All @@ -16,11 +13,7 @@ def perform(work, user, reset = false)
end

def action
"User #{link_to_profile work.proxy_depositor} has transferred #{link_to_work work.title.first} to user #{link_to_profile depositor}"
end

def link_to_work(text)
link_to text, polymorphic_path(work)
"User #{link_to_profile work.proxy_depositor} has transferred #{polymorphic_link_to work} to user #{link_to_profile depositor}"
end

# Log the event to the work's stream
Expand Down
7 changes: 7 additions & 0 deletions app/jobs/content_event_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@ def log_event(repo_object)
def log_user_event(depositor)
depositor.log_profile_event(event)
end

def polymorphic_link_to(object, *args)
link_to(
object.title.first,
Rails.application.routes.url_helpers.polymorphic_path(object, *args)
)
end
end
2 changes: 1 addition & 1 deletion app/jobs/content_new_version_event_job.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Log new version of a file to activity streams
class ContentNewVersionEventJob < ContentEventJob
def action
@action ||= "User #{link_to_profile depositor} has added a new version of #{link_to repo_object.title.first, Rails.application.routes.url_helpers.hyrax_file_set_path(repo_object)}"
"User #{link_to_profile depositor} has added a new version of #{polymorphic_link_to(repo_object)}"
end
end
2 changes: 1 addition & 1 deletion app/jobs/content_restored_version_event_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ def perform(file_set, depositor, revision_id)
end

def action
"User #{link_to_profile depositor} has restored a version '#{revision_id}' of #{link_to repo_object.title.first, Rails.application.routes.url_helpers.hyrax_file_set_path(repo_object)}"
"User #{link_to_profile depositor} has restored a version '#{revision_id}' of #{polymorphic_link_to(repo_object)}"
end
end
2 changes: 1 addition & 1 deletion app/jobs/content_update_event_job.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Log content update to activity streams
class ContentUpdateEventJob < ContentEventJob
def action
"User #{link_to_profile depositor} has updated #{link_to repo_object.title.first, polymorphic_path(repo_object)}"
"User #{link_to_profile depositor} has updated #{polymorphic_link_to(repo_object)}"
end
end
18 changes: 1 addition & 17 deletions app/jobs/file_set_attached_event_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,11 @@ def log_event(repo_object)
end

def action
"User #{link_to_profile depositor} has attached #{file_link} to #{work_link}"
"User #{link_to_profile depositor} has attached #{polymorphic_link_to(repo_object)} to #{polymorphic_link_to(curation_concern)}"
end

private

def file_link
link_to file_title, polymorphic_path(repo_object)
end

def work_link
link_to work_title, polymorphic_path(curation_concern)
end

def file_title
repo_object.title.first
end

def work_title
curation_concern.title.first
end

def curation_concern
repo_object.in_works.first
end
Expand Down

0 comments on commit 4946f4e

Please sign in to comment.