initialize tool settings with tool proxy data

fixes PLAT-787

test-plan
*register the lti2 tool with custom tool setting data set
*launch the lti2 tool
*the tool settings should have the custom tool setting data you set at the tool proxy level

Change-Id: Ia3b45b34f6f1a621993c4cab9fb7cb2625e438e7
Reviewed-on: https://gerrit.instructure.com/45117
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Brad Humphrey <brad@instructure.com>
Product-Review: Nathan Mills <nathanm@instructure.com>
QA-Review: Nathan Mills <nathanm@instructure.com>
This commit is contained in:
Nathan Mills 2014-12-02 10:34:15 -07:00
parent a3b50e9514
commit 961556d582
2 changed files with 30 additions and 1 deletions

View File

@ -159,7 +159,7 @@ module Lti
if parameters && (parameters.map {|p| p['variable']}.compact & (%w( LtiLink.custom.url ToolProxyBinding.custom.url ToolProxy.custom.url ))).any?
link = ToolSetting.where(tool_proxy_id: tool_proxy.id, context_id: @context.id, context_type: @context.class.name, resource_link_id: resource_link_id).first_or_create
binding = ToolSetting.where(tool_proxy_id: tool_proxy.id, context_id: @context.id, context_type: @context.class.name, resource_link_id: nil).first_or_create
proxy = ToolSetting.where(tool_proxy_id: tool_proxy.id, context_id: nil, resource_link_id: nil).first_or_create
proxy = tool_proxy_settings(tool_proxy)
{
'LtiLink.custom.url' => show_lti_tool_settings_url(link.id),
'ToolProxyBinding.custom.url' => show_lti_tool_settings_url(binding.id),
@ -170,5 +170,13 @@ module Lti
end
end
def tool_proxy_settings(tool_proxy)
unless tool_proxy_settings = ToolSetting.where(tool_proxy_id: tool_proxy.id, context_id: nil, resource_link_id: nil).first
custom = tool_proxy.raw_data['custom'] || {}
tool_proxy_settings = ToolSetting.create!(tool_proxy: tool_proxy, context_id: nil, resource_link_id: nil, custom: custom)
end
tool_proxy_settings
end
end
end

View File

@ -202,6 +202,27 @@ module Lti
end
context 'tool settings' do
it 'creates the tool proxy setting object' do
message_handler.parameters = [{ "name" => "tool_settings", "variable" => "ToolProxy.custom.url" }]
message_handler.save!
expect(ToolSetting.where(tool_proxy_id: tool_proxy.id, context_id: nil, resource_link_id: nil).size).to eq 0
get 'basic_lti_launch_request', account_id: account.id, message_handler_id: message_handler.id, params: {tool_launch_context: 'my_custom_context'}
expect(ToolSetting.where(tool_proxy_id: tool_proxy.id, context_id: nil, resource_link_id: nil).size).to eq 1
end
it 'initializes the tool proxy setting with the custom data from the tool proxy' do
message_handler.parameters = [{ "name" => "tool_settings", "variable" => "ToolProxy.custom.url" }]
message_handler.save!
tool_proxy.raw_data = {"custom" => {"data"=> 42}}
tool_proxy.save!
get 'basic_lti_launch_request', account_id: account.id, message_handler_id: message_handler.id, params: {tool_launch_context: 'my_custom_context'}
tool_setting = ToolSetting.where(tool_proxy_id: tool_proxy.id, context_id: nil, resource_link_id: nil).first
expect(tool_setting.custom).to eq({"data"=>42})
end
end
end
end
end