Modified: branches/event_logging/app/helpers/application_helper.rb (2034 => 2035)
--- branches/event_logging/app/helpers/application_helper.rb 2008-12-05 14:40:03 UTC (rev 2034)
+++ branches/event_logging/app/helpers/application_helper.rb 2008-12-05 16:27:55 UTC (rev 2035)
@@ -2371,10 +2371,11 @@
not_found_creditation_count = 0
credited_whom_strings = []
find_object = true
+ object = nil
original_creditation = nil
all_creditation_ids.each do |creditation_id|
- # protected block required to ensure that if several - not all bookmarks are missing, remaining still get displayed
+ # protected block required to ensure that if several - not all creditations 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
@@ -2425,15 +2426,15 @@
if creditation.nil?
# just one of the creditations missing
not_found_creditation_count += 1
- else
+ elsif object.nil?
# 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"
+ raise ActiveRecord::RecordNotFound, "The object for which actors are credited not found"
end
end
end
- if not_found_creditation_count == all_creditation_ids.length
+ 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"
@@ -2453,25 +2454,91 @@
when "Attribution"
if action == "create"
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)
+ # process potentially multiple attributions
+ all_attribution_ids = [log_entry.activity_loggable_id]
+ extra_objects.each do |extra_attribution|
+ # all of the "extra objects" will be attributions, no need to check the type
+ all_attribution_ids << extra_attribution[1]
+ end
- # the news item to be displayed if the current viewer is allowed to view WHAT and TO WHAT it was attributed;
- # if current viewer is not allowed to see the first contributable, they shouldn't see the whole news item
- authorized = ( my_event || attributed_what.authorized?("view", current_viewer) )
- return nil unless authorized
+ not_found_attribution_count = 0
+ attributed_to_strings = []
+ original_attribution = nil
+ find_object = true
+ attributed_what = nil
+ attributed_what_name_link = ""
- 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)
+ all_attribution_ids.each do |attribution_id|
+ # protected block required to ensure that if several - not all attributions are missing, remaining still get displayed
+ begin
+ # if the attribution is found, no need to check for culprit existence - it's the same culprit in all grouped attributions
+ # (due to the way grouping works), and was already checked to exist
+ attribution = nil
+ attribution = Attribution.find(attribution_id)
+
+ if find_object
+ # first "valid" iteration of the loop - need to find the object which is attributed to the other items;
+ # and check if current viewer is authorized to see this
+ original_attribution = attribution
+ attributed_what, attributed_what_path = evaluate_object_instance_and_path(original_attribution.attributable_type, original_attribution.attributable_id)
+ attributed_what_visible_name = contributable_name_from_instance(attributed_what)
+ attributed_what_name_link = (link_to(attributed_what_visible_name, attributed_what_path) + " " + model_visible_name(attributed_what.class.to_s, true, attributed_what))
+ find_object = false
+
+ # the news item to be displayed if the current viewer is allowed to view WHAT and TO WHAT it was attributed;
+ # if current viewer is not allowed to see the first "WHAT" contributable, they shouldn't see the whole news item
+ authorized = ( my_event || attributed_what.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_attribution refers to 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_attribution.attributable_type == attribution.attributable_type && original_attribution.attributable_id == attribution.attributable_id)
+ # all good so far, can join the "attributed to" object;
+ attributed_to = nil
+ attributed_to, attributed_to_path = evaluate_object_instance_and_path(attribution.attributor_type, attribution.attributor_id)
+ attributed_to_visible_name = contributable_name_from_instance(attributed_to)
+ authorized = ( my_event || attributed_to.authorized?("view", current_viewer) )
+
+ if authorized
+ attributed_to_strings << [link_to(attributed_to_visible_name, attributed_to_path) + " " + model_visible_name(attributed_to.class.to_s, true, attributed_to)]
+ end
+ # 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 attribution.nil?
+ # just one of the attributions missing
+ not_found_attribution_count += 1
+ elsif attributed_what.nil?
+ # object not found - no reason for further processing, as all of
+ # these attributions should refer to the same object
+ raise ActiveRecord::RecordNotFound, "The object which attributes to the other objects not found"
+ elsif attributed_to.nil?
+ # just one of the object TO which the main object attributes missing
+ # do nothing
+ end
+ end
+ end
- authorized = ( my_event || attributed_to.authorized?("view", current_viewer) )
+ if not_found_attribution_count >= all_attribution_ids.length
+ raise ActiveRecord::RecordNotFound, "None of the attributions found"
+ # NEXT TWO LINES LEFT HERE ONLY FOR CLARITY - CHECK WITHIN THE "rtn << " block replicates this
+ # elsif attributed_to_strings.empty?
+ # raise ActiveRecord::RecordNotFound, "None of the 'attributed to' objects found or authorized"
+ end
- if authorized
- rtn << [timestamp, "#{culprit_link} <span class='news_feed_action'>attributed</span> #{link_to attributed_what_visible_name, attributed_what_path} #{model_visible_name(attributed_what.class.to_s, true, attributed_what)} to #{link_to attributed_to_visible_name, attributed_to_path} #{model_visible_name(attributed_to.class.to_s, true, attributed_to)}.", "Attributions"]
+
+ unless attributed_to_strings.empty?
+ rtn << [timestamp, "#{culprit_link} <span class='news_feed_action'>attributed</span> #{attributed_what_name_link} to #{attributed_to_strings.join(", ")}.", "Attributions"]
end
- rescue ActiveRecord::RecordNotFound
+ rescue ActiveRecord::RecordNotFound # => e
# do nothing, but don't display the news entry for missing creditation / object
+ #puts "================= Attributions -- ERRORS =================="
+ #puts e
end
end