xapi: handle requests without durations
Change-Id: I907e2131ad01e4aa9dda377c8aadf3f53eac5017 Reviewed-on: https://gerrit.instructure.com/42864 Reviewed-by: Bracken Mosbacker <bracken@instructure.com> Product-Review: Bracken Mosbacker <bracken@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Braden Anderson <braden@instructure.com>
This commit is contained in:
parent
99484f3259
commit
997f4d4280
|
@ -77,8 +77,8 @@ class LtiApiController < ApplicationController
|
|||
# }
|
||||
# }
|
||||
#
|
||||
# * result.duration must be an ISO 8601 duration
|
||||
# * object.id will be logged as url
|
||||
# * result.duration must be an ISO 8601 duration if supplied
|
||||
def xapi_service
|
||||
token = Lti::XapiService::Token.parse_and_validate(params[:token])
|
||||
verify_oauth(token.tool)
|
||||
|
|
|
@ -36,10 +36,13 @@ module Lti
|
|||
course = token.course
|
||||
user = token.user
|
||||
tool = token.tool
|
||||
duration = params[:result]['duration']
|
||||
seconds = Duration.new(duration).to_i
|
||||
duration = params[:result] ? params[:result]['duration'] : nil
|
||||
seconds = duration ? Duration.new(duration).to_i : nil
|
||||
|
||||
course.enrollments.where(:user_id => user).update_all(['total_activity_time = COALESCE(total_activity_time, 0) + ?', seconds])
|
||||
if duration
|
||||
course.enrollments.where(:user_id => user).
|
||||
update_all(['total_activity_time = COALESCE(total_activity_time, 0) + ?', seconds])
|
||||
end
|
||||
|
||||
access = AssetUserAccess.where(user_id: user, asset_code: tool.asset_string).first_or_initialize
|
||||
access.log(course, group_code: "external_tools", category: "external_tools")
|
||||
|
|
|
@ -101,4 +101,11 @@ describe LtiApiController, type: :request do
|
|||
|
||||
after { Setting.set 'enable_page_views', 'false' }
|
||||
end
|
||||
|
||||
it "should handle requests without durations" do
|
||||
body = xapi_body
|
||||
body.delete(:result)
|
||||
make_call('body' => body)
|
||||
expect(response).to be_success
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue