Modified: branches/event_logging/app/helpers/application_helper.rb (2033 => 2034)
--- branches/event_logging/app/helpers/application_helper.rb 2008-12-05 12:37:35 UTC (rev 2033)
+++ branches/event_logging/app/helpers/application_helper.rb 2008-12-05 14:40:03 UTC (rev 2034)
@@ -2361,35 +2361,92 @@
when "Creditation"
if action == "create"
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)
+ # process potentially multiple creditations
+ all_creditation_ids = [log_entry.activity_loggable_id]
+ extra_objects.each do |extra_creditation|
+ # all of the "extra objects" will be creditations, no need to check the type
+ all_creditation_ids << extra_creditation[1]
+ end
- # the news item to be displayed if the current viewer is allowed to see the affected contributable
- authorized = ( my_event || object.authorized?("view", current_viewer) )
+ not_found_creditation_count = 0
+ credited_whom_strings = []
+ find_object = true
+ original_creditation = nil
- # 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)
- credited_whom = "themself"
- else
- case log_entry.referenced_type
- when "User"
- credited_whom = name(log_entry.referenced_id, nil, false)
- return nil if credited_whom.nil?
- when "Network"
- network_title = title(log_entry.referenced_id)
- return nil if network_title.nil?
- credited_whom = "the #{network_title} Group"
+ all_creditation_ids.each do |creditation_id|
+ # protected block required to ensure that if several - not all bookmarks are missing, remaining still get displayed
+ begin
+ # if the creditation is found, no need to check for culprit existence - it's the same culprit in all grouped creditations
+ # (due to the way grouping works), and was already checked to exist
+ creditation = nil
+ creditation = Creditation.find(creditation_id)
+
+ credited_whom = ""
+
+ if find_object
+ # first "valid" iteration of the loop - need to find the object for which actors are credited;
+ # and check if current viewer is authorized to see this
+ original_creditation = creditation
+ object, object_path = evaluate_object_instance_and_path(original_creditation.creditable_type, original_creditation.creditable_id)
+ object_visible_name = contributable_name_from_instance(object)
+ find_object = false
+
+ # the news item to be displayed if the current viewer is allowed to see the affected contributable
+ authorized = ( my_event || object.authorized?("view", current_viewer) )
+ return nil unless authorized
+ end
+
+ # it's most likely that the grouping was done correctly (it's done by culprit_type/ID and the exact timestamp),
+ # but still need to check if the extra_creditation is giving credit to someone for the same object as the original one
+ # (just in case - to prevent any -- unlikely as the timestamps are matched up to the last second -- coincidents)
+ if (original_creditation.creditable_type == creditation.creditable_type && original_creditation.creditable_id == creditation.creditable_id)
+ # all good so far, can join the credited person;
+ # wording for credit to the user themself follows a different pattern (will also check that each credited actor still exists)
+ if (log_entry.culprit_type == creditation.creditor_type && log_entry.culprit_id == creditation.creditor_id)
+ credited_whom = "themself"
+ else
+ case creditation.creditor_type
+ when "User"
+ credited_whom = name(creditation.creditor_id, nil, false)
+ when "Network"
+ network_title = title(creditation.creditor_id)
+ credited_whom = (network_title.nil? ? nil : "the #{network_title} Group")
+ else
+ credited_whom = "(#{creditation.creditor_type},#{creditation.creditor_id})"
+ end
+ end
+ credited_whom_strings << credited_whom unless credited_whom.nil?
+ # else
+ # this can't be matched, so will be discarded (very unlikely event, so it's not
+ # a problem that it might not appear in the news feed at some point)
+ end
+
+ rescue ActiveRecord::RecordNotFound
+ if creditation.nil?
+ # just one of the creditations missing
+ not_found_creditation_count += 1
else
- credited_whom = "(#{log_entry.referenced_type},#{log_entry.referenced_id})"
+ # object not found - no reason for further processing, as all of
+ # these creditations should refer to the same object
+ raise ActiveRecord::RecordNotFound, "The subject of creditations not found"
+ end
end
end
+ if not_found_creditation_count == all_creditation_ids.length
+ raise ActiveRecord::RecordNotFound, "None of the creditations found"
+ elsif credited_whom_strings.empty?
+ raise ActiveRecord::RecordNotFound, "None of the credited actors found"
+ end
+
+
if authorized
- rtn << [timestamp, "#{culprit_link} <span class='news_feed_action'>credited</span> #{credited_whom} for #{link_to object_visible_name, object_path} #{model_visible_name(object.class.to_s, true, object)}.", "Creditations"]
+ rtn << [timestamp, "#{culprit_link} <span class='news_feed_action'>credited</span> #{credited_whom_strings.join(", ")} for #{link_to object_visible_name, object_path} #{model_visible_name(object.class.to_s, true, object)}.", "Creditations"]
end
- rescue ActiveRecord::RecordNotFound
+ rescue ActiveRecord::RecordNotFound # => e
# do nothing, but don't display the news entry for missing creditation / object
+ #puts "================= Creditations -- ERRORS =================="
+ #puts e
end
end