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:
parent
02fd084b88
commit
6486b9cefe
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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
|
|
@ -40,7 +40,12 @@ describe "user asset accesses" do
|
|||
@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!
|
||||
|
@ -56,6 +61,14 @@ 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}"
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue