From bae5a781f86293235a7909e43a34b68a0752f955 Mon Sep 17 00:00:00 2001 From: James Williams Date: Mon, 3 Aug 2015 10:55:26 -0600 Subject: [PATCH] show user name in user profile rows on access report test plan: * enable page views * as a user, visit the course profile page of another user * the visitor's access report should show the visited user's name, rather than a blank "Content" column closes #CNVS-22233 Change-Id: Ifaa4bd9fcdee7a805e00dc23f313262e9925325a Reviewed-on: https://gerrit.instructure.com/59836 Tested-by: Jenkins Reviewed-by: Jeremy Stanley QA-Review: Charles Kimball Product-Review: James Williams --- app/models/asset_user_access.rb | 7 ++++--- spec/integration/asset_accesses_spec.rb | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/models/asset_user_access.rb b/app/models/asset_user_access.rb index 07e80d88152..4f15a88a4f5 100644 --- a/app/models/asset_user_access.rb +++ b/app/models/asset_user_access.rb @@ -58,7 +58,7 @@ class AssetUserAccess < ActiveRecord::Base res[:totals] = {} res[:prior_totals] = {} Rails.cache.fetch(['access_by_category', list.first, list.last, list.length].cache_key) do - list.each{|a| + list.each{|a| a.category ||= 'unknown' cat = res[:categories][a.category] || {} cat[:view_tally] ||= 0 @@ -83,7 +83,7 @@ class AssetUserAccess < ActiveRecord::Base res[:totals][:participate_tally] ||= 0 res[:totals][:participate_tally] += a.participate_score || 0 } - (old_list || []).each{|a| + (old_list || []).each{|a| a.category ||= 'unknown' cat = res[:categories][a.category] || {} cat[:prior_view_tally] ||= 0 @@ -103,7 +103,7 @@ class AssetUserAccess < ActiveRecord::Base res[:prior_totals][:participate_tally] ||= 0 res[:prior_totals][:participate_tally] += a.participate_score || 0 } - res[:categories].each{|key, val| + res[:categories].each{|key, val| res[:categories][key][:participate_average] = (res[:categories][key][:participate_tally].to_f / res[:totals][:participate_tally].to_f * 100).round / 100.0 rescue 0 res[:categories][key][:view_average] = (res[:categories][key][:view_tally].to_f / res[:totals][:view_tally].to_f * 100).round rescue 0 res[:categories][key][:interaction_seconds_average] = (res[:categories][key][:interaction_seconds].to_f / res[:categories][key][:view_tally].to_f * 100).round / 100.0 rescue 0 @@ -160,6 +160,7 @@ class AssetUserAccess < ActiveRecord::Base return nil unless asset_code asset_code, general = self.asset_code.split(":").reverse asset = Context.find_asset_by_asset_string(asset_code, context) + asset ||= (match = asset_code.match(/enrollment_(\d+)/)) && Enrollment.where(:id => match[1]).first asset end diff --git a/spec/integration/asset_accesses_spec.rb b/spec/integration/asset_accesses_spec.rb index a554b813e54..fb8963229fd 100644 --- a/spec/integration/asset_accesses_spec.rb +++ b/spec/integration/asset_accesses_spec.rb @@ -86,4 +86,10 @@ describe "user asset accesses" do expect(html.css('#usage_report .access.assignment .last_viewed').text.strip).to eq datetime_string(now2) expect(AssetUserAccess.where(:user_id => @student).first.last_access.to_i).to eq now2.to_i end + + it "should record user names when viewing profiles" do + user_session(@student) + get "/courses/#{@course.id}/users/#{@teacher.id}" + expect(AssetUserAccess.where(:user_id => @student).first.display_name).to eq @teacher.name + end end