diff --git a/app/controllers/external_tools_controller.rb b/app/controllers/external_tools_controller.rb
index f18573d008c..32548fa23b8 100644
--- a/app/controllers/external_tools_controller.rb
+++ b/app/controllers/external_tools_controller.rb
@@ -178,12 +178,12 @@ class ExternalToolsController < ApplicationController
redirect_to named_context_url(@context, :context_url)
return
end
+
@resource_title = @tool.label_for(selection_type.to_sym)
- @resource_url = @tool.settings[selection_type.to_sym][:url]
- @opaque_id = @context.opaque_identifier(:asset_string)
- @resource_type = selection_type
@return_url ||= url_for(@context)
- @launch = BasicLTI::ToolLaunch.new(:url => @resource_url, :tool => @tool, :user => @current_user, :context => @context, :link_code => @opaque_id, :return_url => @return_url, :resource_type => @resource_type)
+ @launch = @tool.create_launch(@context, @current_user, @return_url, selection_type)
+ @resource_url = @launch.url
+
@tool_settings = @launch.generate
render :template => 'external_tools/tool_show'
end
@@ -200,20 +200,28 @@ class ExternalToolsController < ApplicationController
# @argument description [string] [optional] A description of the tool
# @argument url [string] [optional] The url to match links against. Either "url" or "domain" should be set, not both.
# @argument domain [string] [optional] The domain to match links against. Either "url" or "domain" should be set, not both.
+ # @argument icon_url [string] [optional] The url of the icon to show for this tool
+ # @argument text [string] [optional] The default text to show for this tool
# @argument custom_fields [string] [optional] Custom fields that will be sent to the tool consumer, specified as custom_fields[field_name]
# @argument account_navigation[url] [string] [optional] The url of the external tool for account navigation
+ # @argument account_navigation[enabled] [boolean] [optional] Set this to enable this feature
# @argument account_navigation[text] [string] [optional] The text that will show on the left-tab in the account navigation
# @argument user_navigation[url] [string] [optional] The url of the external tool for user navigation
+ # @argument user_navigation[enabled] [boolean] [optional] Set this to enable this feature
# @argument user_navigation[text] [string] [optional] The text that will show on the left-tab in the user navigation
# @argument course_navigation[url] [string] [optional] The url of the external tool for course navigation
+ # @argument course_navigation[enabled] [boolean] [optional] Set this to enable this feature
# @argument course_navigation[text] [string] [optional] The text that will show on the left-tab in the course navigation
# @argument course_navigation[visibility] [string] [optional] Who will see the navigation tab. "admins" for course admins, "members" for students, null for everyone
# @argument course_navigation[default] [boolean] [optional] Whether the navigation option will show in the course by default or whether the teacher will have to explicitly enable it
# @argument editor_button[url] [string] [optional] The url of the external tool
+ # @argument editor_button[enabled] [boolean] [optional] Set this to enable this feature
# @argument editor_button[icon_url] [string] [optional] The url of the icon to show in the WYSIWYG editor
# @argument editor_button[selection_width] [string] [optional] The width of the dialog the tool is launched in
# @argument editor_button[selection_height] [string] [optional] The height of the dialog the tool is launched in
# @argument resource_selection[url] [string] [optional] The url of the external tool
+ # @argument resource_selection[enabled] [boolean] [optional] Set this to enable this feature
+ # @argument resource_selection[icon_url] [string] [optional] The url of the icon to show in the module external tool list
# @argument resource_selection[selection_width] [string] [optional] The width of the dialog the tool is launched in
# @argument resource_selection[selection_height] [string] [optional] The height of the dialog the tool is launched in
# @argument config_type [string] [optional] Configuration can be passed in as CC xml instead of using query parameters. If this value is "by_url" or "by_xml" then an xml configuration will be expected in either the "config_xml" or "config_url" parameter. Note that the name parameter overrides the tool name provided in the xml
@@ -228,14 +236,14 @@ class ExternalToolsController < ApplicationController
# -F 'name=LTI Example' \
# -F 'consumer_key=asdfg' \
# -F 'shared_secret=lkjh' \
- # -F 'url=http://example.com/ims/lti' \
+ # -F 'url=https://example.com/ims/lti' \
# -F 'privacy_level=name_only' \
# -F 'custom_fields[key1]=value1' \
# -F 'custom_fields[key2]=value2' \
- # -F 'course_navigation[url]=http://example.com/ims/lti/course_endpoint' \
- # -F 'course_navigation[text]=Course Materials' \
+ # -F 'course_navigation[text]=Course Materials' \
# -F 'course_navigation[default]=false'
- #
+ # -F 'course_navigation[enabled]=true'
+ #
# @example_request
#
# This would create a tool on the account with navigation for the user profile page
@@ -244,11 +252,12 @@ class ExternalToolsController < ApplicationController
# -F 'name=LTI Example' \
# -F 'consumer_key=asdfg' \
# -F 'shared_secret=lkjh' \
- # -F 'url=http://example.com/ims/lti' \
+ # -F 'url=https://example.com/ims/lti' \
# -F 'privacy_level=name_only' \
- # -F 'user_navigation[url]=http://example.com/ims/lti/user_endpoint' \
- # -F 'user_navigation[text]=Soemthing Cool'
- #
+ # -F 'user_navigation[url]=https://example.com/ims/lti/user_endpoint' \
+ # -F 'user_navigation[text]=Something Cool'
+ # -F 'user_navigation[enabled]=true'
+ #
# @example_request
#
# This would create a tool on the account with configuration pulled from an external URL
@@ -258,7 +267,7 @@ class ExternalToolsController < ApplicationController
# -F 'consumer_key=asdfg' \
# -F 'shared_secret=lkjh' \
# -F 'config_type=by_url' \
- # -F 'config_url=http://example.com/ims/lti/tool_config.xml'
+ # -F 'config_url=https://example.com/ims/lti/tool_config.xml'
def create
if authorized_action(@context, @current_user, :update)
@tool = @context.context_external_tools.new
@@ -327,9 +336,9 @@ class ExternalToolsController < ApplicationController
private
def set_tool_attributes(tool, params)
- [:name, :description, :url, :domain, :privacy_level, :consumer_key, :shared_secret,
+ [:name, :description, :url, :icon_url, :domain, :privacy_level, :consumer_key, :shared_secret,
:custom_fields, :custom_fields_string, :account_navigation, :user_navigation,
- :course_navigation, :editor_button, :resource_selection,
+ :course_navigation, :editor_button, :resource_selection, :text,
:config_type, :config_url, :config_xml].each do |prop|
tool.send("#{prop}=", params[prop]) if params.has_key?(prop)
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 9378798adac..9626629fe2d 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -483,8 +483,8 @@ module ApplicationHelper
{
:name => tool.label_for(:editor_button, nil),
:id => tool.id,
- :url => tool.settings[:editor_button][:url],
- :icon_url => tool.settings[:editor_button][:icon_url],
+ :url => tool.settings[:editor_button][:url] || tool.url,
+ :icon_url => tool.settings[:editor_button][:icon_url] || tool.settings[:icon_url],
:width => tool.settings[:editor_button][:selection_width],
:height => tool.settings[:editor_button][:selection_height]
}
diff --git a/app/models/context_external_tool.rb b/app/models/context_external_tool.rb
index 5bcc0ec2cf2..960b19dfc55 100644
--- a/app/models/context_external_tool.rb
+++ b/app/models/context_external_tool.rb
@@ -26,8 +26,26 @@ class ContextExternalTool < ActiveRecord::Base
state :public
state :deleted
end
-
- set_policy do
+
+ def create_launch(context, user, return_url, selection_type=nil)
+ if selection_type
+ if self.settings[selection_type.to_sym]
+ resource_url = self.settings[selection_type.to_sym][:url]
+ else
+ raise t('no_selection_type', "This tool has no selection type %{type}", :type => selection_type)
+ end
+ end
+ resource_url ||= self.url
+ BasicLTI::ToolLaunch.new(:url => resource_url,
+ :tool => self,
+ :user => user,
+ :context => context,
+ :link_code => context.opaque_identifier(:asset_string),
+ :return_url => return_url,
+ :resource_type => selection_type)
+ end
+
+ set_policy do
given { |user, session| self.cached_context_grants_right?(user, session, :update) }
can :read and can :update and can :delete
end
@@ -51,9 +69,12 @@ class ContextExternalTool < ActiveRecord::Base
def label_for(key, lang=nil)
labels = settings[key] && settings[key][:labels]
- (labels && labels[lang]) ||
+ labels2 = settings[:labels]
+ (labels && labels[lang]) ||
(labels && lang && labels[lang.split('-').first]) ||
- (settings[key] && settings[key][:text]) ||
+ (settings[key] && settings[key][:text]) ||
+ (labels2 && labels2[lang]) ||
+ (labels2 && lang && labels2[lang.split('-').first]) ||
settings[:text] || name || "External Tool"
end
@@ -169,7 +190,7 @@ class ContextExternalTool < ActiveRecord::Base
end
def resource_selection=(hash)
- tool_setting(:resource_selection, hash, :selection_width, :selection_height)
+ tool_setting(:resource_selection, hash, :selection_width, :selection_height, :icon_url)
end
def resource_selection
@@ -183,6 +204,22 @@ class ContextExternalTool < ActiveRecord::Base
def editor_button
settings[:editor_button]
end
+
+ def icon_url=(i_url)
+ settings[:icon_url] = i_url
+ end
+
+ def icon_url
+ settings[:icon_url]
+ end
+
+ def text=(val)
+ settings[:text] = val
+ end
+
+ def text
+ settings[:text]
+ end
def shared_secret=(val)
write_attribute(:shared_secret, val) unless val.blank?
@@ -191,19 +228,24 @@ class ContextExternalTool < ActiveRecord::Base
def infer_defaults
self.url = nil if url.blank?
self.domain = nil if domain.blank?
-
- settings.delete(:user_navigation) if settings[:user_navigation] && (!settings[:user_navigation][:url])
- settings.delete(:course_navigation) if settings[:course_navigation] && (!settings[:course_navigation][:url])
- settings.delete(:account_navigation) if settings[:account_navigation] && (!settings[:account_navigation][:url])
- settings.delete(:resource_selection) if settings[:resource_selection] && (!settings[:resource_selection][:url] || !settings[:resource_selection][:selection_width] || !settings[:resource_selection][:selection_height])
- settings.delete(:editor_button) if settings[:editor_button] && (!settings[:editor_button][:url] || !settings[:editor_button][:icon_url])
- settings[:icon_url] ||= settings[:editor_button][:icon_url] if settings[:editor_button] && settings[:editor_button][:icon_url]
+
[:resource_selection, :editor_button].each do |type|
if settings[type]
- settings[type][:selection_width] = settings[type][:selection_width].to_i
- settings[type][:selection_height] = settings[type][:selection_height].to_i
+ settings[:icon_url] ||= settings[type][:icon_url] if settings[type][:icon_url]
+ settings[type][:selection_width] = settings[type][:selection_width].to_i if settings[type][:selection_width]
+ settings[type][:selection_height] = settings[type][:selection_height].to_i if settings[type][:selection_height]
end
end
+ [:course_navigation, :account_navigation, :user_navigation, :resource_selection, :editor_button].each do |type|
+ if settings[type]
+ if !(settings[type][:url] || self.url) || (settings[type].has_key?(:enabled) && !settings[type][:enabled])
+ settings.delete(type)
+ end
+ end
+ end
+
+ settings.delete(:resource_selection) if settings[:resource_selection] && (!settings[:resource_selection][:selection_width] || !settings[:resource_selection][:selection_height])
+ settings.delete(:editor_button) if settings[:editor_button] && !settings[:icon_url]
self.has_user_navigation = !!settings[:user_navigation]
self.has_course_navigation = !!settings[:course_navigation]
@@ -369,19 +411,23 @@ class ContextExternalTool < ActiveRecord::Base
end
end
end
-
+
+ # sets the custom fields from the main tool settings, and any on individual resource type settings
def set_custom_fields(hash, resource_type)
- fields = resource_type ? settings[resource_type.to_sym][:custom_fields] : settings[:custom_fields]
- (fields || {}).each do |key, val|
- key = key.gsub(/[^\w]/, '_').downcase
- if key.match(/^custom_/)
- hash[key] = val
- else
- hash["custom_#{key}"] = val
+ fields = [settings[:custom_fields] || {}]
+ fields << (settings[resource_type.to_sym][:custom_fields] || {}) if resource_type && settings[resource_type.to_sym]
+ fields.each do |field_set|
+ field_set.each do |key, val|
+ key = key.to_s.gsub(/[^\w]/, '_').downcase
+ if key.match(/^custom_/)
+ hash[key] = val
+ else
+ hash["custom_#{key}"] = val
+ end
end
end
end
-
+
def clone_for(context, dup=nil, options={})
if !self.cloned_item && !self.new_record?
self.cloned_item = ClonedItem.create(:original_item => self)
@@ -453,9 +499,11 @@ class ContextExternalTool < ActiveRecord::Base
settings[setting] = {}
end
- settings[setting][:url] = hash[:url]
+ settings[setting][:url] = hash[:url] if hash[:url]
settings[setting][:text] = hash[:text] if hash[:text]
- keys.each { |key| settings[setting][key] = hash[key] }
+ settings[setting][:custom_fields] = hash[:custom_fields] if hash[:custom_fields]
+ settings[setting][:enabled] = Canvas::Plugin.value_to_boolean(hash[:enabled]) if hash.has_key?(:enabled)
+ keys.each { |key| settings[setting][key] = hash[key] if hash.has_key?(key) }
# if the type needs to do some validations for specific keys
yield settings[setting] if block_given?
diff --git a/doc/api/editor_button_tools.md b/doc/api/editor_button_tools.md
index 3433171abf9..e5a18987885 100644
--- a/doc/api/editor_button_tools.md
+++ b/doc/api/editor_button_tools.md
@@ -185,17 +185,20 @@ If the launch_presentation_return_url
were
## Settings
All of these settings are contained under "editor_button" in the tool configuration
-- url: <url> (required)
+- url: <url> (optional)
This is the URL that will be POSTed to when users click the button in any rich editor. It can be the same as the tool's URL, or something different. Domain and URL matching are not enforced for editor button links. In order to prevent security warnings for users, it is recommended that this URL be over SSL (https).
+ This is required if a url is not set on the main tool configuration.
-- icon_url: <url> (required)
+- icon_url: <url> (optional)
This is the URL of the icon that will be shown on the button in the rich editor. Icons should be 16x16 in size, and can be any standard web image format (png, gif, ico, etc.). It is recommended that this URL be over SSL (https).
+ This is required if an icon_url is not set on the main tool configuration.
-- text: <text> (required)
+- text: <text> (optional)
This is the default text that will be shown if a user hovers over the editor button. This can be overridden by language-specific settings if desired by using the labels setting. This text will also be shown next to the icon if there are too many buttons and the tool is available in the "more tools" dropdown.
+ This is required if a text value is not set on the main tool configuration.
- labels: <set of locale-label pairs> (optional)
@@ -208,3 +211,7 @@ All of these settings are contained under "editor_button" in the tool configurat
- selection_height: <number> (required)
This value is the explicit height of the dialog that is loaded when a user clicks the icon in the rich editor.
+
+- enabled: <boolean> (required)
+
+ Whether to enable this selection feature.
diff --git a/doc/api/link_selection_tools.md b/doc/api/link_selection_tools.md
index 79d3e0d2872..35fd770fc0c 100644
--- a/doc/api/link_selection_tools.md
+++ b/doc/api/link_selection_tools.md
@@ -59,13 +59,19 @@ If the launch_presentation_return_url
were
## Settings
All of these settings are contained under "resource_selection"
-- url: <url> (required)
+- url: <url> (optional)
This is the URL that will be POSTed to when users click the button in any rich editor. It can be the same as the tool's URL, or something different. Domain and URL matching are not enforced for editor button links. In order to prevent security warnings for users, it is recommended that this URL be over SSL (https).
+ This is required if a url is not set on the main tool configuration.
-- text: <text> (required)
+- icon_url: <url> (optional)
+
+ This is the URL of the icon to be shown.
+
+- text: <text> (optional)
This is the default text that will be shown if a user hovers over the editor button. This can be overridden by language-specific settings if desired by using the labels setting. This text will also be shown next to the icon if there are too many buttons and the tool is available in the "more tools" dropdown.
+ This is required if a text value is not set on the main tool configuration.
- labels: <set of locale-label pairs> (optional)
@@ -78,3 +84,7 @@ All of these settings are contained under "resource_selection"
- selection_height: <number> (required)
This value is the explicit height of the dialog that is loaded when a user clicks the icon in the rich editor.
+
+- enabled: <boolean> (required)
+
+ Whether to enable this selection feature.
\ No newline at end of file
diff --git a/doc/api/navigation_tools.md b/doc/api/navigation_tools.md
index aca47913af8..a3c5def330a 100644
--- a/doc/api/navigation_tools.md
+++ b/doc/api/navigation_tools.md
@@ -20,9 +20,10 @@ of users.
### Settings
All of these settings are contained under "course_navigation"
-- url: <url> (required)
+- url: <url> (optional)
This is the URL that will be POSTed to when users click the left tab. It can be the same as the tool's URL, or something different. Domain and URL matching are not enforced for course navigation links. In order to prevent security warnings for users, it is recommended that this URL be over SSL (https).
+ This is required if a url is not set on the main tool configuration.
- default: ['enabled', 'disabled'] (optional, 'enabled' by default)
@@ -32,14 +33,19 @@ All of these settings are contained under "course_navigation"
This specifies what types of users will see the link in the course navigation. "public" means anyone accessing the course, "members" means only users enrolled in the course, and "admins" means only Teachers, TAs, Designers and account admins will see the link.
-- text: <text> (required)
+- text: <text> (optional)
This is the default text that will be shown in the left hand navigation as the text of the link. This can be overridden by language-specific settings if desired by using the labels setting.
+ This is required if a text value is not set on the main tool configuration.
- labels: <set of locale-label pairs> (optional)
This can be used to specify different label names for different locales. For example, if an institution supports both English and Spanish interfaces, the text in the link should change depending on the language being displayed. This option lets you support multiple languages for a single tool.
+- enabled: <boolean> (required)
+
+ Whether to enable this selection feature.
+
## Account navigation links
External tools can also be configured to appear as links in
@@ -51,18 +57,24 @@ the link in their account navigation.
### Settings
All of these settings are contained under "account_navigation"
-- url: <url> (required)
+- url: <url> (optional)
This is the URL that will be POSTed to when users click the left tab. It can be the same as the tool's URL, or something different. Domain and URL matching are not enforced for account navigation links. In order to prevent security warnings for users, it is recommended that this URL be over SSL (https).
+ This is required if a url is not set on the main tool configuration.
-- text: <text> (required)
+- text: <text> (optional)
This is the default text that will be shown in the left hand navigation as the text of the link. This can be overridden by language-specific settings if desired by using the labels setting.
+ This is required if a text value is not set on the main tool configuration.
- labels: <set of locale-label pairs> (optional)
This can be used to specify different label names for different locales. For example, if an institution supports both English and Spanish interfaces, the text in the link should change depending on the language being displayed. This option lets you support multiple languages for a single tool.
+- enabled: <boolean> (required)
+
+ Whether to enable this selection feature.
+
## User navigation links
External tools can also be configured to appear as links in
@@ -76,14 +88,20 @@ profile navigation.
### Settings
All of these settings are contained under "user_navigation"
-- url: <url> (required)
+- url: <url> (optional)
This is the URL that will be POSTed to when users click the left tab. It can be the same as the tool's URL, or something different. Domain and URL matching are not enforced for user navigation links. In order to prevent security warnings for users, it is recommended that this URL be over SSL (https).
+ This is required if a url is not set on the main tool configuration.
-- text: <text> (required)
+- text: <text> (optional)
This is the default text that will be shown in the left hand navigation as the text of the link. This can be overridden by language-specific settings if desired by using the labels setting.
+ This is required if a text value is not set on the main tool configuration.
- labels: <set of locale-label pairs> (optional)
This can be used to specify different label names for different locales. For example, if an institution supports both English and Spanish interfaces, the text in the link should change depending on the language being displayed. This option lets you support multiple languages for a single tool.
+
+- enabled: <boolean> (required)
+
+ Whether to enable this selection feature.
diff --git a/doc/api/tools_xml.md b/doc/api/tools_xml.md
index 8ce5040a9bb..0dc94099bfd 100644
--- a/doc/api/tools_xml.md
+++ b/doc/api/tools_xml.md
@@ -39,9 +39,7 @@ found below.
public
-
-
-
+
### Domain matching, "name only" privacy level
@@ -60,9 +58,7 @@ found below.
name_only
example.com
-
-
-
+
## Course Navigation External Tool Examples
@@ -78,19 +74,67 @@ found below.
http://www.imsglobal.org/xsd/imsbasiclti_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imsbasiclti_v1p0.xsd
http://www.imsglobal.org/xsd/imslticm_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticm_v1p0.xsd
http://www.imsglobal.org/xsd/imslticp_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticp_v1p0.xsd">
+ https://example.com/attendance
Attendance
Provides an interactive seating chart and attendance tool
public
- example.com
- https://example.com/attendance
- Attendance
+ true
-
-
-
+
+
+### Minimal configuration with specific launch url for extension
+
+
+
+ https://example.com/
+ Attendance
+ Provides an interactive seating chart and attendance tool
+
+ public
+
+ https://example.com/attendance
+ true
+
+
+
+
+### Configuration with specific custom variables for extension
+
+
+
+ https://example.com/launch
+ Mind blowing awesomeness
+ Provides something so awesome you'll just have to launch it to believe it
+
+ public
+
+ true
+
+ value1
+ value2
+
+
+
+
### Teacher/Admin-only navigation
@@ -104,20 +148,18 @@ found below.
http://www.imsglobal.org/xsd/imsbasiclti_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imsbasiclti_v1p0.xsd
http://www.imsglobal.org/xsd/imslticm_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticm_v1p0.xsd
http://www.imsglobal.org/xsd/imslticp_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticp_v1p0.xsd">
+ https://example.com/attendance
Attendance
Provides an interactive seating chart and attendance tool
public
example.com
- https://example.com/attendance
- Attendance
admins
+ true
-
-
-
+
### Disabled by default
@@ -131,20 +173,18 @@ found below.
http://www.imsglobal.org/xsd/imsbasiclti_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imsbasiclti_v1p0.xsd
http://www.imsglobal.org/xsd/imslticm_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticm_v1p0.xsd
http://www.imsglobal.org/xsd/imslticp_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticp_v1p0.xsd">
+ https://example.com/attendance
Attendance
Provides an interactive seating chart and attendance tool
public
example.com
- https://example.com/attendance
- Attendance
disabled
+ true
-
-
-
+
### Multiple language support
@@ -166,15 +206,14 @@ found below.
https://example.com/attendance
Attendance
+ true
Attendance
Asistencia
-
-
-
+
## Account Navigation External Tool Examples
@@ -190,19 +229,18 @@ found below.
http://www.imsglobal.org/xsd/imsbasiclti_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imsbasiclti_v1p0.xsd
http://www.imsglobal.org/xsd/imslticm_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticm_v1p0.xsd
http://www.imsglobal.org/xsd/imslticp_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticp_v1p0.xsd">
+ https://example.com/reports
Custom Reports
Department reports pulled from other campus systems
public
example.com
+ Other Reports
- https://example.com/reports
- Other Reports
+ true
-
-
-
+
## User Navigation External Tool Examples
@@ -218,19 +256,17 @@ found below.
http://www.imsglobal.org/xsd/imsbasiclti_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imsbasiclti_v1p0.xsd
http://www.imsglobal.org/xsd/imslticm_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticm_v1p0.xsd
http://www.imsglobal.org/xsd/imslticp_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticp_v1p0.xsd">
+ https://example.com/profile
Campus Profile
Access to campus profile from within Canvas
public
example.com
- https://example.com/profile
- Campus Profile
+ true
-
-
-
+
## Rich Editor External Tool Examples
@@ -246,22 +282,21 @@ found below.
http://www.imsglobal.org/xsd/imsbasiclti_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imsbasiclti_v1p0.xsd
http://www.imsglobal.org/xsd/imslticm_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticm_v1p0.xsd
http://www.imsglobal.org/xsd/imslticp_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticp_v1p0.xsd">
+ https://example.com/image_selector
Image Selector
This connects to the campus image library and allows inserting images into content directly from this library
public
example.com
+ Image Library
- https://example.com/image_selector
+ true
https://example.com/image_selector.png
- Image Library
500
300
-
-
-
+
### Multiple language support
@@ -275,14 +310,15 @@ found below.
http://www.imsglobal.org/xsd/imsbasiclti_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imsbasiclti_v1p0.xsd
http://www.imsglobal.org/xsd/imslticm_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticm_v1p0.xsd
http://www.imsglobal.org/xsd/imslticp_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticp_v1p0.xsd">
+ https://example.com/image_selector
Image Selector
This connects to the campus image library and allows inserting images into content directly from this library
public
example.com
+ https://example.com/image_selector.png
- https://example.com/image_selector
- https://example.com/image_selector.png
+ true
Image Library
500
300
@@ -292,9 +328,7 @@ found below.
-
-
-
+
## Link Selection External Tool Examples
@@ -319,15 +353,14 @@ matching, and to only return URLs matching that domain.
public
example.com
+ true
https://example.com/chapter_selector
eBook Chapter Selector
500
300
-
-
-
+
### Multiple language support
@@ -347,6 +380,7 @@ matching, and to only return URLs matching that domain.
public
example.com
+ true
https://example.com/chapter_selector
eBook Chapter Selector
500
@@ -357,9 +391,7 @@ matching, and to only return URLs matching that domain.
-
-
-
+
## Combined External Tool Configuration Examples
@@ -386,19 +418,48 @@ by the service should be scoped to the matching domain.
public
example.com
+ true
https://example.com/attendance
Attendance
admins
disabled
+ true
https://example.com/attendance_admin
Attendance
-
-
-
+
+
+### Course navigation and account navigation with shared url and text
+
+
+
+ https://example.com/attendance
+ Attendance
+ Provides an interactive seating chart and attendance tool
+
+ public
+ Attendance
+
+ true
+ admins
+ disabled
+
+
+ true
+
+
+
### Rich editor and link selection with multiple language support
@@ -412,33 +473,27 @@ by the service should be scoped to the matching domain.
http://www.imsglobal.org/xsd/imsbasiclti_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imsbasiclti_v1p0.xsd
http://www.imsglobal.org/xsd/imslticm_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticm_v1p0.xsd
http://www.imsglobal.org/xsd/imslticp_v1p0 http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticp_v1p0.xsd">
+ https://example.com/wiki
Global Wiki
Institution-wide wiki tool with all the trimmings
public
example.com
-
- https://example.com/wiki
- https://example.com/wiki.png
- Build/Link to Wiki Page
- 500
- 300
-
+ https://example.com/wiki.png
+ Build/Link to Wiki Page
+
Build/Link to Wiki Page
Build/Link to Wiki Page
+
+ true
+ 500
+ 300
- https://example.com/wiki
- Build/Link to Wiki Page
+ true
500
300
-
- Build/Link to Wiki Page
- Build/Link to Wiki Page
-
-
-
-
+
diff --git a/spec/models/context_external_tool_spec.rb b/spec/models/context_external_tool_spec.rb
index 922d0d73553..16311ec7ba8 100644
--- a/spec/models/context_external_tool_spec.rb
+++ b/spec/models/context_external_tool_spec.rb
@@ -47,7 +47,7 @@ describe ContextExternalTool do
@tool.settings[:editor_button] = {
"icon_url"=>"http://www.example.com/favicon.ico",
"text"=>"Example",
- "url"=>"http://www.example.com",
+ "url"=>"http://www.example.com",
"selection_height"=>400,
"selection_width"=>600
}
@@ -55,7 +55,47 @@ describe ContextExternalTool do
@tool.should_not be_new_record
@tool.errors.should be_empty
end
-
+
+ def url_test(nav_url=nil)
+ course_with_teacher(:active_all => true)
+ @tool = @course.context_external_tools.new(:name => "a", :consumer_key => '12345', :shared_secret => 'secret', :url => "http://www.example.com")
+ [:course_navigation, :account_navigation, :user_navigation, :resource_selection, :editor_button].each do |type|
+ @tool.send "#{type}=", {
+ :url => nav_url,
+ :text => "Example",
+ :icon_url => "http://www.example.com/image.ico",
+ :selection_width => 50,
+ :selection_height => 50
+ }
+ @tool.save!
+ launch = @tool.create_launch(@course, @user, "http://test.com", type)
+ launch.resource_type.should == type
+
+ if nav_url
+ launch.url.should == nav_url
+ else
+ launch.url.should == @tool.url
+ end
+ end
+ end
+
+ it "should allow extension to not have a url if the main config has a url" do
+ url_test
+ end
+
+ it "should prefer the extension url to the main config url" do
+ url_test(nav_url="https://example.com/special_launch_of_death")
+ end
+
+ it "should not allow extension with no custom url and a domain match" do
+ @tool = @course.context_external_tools.create!(:name => "a", :domain => "google.com", :consumer_key => '12345', :shared_secret => 'secret')
+ @tool.course_navigation = {
+ :text => "Example"
+ }
+ @tool.save!
+ @tool.has_course_navigation.should == false
+ end
+
it "should not validate with no domain or url setting" do
@tool = @course.context_external_tools.create(:name => "a", :consumer_key => '12345', :shared_secret => 'secret')
@tool.should be_new_record
@@ -63,6 +103,25 @@ describe ContextExternalTool do
@tool.errors['domain'].should == "Either the url or domain should be set."
end
end
+
+ it "should allow extension with only 'enabled' key" do
+ @tool = @course.context_external_tools.create!(:name => "a", :url => "http://google.com", :consumer_key => '12345', :shared_secret => 'secret')
+ @tool.course_navigation = {
+ :enabled => "true"
+ }
+ @tool.save!
+ @tool.has_course_navigation.should == true
+ end
+
+ it "should clear disabled extensions" do
+ @tool = @course.context_external_tools.create!(:name => "a", :url => "http://google.com", :consumer_key => '12345', :shared_secret => 'secret')
+ @tool.course_navigation = {
+ :enabled => "false"
+ }
+ @tool.save!
+ @tool.has_course_navigation.should == false
+ end
+
describe "find_external_tool" do
it "should match on the same domain" do
@tool = @course.context_external_tools.create!(:name => "a", :domain => "google.com", :consumer_key => '12345', :shared_secret => 'secret')
@@ -217,8 +276,34 @@ describe ContextExternalTool do
tool = @course.context_external_tools.create!(:name => "a", :url => "http://www.google.com", :consumer_key => '12345', :shared_secret => 'secret', :custom_fields => {'a' => '123', 'b' => '456'})
tool.custom_fields_string.should == "a=123\nb=456"
end
-
-
+
+ it "should merge custom fields for extension launches" do
+ course_with_teacher(:active_all => true)
+ @tool = @course.context_external_tools.new(:name => "a", :consumer_key => '12345', :shared_secret => 'secret', :custom_fields => {'a' => "1", 'b' => "2"}, :url =>"http://www.example.com")
+ [:course_navigation, :account_navigation, :user_navigation, :resource_selection, :editor_button].each do |type|
+ @tool.send "#{type}=", {
+ :text =>"Example",
+ :url =>"http://www.example.com",
+ :icon_url => "http://www.example.com/image.ico",
+ :custom_fields => {"b" => "5", "c" => "3"},
+ :selection_width => 50,
+ :selection_height => 50
+ }
+ @tool.save!
+
+ hash = @tool.create_launch(@course, @user, "http://test.com", type).generate
+ hash["custom_a"].should == "1"
+ hash["custom_b"].should == "5"
+ hash["custom_c"].should == "3"
+
+ @tool.settings[type.to_sym][:custom_fields] = nil
+ @tool.save!
+ hash = @tool.create_launch(@course, @user, "http://test.com", type).generate
+ hash["custom_a"].should == "1"
+ hash["custom_b"].should == "2"
+ hash.has_key?("custom_c").should == false
+ end
+ end
end
describe "all_tools_for" do
@@ -362,53 +447,56 @@ describe ContextExternalTool do
end
describe "label_for" do
+ append_before(:each) do
+ @tool = @root_account.context_external_tools.new(:name => 'tool', :consumer_key => '12345', :shared_secret => 'secret', :url => "http://example.com")
+ end
+
it "should return the tool name if nothing else is configured and no key is sent" do
- tool = @root_account.context_external_tools.new(:name => 'tool', :consumer_key => '12345', :shared_secret => 'secret', :url => "http://example.com")
- tool.save!
- tool.label_for(nil).should == 'tool'
+ @tool.save!
+ @tool.label_for(nil).should == 'tool'
end
it "should return the tool name if nothing is configured on the sent key" do
- tool = @root_account.context_external_tools.new(:name => 'tool', :consumer_key => '12345', :shared_secret => 'secret', :url => "http://example.com")
- tool.settings = {:course_navigation => {:bob => 'asfd'}}
- tool.save!
- tool.label_for(:course_navigation).should == 'tool'
+ @tool.settings = {:course_navigation => {:bob => 'asfd'}}
+ @tool.save!
+ @tool.label_for(:course_navigation).should == 'tool'
end
it "should return the tool's 'text' value if no key is sent" do
- tool = @root_account.context_external_tools.new(:name => 'tool', :consumer_key => '12345', :shared_secret => 'secret', :url => "http://example.com")
- tool.settings = {:text => 'tool label', :course_navigation => {:url => "http://example.com", :text => 'course nav'}}
- tool.save!
- tool.label_for(nil).should == 'tool label'
+ @tool.settings = {:text => 'tool label', :course_navigation => {:url => "http://example.com", :text => 'course nav'}}
+ @tool.save!
+ @tool.label_for(nil).should == 'tool label'
end
it "should return the tool's 'text' value if no 'text' value is set for the sent key" do
- tool = @root_account.context_external_tools.new(:name => 'tool', :consumer_key => '12345', :shared_secret => 'secret', :url => "http://example.com")
- tool.settings = {:text => 'tool label', :course_navigation => {:bob => 'asdf'}}
- tool.save!
- tool.label_for(:course_navigation).should == 'tool label'
+ @tool.settings = {:text => 'tool label', :course_navigation => {:bob => 'asdf'}}
+ @tool.save!
+ @tool.label_for(:course_navigation).should == 'tool label'
+ end
+
+ it "should return the tool's locale-specific 'text' value if no 'text' value is set for the sent key" do
+ @tool.settings = {:text => 'tool label', :labels => {'en' => 'translated tool label'}, :course_navigation => {:bob => 'asdf'}}
+ @tool.save!
+ @tool.label_for(:course_navigation, 'en').should == 'translated tool label'
end
it "should return the setting's 'text' value for the sent key if available" do
- tool = @root_account.context_external_tools.new(:name => 'tool', :consumer_key => '12345', :shared_secret => 'secret', :url => "http://example.com")
- tool.settings = {:text => 'tool label', :course_navigation => {:url => "http://example.com", :text => 'course nav'}}
- tool.save!
- tool.label_for(:course_navigation).should == 'course nav'
+ @tool.settings = {:text => 'tool label', :course_navigation => {:url => "http://example.com", :text => 'course nav'}}
+ @tool.save!
+ @tool.label_for(:course_navigation).should == 'course nav'
end
it "should return the locale-specific label if specified and matching exactly" do
- tool = @root_account.context_external_tools.new(:name => 'tool', :consumer_key => '12345', :shared_secret => 'secret', :url => "http://example.com")
- tool.settings = {:text => 'tool label', :course_navigation => {:url => "http://example.com", :text => 'course nav', :labels => {'en-US' => 'english nav'}}}
- tool.save!
- tool.label_for(:course_navigation, 'en-US').should == 'english nav'
- tool.label_for(:course_navigation, 'es').should == 'course nav'
+ @tool.settings = {:text => 'tool label', :course_navigation => {:url => "http://example.com", :text => 'course nav', :labels => {'en-US' => 'english nav'}}}
+ @tool.save!
+ @tool.label_for(:course_navigation, 'en-US').should == 'english nav'
+ @tool.label_for(:course_navigation, 'es').should == 'course nav'
end
it "should return the locale-specific label if specified and matching based on general locale" do
- tool = @root_account.context_external_tools.new(:name => 'tool', :consumer_key => '12345', :shared_secret => 'secret', :url => "http://example.com")
- tool.settings = {:text => 'tool label', :course_navigation => {:url => "http://example.com", :text => 'course nav', :labels => {'en' => 'english nav'}}}
- tool.save!
- tool.label_for(:course_navigation, 'en-US').should == 'english nav'
+ @tool.settings = {:text => 'tool label', :course_navigation => {:url => "http://example.com", :text => 'course nav', :labels => {'en' => 'english nav'}}}
+ @tool.save!
+ @tool.label_for(:course_navigation, 'en-US').should == 'english nav'
end
end