log external tool assignment views as assignment AUAs

Our AUA system is set up to be 1-1 with requests, but in the case of
external tool assignments, we call log_asset_access twice, once for the
assignment and once for the tool, and the system is set up that the last
call wins. It has been determined that the old behavior of counting
these as assignments is a better fit.

However, this system is tied into the Live Events system, and that
system handles multiple accesses per request just fine, so we want to
continue to log these to that system.

fixes CNVS-26743

test plan:
- view assignment and non-assignment external tools as a student
- look at the results in the course user page "Access Report"
- the assignment views should be counted as assignments

Change-Id: I31687222065a99c7680012f240b799dd7485edc9
Reviewed-on: https://gerrit.instructure.com/72280
Reviewed-by: Cody Cutrer <cody@instructure.com>
Tested-by: Jenkins
QA-Review: Jeremy Putnam <jeremyp@instructure.com>
Product-Review: Simon Williams <simon@instructure.com>
This commit is contained in:
Simon Williams 2016-02-16 12:02:57 -07:00
parent b824a36778
commit c975f1f009
5 changed files with 50 additions and 20 deletions

View File

@ -956,7 +956,7 @@ class ApplicationController < ActionController::Base
#
# If asset is an AR model, then its asset_string will be used. If it's an array,
# it should look like [ "subtype", context ], like [ "pages", course ].
def log_asset_access(asset, asset_category, asset_group=nil, level=nil, membership_type=nil)
def log_asset_access(asset, asset_category, asset_group=nil, level=nil, membership_type=nil, overwrite:true)
user = @current_user
user ||= User.where(id: session['file_access_user_id']).first if session['file_access_user_id'].present?
return unless user && @context && asset
@ -978,14 +978,16 @@ class ApplicationController < ActionController::Base
'unknown'
end
@accessed_asset = {
:user => user,
:code => code,
:group_code => group_code,
:category => asset_category,
:membership_type => membership_type,
:level => level
}
if !@accessed_asset || overwrite
@accessed_asset = {
:user => user,
:code => code,
:group_code => group_code,
:category => asset_category,
:membership_type => membership_type,
:level => level
}
end
Canvas::LiveEvents.asset_access(asset, asset_category, membership_type, level)
@ -1327,7 +1329,7 @@ class ApplicationController < ActionController::Base
flash[:error] = t "#application.errors.invalid_external_tool", "Couldn't find valid settings for this link"
redirect_to named_context_url(context, error_redirect_symbol)
else
log_asset_access(@tool, "external_tools", "external_tools")
log_asset_access(@tool, "external_tools", "external_tools", overwrite: false)
@opaque_id = @tool.opaque_identifier_for(@tag)
@lti_launch = @tool.settings['post_only'] ? Lti::Launch.new(post_only: true) : Lti::Launch.new

View File

@ -99,8 +99,6 @@ describe LtiApiController, type: :request do
expect(page_view.url).to eq body[:object][:id]
expect(page_view.interaction_seconds).to eq 600
end
after { Setting.set 'enable_page_views', 'false' }
end
it "should handle requests without durations" do
@ -191,8 +189,6 @@ describe LtiApiController, type: :request do
expect(page_view.url).to eq body['object']['@id']
expect(page_view.interaction_seconds).to eq 600
end
after { Setting.set 'enable_page_views', 'false' }
end
it "should handle requests without durations" do

View File

@ -175,7 +175,12 @@ describe AssignmentsController do
it "should require login for external tools in a public course" do
@course.update_attribute(:is_public, true)
@course.context_external_tools.create!(:shared_secret => 'test_secret', :consumer_key => 'test_key', :name => 'test tool', :domain => 'example.com')
@course.context_external_tools.create!(
:shared_secret => 'test_secret',
:consumer_key => 'test_key',
:name => 'test tool',
:domain => 'example.com'
)
@assignment.submission_types = 'external_tool'
@assignment.build_external_tool_tag(:url => "http://example.com/test")
@assignment.save!
@ -200,6 +205,37 @@ describe AssignmentsController do
expect(assigns(:user_has_google_drive)).to be true
end
context "page views enabled" do
before do
Setting.set('enable_page_views', 'db')
@old_thread_context = Thread.current[:context]
Thread.current[:context] = { request_id: SecureRandom.uuid }
end
after do
Thread.current[:context] = @old_thread_context
end
it "should log an AUA as an assignment view for an external tool assignment" do
user_session(@student)
@course.context_external_tools.create!(
:shared_secret => 'test_secret',
:consumer_key => 'test_key',
:name => 'test tool',
:domain => 'example.com'
)
@assignment.submission_types = 'external_tool'
@assignment.build_external_tool_tag(:url => "http://example.com/test")
@assignment.save!
get 'show', :course_id => @course.id, :id => @assignment.id
expect(response).to be_success
aua = AssetUserAccess.where(user_id: @student, context_type: 'Course', context_id: @course).first
expect(aua.asset_category).to eq 'assignments'
expect(aua.asset_code).to eq @assignment.asset_string
end
end
end
describe "GET 'syllabus'" do

View File

@ -202,8 +202,6 @@ describe ConferencesController do
post 'join', :course_id => @course.id, :conference_id => @conference.id
end
after { Setting.set 'enable_page_views', 'false' }
it "should let students join an active conference" do
expect(response).to be_redirect
expect(response['Location']).to match /wimba\.test/
@ -226,4 +224,4 @@ describe ConferencesController do
end
end
end
end
end

View File

@ -14,8 +14,6 @@ describe DiscussionTopicsApiController do
post 'add_entry', :format => 'json', :topic_id => @topic.id, :course_id => @course.id, :user_id => @user.id, :message => 'message', :read_state => 'read'
end
after { Setting.set 'enable_page_views', 'false' }
it 'creates a new discussion entry' do
entry = assigns[:entry]
expect(entry.discussion_topic).to eq @topic