show the correct date/time for the student access report

The report was displaying the AssetUserAccess updated_at, which isn't
always the time of the last access -- #display_name re-saves the record,
for example.

Now AssetUserAccess keeps the last access time in a dedicated
last_access field. Turns out the table already had this column, but it
was unused. So now we're using it.

fixes #6679

test plan:
  * As a student, access some course content -- look at assignments,
    quizzes, pages, the syllabus, etc
  * As a teacher, go to the student roster, select the student, and
    click to view the student access report.
  * Verify that all the last access times are correct (and not just set
    to the current time).

Change-Id: Icef3073e777d191c281a21e8d160ec08201be374
Reviewed-on: https://gerrit.instructure.com/8880
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
This commit is contained in:
Brian Palmer 2012-02-21 15:40:06 -07:00
parent 02fd084b88
commit 6486b9cefe
4 changed files with 36 additions and 11 deletions

View File

@ -698,6 +698,7 @@ class ApplicationController < ActionController::Base
@access.membership_type ||= @accessed_asset[:membership_type]
@access.context = @context.is_a?(UserProfile) ? @context.user : @context
@access.summarized_at = nil
@access.last_access = Time.now.utc
@access.save
@page_view.asset_user_access_id = @access.id if @page_view
@page_view_update = true

View File

@ -75,7 +75,7 @@
</td>
<td class="view_score"><%= access.view_score %></td>
<td class="participate_score"><%= access.participate_score %></td>
<td class="last_viewed time_ago_date"><%= datetime_string(access.updated_at) %></td>
<td class="last_viewed time_ago_date"><%= datetime_string(access.last_access) %></td>
</tr>
<% end %>
<tr class="access blank" style="display: none;">
@ -120,7 +120,7 @@
var access = data[idx].asset_user_access;
$access.addClass(access.asset_class_name);
access.readable_name = access.readable_name || access.display_name || access.asset_code;
access.last_viewed = $.parseFromISO(access.updated_at).datetime_formatted;
access.last_viewed = $.parseFromISO(access.last_access).datetime_formatted;
$access.fillTemplateData({data: access});
$("#usage_report table tbody").append($access.show());
}

View File

@ -0,0 +1,11 @@
class UseAssetUserAccessLastAccess < ActiveRecord::Migration
tag :postdeploy
def self.up
AssetUserAccess.update_all("last_access = updated_at", "last_access is null")
end
def self.down
raise ActiveRecord::IrreversibleMigration
end
end

View File

@ -21,7 +21,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe "user asset accesses" do
before(:each) do
Setting.set('enable_page_views', 'db')
username = "nobody@example.com"
password = "asdfasdf"
u = user_with_pseudonym :active_user => true,
@ -34,21 +34,26 @@ describe "user asset accesses" do
@e.save!
@teacher = u
user_session(@user, @pseudonym)
user_model
@student = @user
@course.enroll_student(@student).accept
end
include ApplicationHelper
it "should record and show user asset accesses" do
now = Time.now.utc
Time.stubs(:now).returns(now)
assignment = @course.assignments.create(:title => 'Assignment 1')
assignment.workflow_state = 'active'
assignment.save!
user_session(@student)
get "/courses/#{@course.id}/assignments/#{assignment.id}"
response.should be_success
user_session(@teacher)
get "/courses/#{@course.id}/users/#{@student.id}/usage"
response.should be_success
@ -56,11 +61,19 @@ describe "user asset accesses" do
html.css('#usage_report .access.assignment').length.should == 1
html.css('#usage_report .access.assignment .readable_name').text.strip.should == 'Assignment 1'
html.css('#usage_report .access.assignment .view_score').text.strip.should == '1'
html.css('#usage_report .access.assignment .last_viewed').text.strip.should == datetime_string(now)
AssetUserAccess.first(:conditions => { :user_id => @student.id }).last_access.should == now
now2 = now + 1.hour
Time.stubs(:now).returns(now2)
# make sure that we're not using the uodated_at time as the time of the access
AssetUserAccess.update_all({ :updated_at => now2 + 5.hours }, { :user_id => @student.id })
user_session(@student)
get "/courses/#{@course.id}/assignments/#{assignment.id}"
response.should be_success
user_session(@teacher)
get "/courses/#{@course.id}/users/#{@student.id}/usage"
response.should be_success
@ -68,7 +81,7 @@ describe "user asset accesses" do
html.css('#usage_report .access.assignment').length.should == 1
html.css('#usage_report .access.assignment .readable_name').text.strip.should == 'Assignment 1'
html.css('#usage_report .access.assignment .view_score').text.strip.should == '2'
html.css('#usage_report .access.assignment .last_viewed').text.strip.should == datetime_string(now2)
AssetUserAccess.first(:conditions => { :user_id => @student.id }).last_access.should == now2
end
end