diff --git a/lib/lti/variable_expander.rb b/lib/lti/variable_expander.rb index 6e9180c374a..9b3cf16f382 100644 --- a/lib/lti/variable_expander.rb +++ b/lib/lti/variable_expander.rb @@ -233,6 +233,10 @@ module Lti -> { @current_pseudonym.id }, -> { @current_pseudonym != @current_user } + register_expansion 'Canvas.masqueradingUser.userId', [], + -> { @tool.opaque_identifier_for(@controller.logged_in_user) }, + USER_GUARD + register_expansion 'Canvas.xapi.url', [], -> { @controller.lti_xapi_url(Lti::AnalyticsService.create_token(@tool, @current_user, @context)) }, -> { @current_user && @context.is_a?(Course) && @tool } diff --git a/spec/lib/lti/variable_expander_spec.rb b/spec/lib/lti/variable_expander_spec.rb index 1d20bb2612f..debef8f3363 100644 --- a/spec/lib/lti/variable_expander_spec.rb +++ b/spec/lib/lti/variable_expander_spec.rb @@ -34,6 +34,7 @@ module Lti shard_mock = mock('shard') shard_mock.stubs(:settings).returns({encription_key: 'abc'}) m.stubs(:shard).returns(shard_mock) + m.stubs(:opaque_identifier_for).returns("6cd2e0d65bd5aef3b5ee56a64bdcd595e447bc8f") m end let(:controller) do @@ -546,6 +547,12 @@ module Lti expect(exp_hash[:test]).to eq 7878 end + it 'has substitution for $Canvas.masqueradingUser.userId' do + exp_hash = {test: '$Canvas.masqueradingUser.userId'} + subject.expand_variables!(exp_hash) + expect(exp_hash[:test]).to eq '6cd2e0d65bd5aef3b5ee56a64bdcd595e447bc8f' + end + it 'has substitution for Canvas.module.id' do content_tag = mock('content_tag') content_tag.stubs(:context_module_id).returns('foo')