Modified: branches/event_logging/app/helpers/application_helper.rb (1870 => 1871)
--- branches/event_logging/app/helpers/application_helper.rb 2008-10-17 13:36:32 UTC (rev 1870)
+++ branches/event_logging/app/helpers/application_helper.rb 2008-10-17 15:57:59 UTC (rev 1871)
@@ -450,6 +450,18 @@
return truncate ? truncate(str, truncate) : str
end
+ # used to return the "visible" part for links to contributable
+ def contributable_name_from_instance(contributable)
+ case contributable.class.to_s
+ when "Workflow", "Pack"
+ return contributable.title
+ when "Blob"
+ return ((contributable.title && contributable.title.length > 0) ? h(contributable.title) : h(contributable.local_name))
+ else
+ return "(#{contributable.class.to_s},#{contributable.id})"
+ end
+ end
+
def contributable_url(contributableid, contributabletype, base_host=nil)
if base_host.blank?
return url_for(:controller => contributabletype.downcase.pluralize,
@@ -1429,7 +1441,7 @@
# get events for current contributor
- events = ActivityLog.find(:all, :conditions => ["created_at > ? AND created_at < ? AND ((culprit_type = ? AND culprit_id = ?) OR (referenced_type = ? AND referenced_id = ?))", after, before, contributor.class.to_s, contributor.id, contributor.class.to_s, contributor.id])
+ events = ActivityLog.find(:all, :conditions => ["created_at > ? AND created_at < ? AND ((activity_loggable_type = ? AND activity_loggable_id = ?) OR (culprit_type = ? AND culprit_id = ?) OR (referenced_type = ? AND referenced_id = ?))", after, before, contributor.class.to_s, contributor.id, contributor.class.to_s, contributor.id, contributor.class.to_s, contributor.id])
# if any "related_contributors", get events for each
events_for_related_contributor = []
@@ -1462,33 +1474,64 @@
loggable_type = log_entry.activity_loggable_type
timestamp = log_entry.created_at
+ # TODO: add basic check that culprit exists
+
case loggable_type.to_s
when "Workflow", "Blob", "Pack"
- # TODO: check that the event is still valid
case action
when "create", "update"
- rtn << [timestamp, "#{name(log_entry.culprit_id)} #{action}d the #{contributable(log_entry.activity_loggable_id, loggable_type)} #{model_visible_name(loggable_type.to_s)}."]
+ begin
+ object, object_path = evaluate_object_instance_and_path(log_entry.activity_loggable_type, log_entry.activity_loggable_id)
+ object_visible_name = contributable_name_from_instance(object)
+
+ rtn << [timestamp, "#{name(log_entry.culprit_id)} #{action}d the #{link_to object_visible_name, object_path} #{model_visible_name(loggable_type.to_s)}."]
+ rescue ActiveRecord::RecordNotFound
+ # do nothing, but don't display the news entry for missing contributable item
+ end
end
when "Membership"
- # TODO: check that the event is still valid
- if action == "accept"
- # this membership record contains ID of the relevant user, but was that the user who
- # accepted the membership or the "network" (i.e. the network admin - currently networks have only 1 admin)
- if log_entry.culprit_type.downcase == "user"
- user_id = log_entry.culprit_id
- network_id = log_entry.referenced_id
- else
- user_id = log_entry.referenced_id
- network_id = log_entry.culprit_id
- end
- rtn << [timestamp, "#{name(user_id)} joined the #{title(network_id)} Group."]
+ # this membership record contains ID of the user who has performed the "accept" action;
+ # was that the new member or the "network" (i.e. the network admin - currently networks have only 1 admin)
+ if log_entry.culprit_type.downcase == "user"
+ user_id = log_entry.culprit_id
+ network_id = log_entry.referenced_id
+ else
+ user_id = log_entry.referenced_id
+ network_id = log_entry.culprit_id
end
+
+ case action
+ when "invite"
+ rtn << [timestamp, "#{name(user_id)} was invited to join the #{title(network_id)} Group."]
+ when "request"
+ rtn << [timestamp, "#{name(user_id)} requested to join the #{title(network_id)} Group."]
+ when "accept"
+ rtn << [timestamp, "#{name(user_id)} joined the #{title(network_id)} Group."]
+ when "reject"
+ if log_entry.culprit_type == "User"
+ rtn << [timestamp, "#{name(user_id)} rejected invitation to join the #{title(network_id)} Group."]
+ else
+ rtn << [timestamp, "#{name(user_id)}'s request to join the #{title(network_id)} Group was rejected."]
+ end
+ when "destroy"
+ if log_entry.culprit_type == "User"
+ rtn << [timestamp, "#{name(user_id)} has left the #{title(network_id)} Group."]
+ else
+ rtn << [timestamp, "#{name(user_id)} was removed from the list of members of the #{title(network_id)} Group."]
+ end
+ end
when "Friendship"
- # TODO: check that the event is still valid
- if action == "accept"
- rtn << [timestamp, "#{name(log_entry.culprit_id)} and #{name(log_entry.referenced_id)} became friends."]
+ case action
+ when "create"
+ rtn << [timestamp, "#{name(log_entry.culprit_id)} requested friendship with #{name(log_entry.referenced_id)}."]
+ when "accept"
+ rtn << [timestamp, "#{name(log_entry.culprit_id)} and #{name(log_entry.referenced_id)} became friends."]
+ when "reject"
+ rtn << [timestamp, "#{name(log_entry.culprit_id)} rejected a friendship request from #{name(log_entry.referenced_id)}."]
+ when "destroy"
+ rtn << [timestamp, "#{name(log_entry.culprit_id)} removed #{name(log_entry.referenced_id)} from their friends list."]
end
when "Network"
@@ -1547,13 +1590,14 @@
end
shared_what_links_arr = []
- items_shared_with_this_permission = Contribution.find_by_sql("SELECT contributable_type, contributable_id FROM Contributions WHERE policy_id = #{permission.policy_id}")
+ items_shared_with_this_permission = Contribution.find_by_sql("SELECT contributable_type, contributable_id FROM Contributions WHERE policy_id = #{permission.policy_id}.")
if items_shared_with_this_permission.empty?
raise ActiveRecord::RecordNotFound, "Couldn't find any contributions associated with Policy ID = #{permission.policy_id}"
end
items_shared_with_this_permission.each do |item|
object, path = evaluate_object_instance_and_path(item.contributable_type, item.contributable_id)
- shared_what_links_arr << link_to(object.title, path)
+ object_visible_name = contributable_name_from_instance(object)
+ shared_what_links_arr << link_to(object_visible_name, path)
end
rtn << [timestamp, "#{name(log_entry.culprit_id)} shared #{access_rights} #{shared_what_links_arr.join(", ")} with #{link_to shared_with_name_or_title, shared_with_path} #{model_visible_name(shared_with.class.to_s)}."]
@@ -1569,8 +1613,9 @@
begin
rating = Rating.find(log_entry.activity_loggable_id)
object, object_path = evaluate_object_instance_and_path(log_entry.referenced_type, log_entry.referenced_id)
+ object_visible_name = contributable_name_from_instance(object)
- rtn << [timestamp, "#{name(log_entry.culprit_id)} rated #{link_to object.title, object_path} #{model_visible_name(log_entry.referenced_type.to_s)} #{rating.rating} out of 5"]
+ rtn << [timestamp, "#{name(log_entry.culprit_id)} rated #{link_to object_visible_name, object_path} #{model_visible_name(log_entry.referenced_type.to_s)} #{rating.rating} out of 5."]
rescue ActiveRecord::RecordNotFound
# do nothing, but don't display the news entry for missing rating / object
end
@@ -1586,8 +1631,9 @@
# RecordNotFound exception will be thrown and the news item won't appear
bookmark = Bookmark.find(log_entry.activity_loggable_id)
object, object_path = evaluate_object_instance_and_path(log_entry.referenced_type, log_entry.referenced_id)
+ object_visible_name = contributable_name_from_instance(object)
- rtn << [timestamp, "#{name(log_entry.culprit_id)} added #{link_to object.title, object_path} #{model_visible_name(log_entry.referenced_type.to_s)} to #{link_to "favourites", user_path(log_entry.culprit_id) + "/favourites"}"]
+ rtn << [timestamp, "#{name(log_entry.culprit_id)} added #{link_to object_visible_name, object_path} #{model_visible_name(log_entry.referenced_type.to_s)} to #{link_to "favourites", user_path(log_entry.culprit_id) + "/favourites"}."]
rescue ActiveRecord::RecordNotFound
# do nothing, but don't display the news entry for missing bookmark / object
end
@@ -1599,8 +1645,9 @@
begin
comment = Comment.find(log_entry.activity_loggable_id)
object, object_path = evaluate_object_instance_and_path(log_entry.referenced_type, log_entry.referenced_id)
+ object_visible_name = contributable_name_from_instance(object)
- rtn << [timestamp, "#{name(log_entry.culprit_id)} #{link_to "commented", object_path + "#comment_" + comment.id.to_s} on #{link_to object.title, object_path} #{model_visible_name(log_entry.referenced_type.to_s)}"]
+ rtn << [timestamp, "#{name(log_entry.culprit_id)} #{link_to "commented", object_path + "#comment_" + comment.id.to_s} on #{link_to object_visible_name, object_path} #{model_visible_name(log_entry.referenced_type.to_s)}."]
rescue ActiveRecord::RecordNotFound
# do nothing, but don't display the news entry for missing comment / object
end
@@ -1621,8 +1668,9 @@
review_title_link = ": \"" + link_to(review.title, review_path) + "\""
end
object, object_path = evaluate_object_instance_and_path(log_entry.referenced_type, log_entry.referenced_id)
+ object_visible_name = contributable_name_from_instance(object)
- rtn << [timestamp, "#{name(log_entry.culprit_id)} #{link_to_unless reviewed_link.nil?, "reviewed", reviewed_link} #{link_to object.title, object_path} #{model_visible_name(log_entry.referenced_type.to_s)}#{review_title_link}"]
+ rtn << [timestamp, "#{name(log_entry.culprit_id)} #{link_to_unless reviewed_link.nil?, "reviewed", reviewed_link} #{link_to object_visible_name, object_path} #{model_visible_name(log_entry.referenced_type.to_s)}#{review_title_link}."]
rescue ActiveRecord::RecordNotFound
# do nothing, but don't display the news entry for missing review / object
end
@@ -1634,6 +1682,7 @@
begin
creditation = Creditation.find(log_entry.activity_loggable_id)
object, object_path = evaluate_object_instance_and_path(creditation.creditable_type, creditation.creditable_id)
+ object_visible_name = contributable_name_from_instance(object)
# wording for credit to the user themself follows a different pattern
if (log_entry.culprit_type == log_entry.referenced_type && log_entry.culprit_id == log_entry.referenced_id)
@@ -1649,7 +1698,7 @@
end
end
- rtn << [timestamp, "#{name(log_entry.culprit_id)} credited #{credited_whom} for #{link_to object.title, object_path} #{model_visible_name(object.class.to_s)}"]
+ rtn << [timestamp, "#{name(log_entry.culprit_id)} credited #{credited_whom} for #{link_to object_visible_name, object_path} #{model_visible_name(object.class.to_s)}."]
rescue ActiveRecord::RecordNotFound
# do nothing, but don't display the news entry for missing creditation / object
end
@@ -1660,22 +1709,11 @@
begin
attribution = Attribution.find(log_entry.activity_loggable_id)
attributed_what, attributed_what_path = evaluate_object_instance_and_path(attribution.attributable_type, attribution.attributable_id)
+ attributed_what_visible_name = contributable_name_from_instance(attributed_what)
attributed_to, attributed_to_path = evaluate_object_instance_and_path(log_entry.referenced_type, log_entry.referenced_id)
+ attributed_to_visible_name = contributable_name_from_instance(attributed_to)
- attribution_visible_titles = []
- attribution_objects = [attributed_what, attributed_to]
- attribution_objects.each do |o|
- case o.class.to_s
- when "Blob"
- attribution_visible_titles << ((o.title && o.title.length > 0) ? h(o.title) : h(o.local_name))
- when "Workflow"
- attribution_visible_titles << o.title
- else
- attribution_visible_titles << "(#{o.class.to_s},#{o.id})"
- end
- end
-
- rtn << [timestamp, "#{name(log_entry.culprit_id)} attributed #{link_to attribution_visible_titles[0], attributed_what_path} #{model_visible_name(attributed_what.class.to_s)} to #{link_to attribution_visible_titles[1], attributed_to_path} #{model_visible_name(attributed_to.class.to_s)}"]
+ rtn << [timestamp, "#{name(log_entry.culprit_id)} attributed #{link_to attributed_what_visible_name, attributed_what_path} #{model_visible_name(attributed_what.class.to_s)} to #{link_to attributed_to_visible_name, attributed_to_path} #{model_visible_name(attributed_to.class.to_s)}."]
rescue ActiveRecord::RecordNotFound
# do nothing, but don't display the news entry for missing creditation / object
end
@@ -1687,8 +1725,9 @@
tagging = Tagging.find(log_entry.activity_loggable_id)
tag = Tag.find(tagging.tag_id)
object, object_path = evaluate_object_instance_and_path(log_entry.referenced_type, log_entry.referenced_id)
+ object_visible_name = contributable_name_from_instance(object)
- rtn << [timestamp, "#{name(log_entry.culprit_id)} tagged #{link_to object.title, object_path} #{model_visible_name(log_entry.referenced_type.to_s)} with \"#{link_to tag.name, tag_path(tag.id)}.\""]
+ rtn << [timestamp, "#{name(log_entry.culprit_id)} tagged #{link_to object_visible_name, object_path} #{model_visible_name(log_entry.referenced_type.to_s)} with \"#{link_to tag.name, tag_path(tag.id)}\"."]
rescue ActiveRecord::RecordNotFound
# do nothing, but don't display the news entry for missing tagging / tag / object
end
@@ -1698,8 +1737,11 @@
rtn << [timestamp, "#{name(log_entry.culprit_id)} selected a new profile picture #{link_to image_tag(avatar_url(log_entry.referenced_id, 50)), user_path(log_entry.culprit_id)}."]
when "User"
- if action == "activate"
- rtn << [timestamp, "#{name(log_entry.activity_loggable.id)} joined #{link_to "myExperiment", "/"}."]
+ case action
+ when "activate"
+ rtn << [timestamp, "#{name(log_entry.activity_loggable.id)} joined #{link_to "myExperiment", "/"}."]
+ when "update"
+ rtn << [timestamp, "#{name(log_entry.activity_loggable.id)} updated their #{link_to "account", user_path(log_entry.activity_loggable.id)}."]
end
else