convert parameter helper to a privacy level decorator

test plan: specs pass

fixes PLAT-2587

Change-Id: I92a73ea9f45447db09bace05721bcb81fe45ecde
Reviewed-on: https://gerrit.instructure.com/111698
Tested-by: Jenkins
Reviewed-by: Weston Dransfield <wdransfield@instructure.com>
Product-Review: Brad Humphrey <brad@instructure.com>
QA-Review: Brad Humphrey <brad@instructure.com>
This commit is contained in:
Brad Humphrey 2017-05-12 16:02:10 -06:00
parent f85f36f234
commit 7eec8153df
3 changed files with 31 additions and 90 deletions

View File

@ -661,11 +661,14 @@ class ExternalToolsController < ApplicationController
}
collaboration = opts[:content_item_id].present? ? ExternalToolCollaboration.find(opts[:content_item_id]) : nil
params_helper = content_item_param_helper(placement, collaboration)
base_expander = variable_expander(tool: tool, collaboration: collaboration)
expander = Lti::PrivacyLevelExpander.new(placement, base_expander)
selection_request.generate_lti_launch(placement: placement,
expanded_variables: params_helper.expanded_variables,
opts: opts)
selection_request.generate_lti_launch(
placement: placement,
expanded_variables: expander.expanded_variables!(tool.set_custom_fields(placement)),
opts: opts
)
end
protected :content_item_selection_request
@ -1085,19 +1088,6 @@ class ExternalToolsController < ApplicationController
Lti::VariableExpander.new(@domain_root_account, @context, self, default_opts.merge(opts))
end
def content_item_param_helper(placement, collaboration)
Lti::PrivacyLevelExpander.new(tool: @tool,
placement: placement,
collaboration: collaboration,
context: @context,
opts: {
current_user: @current_user,
current_pseudonym: @current_pseudonym,
domain_root_account: @domain_root_account,
controller: self
})
end
def placement_from_params
params[:placement] || params[:launch_type] || "#{@context.class.base_class.to_s.downcase}_navigation"
end

View File

@ -30,35 +30,23 @@ module Lti
anonymous: ANONYMOUS
}.freeze
def initialize(tool:, placement:, context:, collaboration: nil, opts: {})
@tool = tool
def initialize(placement, variable_expander)
@placement = placement
@context = context
@collaboration = collaboration
@opts = opts.merge({tool: tool, collaboration: collaboration})
@variable_expander = variable_expander
end
def expanded_variables
variable_expander.expand_variables!(@tool.set_custom_fields(@placement)).merge(parameter_hash)
def expanded_variables!(var_hash)
@variable_expander.expand_variables!(var_hash).merge(parameter_hash)
end
def supported_parameters
SUPPORTED_PARAMETERS_HASH[:anonymous] | SUPPORTED_PARAMETERS_HASH[@tool.workflow_state.to_sym]
SUPPORTED_PARAMETERS_HASH[:anonymous] | SUPPORTED_PARAMETERS_HASH[@variable_expander.tool.workflow_state.to_sym]
end
private
def parameter_hash
variable_expander.enabled_capability_params(supported_parameters)
end
def variable_expander
@_varaible_expander ||= begin
Lti::VariableExpander.new(@opts[:domain_root_account],
@context,
@opts[:controller],
@opts)
end
@variable_expander.enabled_capability_params(supported_parameters)
end
end
end

View File

@ -25,14 +25,17 @@ describe Lti::PrivacyLevelExpander do
let(:placement) {'resource_selection'}
let(:tool) { new_valid_tool(course) }
let(:launch_url) { 'http://www.test.com/launch' }
let(:opts) do
{
current_user: user,
current_pseudonym: user.pseudonyms.first,
domain_root_account: course.root_account,
controller: double(request: {body: 'body content'})
}
let(:variable_expander) do
Lti::VariableExpander.new(
course.root_account,
course,
double(request: {body: 'body content'}),
{
current_user: user,
current_pseudonym: user.pseudonyms.first,
tool: tool
}
)
end
before do
@ -40,15 +43,7 @@ describe Lti::PrivacyLevelExpander do
tool.save!
end
let(:helper) do
Lti::PrivacyLevelExpander.new(
tool: tool,
placement: placement,
context: course,
collaboration: nil,
opts: opts
)
end
let(:helper) { Lti::PrivacyLevelExpander.new(placement, variable_expander) }
describe 'expanded_variables' do
it 'expands custom fields' do
@ -56,7 +51,7 @@ describe Lti::PrivacyLevelExpander do
'custom_context_id' => Lti::Asset.opaque_identifier_for(course)
}
expect(helper.expanded_variables).to include expected_params
expect(helper.expanded_variables!(tool.set_custom_fields(placement))).to include expected_params
end
it 'includes supported parameters' do
@ -64,7 +59,7 @@ describe Lti::PrivacyLevelExpander do
'context_label' => course.course_code
}
expect(helper.expanded_variables).to include expected_params
expect(helper.expanded_variables!(Hash.new)).to include expected_params
end
end
@ -77,15 +72,7 @@ describe Lti::PrivacyLevelExpander do
tool
end
let(:helper) do
Lti::PrivacyLevelExpander.new(
tool: tool,
placement: placement,
context: course,
collaboration: nil,
opts: opts
)
end
let(:helper) { Lti::PrivacyLevelExpander.new(placement, variable_expander) }
it 'includes all supported parameters if privacy level is public' do
expected_params = %w(com.instructure.contextLabel
@ -107,15 +94,7 @@ describe Lti::PrivacyLevelExpander do
tool
end
let(:helper) do
Lti::PrivacyLevelExpander.new(
tool: tool,
placement: placement,
context: course,
collaboration: nil,
opts: opts
)
end
let(:helper) { Lti::PrivacyLevelExpander.new(placement, variable_expander) }
it 'inlcudes anonymous and name only params if privacy level is name only' do
expected_params = %w(com.instructure.contextLabel
@ -134,15 +113,7 @@ describe Lti::PrivacyLevelExpander do
tool
end
let(:helper) do
Lti::PrivacyLevelExpander.new(
tool: tool,
placement: placement,
context: course,
collaboration: nil,
opts: opts
)
end
let(:helper) { Lti::PrivacyLevelExpander.new(placement, variable_expander) }
it 'includes anonymous and email only params if privacy level is email only' do
expected_params = %w(com.instructure.contextLabel
@ -159,15 +130,7 @@ describe Lti::PrivacyLevelExpander do
tool
end
let(:helper) do
Lti::PrivacyLevelExpander.new(
tool: tool,
placement: placement,
context: course,
collaboration: nil,
opts: opts
)
end
let(:helper) { Lti::PrivacyLevelExpander.new(placement, variable_expander) }
it 'includes anonymouse parameters only if privacy level is anonymous' do
expected_params = %w(com.instructure.contextLabel)