2015-01-08 01:54:38 +08:00
#
2017-04-28 04:04:26 +08:00
# Copyright (C) 2015 - present Instructure, Inc.
2015-01-08 01:54:38 +08:00
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
2017-02-15 07:17:07 +08:00
# NOTE: To update the VariableExpansion docs run `script/generate_lti_variable_substitution_markdown`
2015-01-08 01:54:38 +08:00
module Lti
class VariableExpander
2015-05-14 01:00:18 +08:00
SUBSTRING_REGEX = / (?<= \ ${).*?(?=}) / . freeze #matches only the stuff inside `${}`
2015-01-08 01:54:38 +08:00
attr_reader :context , :root_account , :controller , :current_user
attr_accessor :current_pseudonym , :content_tag , :assignment ,
2016-06-25 00:21:16 +08:00
:tool_setting_link_id , :tool_setting_binding_id , :tool_setting_proxy_id , :tool , :attachment ,
Render simplified launch params into NRPS v2 responses
- Output a smaller version of a LTI 1.3 launch payload for
each NRPS v2 member when the NRPS request includes a `rlid`
query parameter.
- Most claims and custom params from the launch payload are
excluded either because:
- They describe the context and would thus be redundant, or
- They pose performance problems (N+1 queries, usually), or
- They are absent from the spec example, e.g.
`https://purl.imsglobal.org/spec/lti/claim/version`, or
- They require additional development and thus need to be
handled as a separate task.
- See `memberships_provider.rb` ~line 68 for list of
custom params supported in this commit. (More coming later.)
- Vast majority of the patch has to do with tests against
`JwtMessage`, which was modified to allow claims to be turned
on/off via a new white/blacklist mechanism in `AppUtil`.
- Custom param white/blacklisting is handled directly in
`VariableExpander` to satisfy the LTI rule that unsupported
params should just be echoed as-is. This (instead of keeping
all the white/blacklist support in `JwtMessage` ensures
consistent behavior w/r/t `VariableExpander`'s more sophisticated
features, specifically its suport for expanding variables embedded
into larger strings.
Closes LTIA-40
Test Plan
- Configure a LTI 1.3/Advantage tool with the supported set of
custom params listed in `memberships_provider.rb` starting ~line 68.
If using the POST
`/api/lti/accounts/:account_id/developer_keys/tool_configuration`
API, this is done by setting
`tool_configuration.settings.custom_fields` to a JSON object where
keys are the param name to be rendered into LTI payloads and values
are the $-prefixed custom param names themselves. Include several
nonsense entries as well as unsupported entries e.g.:
```
// ... snip ...
"tool_configuration": {
"settings": {
// ... snip ...
"custom_fields": {
"person_name_full": "$Person.name.full",
"person_name_display": "$Person.name.display",
"person_name_family": "$Person.name.family",
"person_name_given": "$Person.name.given",
"canvas_user_isrootaccountadmin": "$Canvas.user.isRootAccountAdmin"
"unsupported_param_1": "$unsupported.param.1",
"unsupported_param_2": "$unsupported.param.2"
}
// ... snip ...
}
// ... snip ...
}
// ... snip ...
```
- Place this tool into a course, ensure the course has several active
members.
- Launch the tool in order to observe the course context's LTI
identifier. Use that identifier as the value of the NRPS `rlid`
parameter, e.g. a GET to:
`/api/lti/courses/1/names_and_roles?rlid=4dde05e8ca1973bcca9bffc13e1548820eee93a3`
- Each `members` array element in the response should have a
`message` array with a single element being the simplified
representation of a LTI 1.3 launch payload, were that user to launch
the context referenced by `rlid`.
- The `message` entry should have two top level claims:
- `"https://purl.imsglobal.org/spec/lti/claim/message_type": "LtiResourceLinkRequest"`
- `"https://purl.imsglobal.org/spec/lti/claim/custom": <object>`
- The `custom` claim should include an entry for each `custom_fields`
key/value pair configured above, with supported entries being
correctly expanded and nonsense and unsupported entries being echoed
as-is.
- Repeat for a group context in the same course (still using the
course's LTI ID as the `rlid` value). Results should be the same,
though scoped to group membership.
Change-Id: If2591c62c494756d65774e3115abeca19935c988
Reviewed-on: https://gerrit.instructure.com/169090
Tested-by: Jenkins
Product-Review: Karl Lloyd <karl@instructure.com>
Reviewed-by: Weston Dransfield <wdransfield@instructure.com>
Reviewed-by: Marc Phillips <mphillips@instructure.com>
QA-Review: Bill Smith <bsmith@instructure.com>
2018-10-19 07:47:37 +08:00
:collaboration , :variable_whitelist , :variable_blacklist
2015-01-08 01:54:38 +08:00
2016-10-28 03:57:01 +08:00
def self . register_expansion ( name , permission_groups , expansion_proc , * guards )
2015-01-08 01:54:38 +08:00
@expansions || = { }
Render simplified launch params into NRPS v2 responses
- Output a smaller version of a LTI 1.3 launch payload for
each NRPS v2 member when the NRPS request includes a `rlid`
query parameter.
- Most claims and custom params from the launch payload are
excluded either because:
- They describe the context and would thus be redundant, or
- They pose performance problems (N+1 queries, usually), or
- They are absent from the spec example, e.g.
`https://purl.imsglobal.org/spec/lti/claim/version`, or
- They require additional development and thus need to be
handled as a separate task.
- See `memberships_provider.rb` ~line 68 for list of
custom params supported in this commit. (More coming later.)
- Vast majority of the patch has to do with tests against
`JwtMessage`, which was modified to allow claims to be turned
on/off via a new white/blacklist mechanism in `AppUtil`.
- Custom param white/blacklisting is handled directly in
`VariableExpander` to satisfy the LTI rule that unsupported
params should just be echoed as-is. This (instead of keeping
all the white/blacklist support in `JwtMessage` ensures
consistent behavior w/r/t `VariableExpander`'s more sophisticated
features, specifically its suport for expanding variables embedded
into larger strings.
Closes LTIA-40
Test Plan
- Configure a LTI 1.3/Advantage tool with the supported set of
custom params listed in `memberships_provider.rb` starting ~line 68.
If using the POST
`/api/lti/accounts/:account_id/developer_keys/tool_configuration`
API, this is done by setting
`tool_configuration.settings.custom_fields` to a JSON object where
keys are the param name to be rendered into LTI payloads and values
are the $-prefixed custom param names themselves. Include several
nonsense entries as well as unsupported entries e.g.:
```
// ... snip ...
"tool_configuration": {
"settings": {
// ... snip ...
"custom_fields": {
"person_name_full": "$Person.name.full",
"person_name_display": "$Person.name.display",
"person_name_family": "$Person.name.family",
"person_name_given": "$Person.name.given",
"canvas_user_isrootaccountadmin": "$Canvas.user.isRootAccountAdmin"
"unsupported_param_1": "$unsupported.param.1",
"unsupported_param_2": "$unsupported.param.2"
}
// ... snip ...
}
// ... snip ...
}
// ... snip ...
```
- Place this tool into a course, ensure the course has several active
members.
- Launch the tool in order to observe the course context's LTI
identifier. Use that identifier as the value of the NRPS `rlid`
parameter, e.g. a GET to:
`/api/lti/courses/1/names_and_roles?rlid=4dde05e8ca1973bcca9bffc13e1548820eee93a3`
- Each `members` array element in the response should have a
`message` array with a single element being the simplified
representation of a LTI 1.3 launch payload, were that user to launch
the context referenced by `rlid`.
- The `message` entry should have two top level claims:
- `"https://purl.imsglobal.org/spec/lti/claim/message_type": "LtiResourceLinkRequest"`
- `"https://purl.imsglobal.org/spec/lti/claim/custom": <object>`
- The `custom` claim should include an entry for each `custom_fields`
key/value pair configured above, with supported entries being
correctly expanded and nonsense and unsupported entries being echoed
as-is.
- Repeat for a group context in the same course (still using the
course's LTI ID as the `rlid` value). Results should be the same,
though scoped to group membership.
Change-Id: If2591c62c494756d65774e3115abeca19935c988
Reviewed-on: https://gerrit.instructure.com/169090
Tested-by: Jenkins
Product-Review: Karl Lloyd <karl@instructure.com>
Reviewed-by: Weston Dransfield <wdransfield@instructure.com>
Reviewed-by: Marc Phillips <mphillips@instructure.com>
QA-Review: Bill Smith <bsmith@instructure.com>
2018-10-19 07:47:37 +08:00
@expansions [ " $ #{ name } " . to_sym ] = VariableExpansion . new (
name ,
permission_groups ,
expansion_proc ,
* ( [ - > { Lti :: AppUtil . allowed? ( name , @variable_whitelist , @variable_blacklist ) } ] + guards )
)
2015-01-08 01:54:38 +08:00
end
def self . expansions
2016-10-28 03:57:01 +08:00
@expansions || { }
2015-01-08 01:54:38 +08:00
end
2017-05-25 01:06:33 +08:00
def self . expansion_keys
self . expansions . keys . map { | c | c . to_s [ 1 .. - 1 ] }
end
2017-06-21 03:00:17 +08:00
def self . default_name_expansions
self . expansions . values . select { | v | v . default_name . present? } . map ( & :name )
end
2016-10-28 03:57:01 +08:00
CONTROLLER_GUARD = - > { ! ! @controller }
2015-01-08 01:54:38 +08:00
COURSE_GUARD = - > { @context . is_a? Course }
2015-04-23 23:08:26 +08:00
TERM_START_DATE_GUARD = - > { @context . is_a? ( Course ) && @context . enrollment_term &&
@context . enrollment_term . start_at }
2017-11-18 01:23:54 +08:00
TERM_NAME_GUARD = - > { @context . is_a? ( Course ) && @context . enrollment_term & . name }
2015-01-08 01:54:38 +08:00
USER_GUARD = - > { @current_user }
2017-01-13 06:22:26 +08:00
SIS_USER_GUARD = - > { @current_user && @current_user . pseudonym && @current_user . pseudonym . sis_user_id }
2015-01-08 01:54:38 +08:00
PSEUDONYM_GUARD = - > { sis_pseudonym }
ENROLLMENT_GUARD = - > { @current_user && @context . is_a? ( Course ) }
2015-08-04 03:46:13 +08:00
ROLES_GUARD = - > { @current_user && ( @context . is_a? ( Course ) || @context . is_a? ( Account ) ) }
2015-01-08 01:54:38 +08:00
CONTENT_TAG_GUARD = - > { @content_tag }
ASSIGNMENT_GUARD = - > { @assignment }
2016-06-25 00:21:16 +08:00
COLLABORATION_GUARD = - > { @collaboration }
2015-02-11 07:40:06 +08:00
MEDIA_OBJECT_GUARD = - > { @attachment && @attachment . media_object }
USAGE_RIGHTS_GUARD = - > { @attachment && @attachment . usage_rights }
MEDIA_OBJECT_ID_GUARD = - > { @attachment && ( @attachment . media_object || @attachment . media_entry_id ) }
2016-10-28 03:57:01 +08:00
LTI1_GUARD = - > { @tool . is_a? ( ContextExternalTool ) }
MASQUERADING_GUARD = - > { ! ! @controller && @controller . logged_in_user != @current_user }
2017-07-20 02:52:15 +08:00
MESSAGE_TOKEN_GUARD = - > { @post_message_token . present? || @launch & . instance_of? ( Lti :: Launch ) }
2017-08-16 08:38:29 +08:00
ORIGINALITY_REPORT_GUARD = - > { @originality_report . present? }
2017-12-13 02:02:29 +08:00
ORIGINALITY_REPORT_ATTACHMENT_GUARD = - > { @originality_report & . attachment . present? }
2017-08-16 08:38:29 +08:00
LTI_ASSIGN_ID = - > { @assignment . present? || @originality_report . present? || @secure_params . present? }
2017-10-10 01:39:20 +08:00
EDITOR_CONTENTS_GAURD = - > { @editor_contents . present? }
EDITOR_SELECTION_GAURD = - > { @editor_contents . present? }
2015-01-08 01:54:38 +08:00
def initialize ( root_account , context , controller , opts = { } )
@root_account = root_account
@context = context
@controller = controller
2016-10-28 03:57:01 +08:00
@request = controller . request if controller
2015-01-08 01:54:38 +08:00
opts . each { | opt , val | instance_variable_set ( " @ #{ opt } " , val ) }
end
def lti_helper
2017-02-25 04:02:00 +08:00
@lti_helper || = Lti :: SubstitutionsHelper . new ( @context , @root_account , @current_user , @tool )
2015-01-08 01:54:38 +08:00
end
def current_user = ( current_user )
@lti_helper = nil
@current_user = current_user
end
def [] ( key )
k = ( key [ 0 ] == '$' && key ) || " $ #{ key } "
2015-05-14 01:00:18 +08:00
if ( expansion = self . class . expansions [ k . respond_to? ( :to_sym ) && k . to_sym ] )
2015-01-08 01:54:38 +08:00
expansion . expand ( self )
end
end
def expand_variables! ( var_hash )
var_hash . update ( var_hash ) do | _ , v |
2015-05-14 01:00:18 +08:00
if ( expansion = v . respond_to? ( :to_sym ) && self . class . expansions [ v . to_sym ] )
2015-01-08 01:54:38 +08:00
expansion . expand ( self )
2015-05-14 01:00:18 +08:00
elsif v . respond_to? ( :to_s ) && v . to_s =~ SUBSTRING_REGEX
expand_substring_variables ( v )
2015-01-08 01:54:38 +08:00
else
v
end
end
end
2017-02-08 04:51:01 +08:00
def enabled_capability_params ( enabled_capabilities )
enabled_capabilities . each_with_object ( { } ) do | capability , hash |
if ( expansion = capability . respond_to? ( :to_sym ) && self . class . expansions [ " $ #{ capability } " . to_sym ] )
2017-05-04 04:15:23 +08:00
value = expansion . expand ( self )
hash [ expansion . default_name ] = value if expansion . default_name . present? && value != " $ #{ capability } "
2017-02-08 04:51:01 +08:00
end
end
end
2017-07-06 02:15:05 +08:00
# The title of the context
# @launch_parameter context_title
# @example
# ```
# Example Course
# ```
register_expansion 'Context.title' , [ ] ,
- > { @context . name } ,
default_name : 'context_title'
2017-10-10 01:39:20 +08:00
# The contents of the text editor associated with the content item launch.
# @launch_parameter com_instructure_editor_contents
# @example
# ```
# "This text was in the editor"
# ```
register_expansion 'com.instructure.Editor.contents' , [ ] ,
- > { @editor_contents } ,
EDITOR_CONTENTS_GAURD ,
default_name : 'com_instructure_editor_contents'
# The contents the user has selected in the text editor associated
# with the content item launch.
# @launch_parameter com_instructure_editor_selection
# @example
# ```
# "this text was selected by the user"
# ```
register_expansion 'com.instructure.Editor.selection' , [ ] ,
- > { @editor_selection } ,
EDITOR_SELECTION_GAURD ,
default_name : 'com_instructure_editor_selection'
2017-07-20 02:52:15 +08:00
# A token that can be used for frontend communication between an LTI tool
# and Canvas via the Window.postMessage API
# @launch_parameter com_instructure_post_message_token
# @example
# ```
# 9ae4170c-6b64-444d-9246-0b7dedd5f560
# ```
register_expansion 'com.instructure.PostMessageToken' , [ ] ,
- > { @post_message_token || @launch . post_message_token } ,
MESSAGE_TOKEN_GUARD ,
default_name : 'com_instructure_post_message_token'
2017-07-10 23:28:06 +08:00
# The LTI assignment id of an assignment. This value corresponds with
# the `ext_lti_assignment_id` send in various launches and webhooks.
# @launch_parameter com_instructure_assignment_lti_id
# @example
# ```
# 9ae4170c-6b64-444d-9246-0b7dedd5f560
# ```
register_expansion 'com.instructure.Assignment.lti.id' , [ ] ,
- > do
if @assignment
@assignment . lti_context_id
2017-08-16 08:38:29 +08:00
elsif @originality_report
@originality_report . submission . assignment . lti_context_id
2017-07-10 23:28:06 +08:00
elsif @secure_params . present?
Lti :: Security . decoded_lti_assignment_id ( @secure_params )
end
end ,
LTI_ASSIGN_ID ,
default_name : 'com_instructure_assignment_lti_id'
2017-06-21 03:00:17 +08:00
# The Canvas id of the Originality Report associated
# with the launch.
# @launch_parameter com_instructure_originality_report_id
# @example
# ```
# 23
# ```
register_expansion 'com.instructure.OriginalityReport.id' , [ ] ,
- > do
2017-08-16 08:38:29 +08:00
@originality_report . id
2017-06-21 03:00:17 +08:00
end ,
2017-08-16 08:38:29 +08:00
ORIGINALITY_REPORT_GUARD ,
2017-06-21 03:00:17 +08:00
default_name : 'com_instructure_originality_report_id'
# The Canvas id of the submission associated with the
# launch.
# @launch_parameter com_instructure_submission_id
# @example
# ```
# 23
# ```
register_expansion 'com.instructure.Submission.id' , [ ] ,
2017-08-16 08:38:29 +08:00
- > { @originality_report . submission . id } ,
ORIGINALITY_REPORT_GUARD ,
2017-06-21 03:00:17 +08:00
default_name : 'com_instructure_submission_id'
# The Canvas id of the file associated with the submission
# in the launch.
# @launch_parameter com_instructure_file_id
# @example
# ```
# 23
# ```
register_expansion 'com.instructure.File.id' , [ ] ,
2017-08-16 08:38:29 +08:00
- > { @originality_report . attachment . id } ,
2017-12-13 02:02:29 +08:00
ORIGINALITY_REPORT_ATTACHMENT_GUARD ,
2017-06-21 03:00:17 +08:00
default_name : 'com_instructure_file_id'
2017-05-04 04:15:23 +08:00
# the LIS identifier for the course offering
# @launch_parameter lis_course_offering_sourcedid
# @example
# ```
# 1234
# ```
register_expansion 'CourseOffering.sourcedId' , [ ] ,
- > { @context . sis_source_id } ,
COURSE_GUARD ,
default_name : 'lis_course_offering_sourcedid'
2017-02-15 07:17:07 +08:00
# an opaque identifier that uniquely identifies the context of the tool launch
# @launch_parameter context_id
2017-02-09 06:35:31 +08:00
# @example
# ```
# cdca1fe2c392a208bd8a657f8865ddb9ca359534
# ```
register_expansion 'Context.id' , [ ] ,
- > { Lti :: Asset . opaque_identifier_for ( @context ) } ,
default_name : 'context_id'
2017-06-21 03:48:02 +08:00
# The sourced Id of the context.
# @example
# ```
# 1234
# ```
register_expansion 'Context.sourcedId' , [ ] ,
- > { @context . sis_source_id }
2017-02-08 04:51:01 +08:00
# communicates the kind of browser window/frame where the Canvas has launched a tool
2017-02-15 07:17:07 +08:00
# @launch_parameter launch_presentation_document_target
2017-02-08 04:51:01 +08:00
# @example
# ```
2017-02-15 07:17:07 +08:00
# iframe
2017-02-08 04:51:01 +08:00
# ```
register_expansion 'Message.documentTarget' , [ ] ,
- > { IMS :: LTI :: Models :: Messages :: Message :: LAUNCH_TARGET_IFRAME } ,
default_name : 'launch_presentation_document_target'
# returns the current locale
2017-02-15 07:17:07 +08:00
# @launch_parameter launch_presentation_locale
2017-02-08 04:51:01 +08:00
# @example
# ```
# de
# ```
register_expansion 'Message.locale' , [ ] ,
- > { I18n . locale || I18n . default_locale } ,
default_name : 'launch_presentation_locale'
# returns a unique identifier for the Tool Consumer (Canvas)
2017-02-15 07:17:07 +08:00
# @launch_parameter tool_consumer_instance_guid
2017-02-08 04:51:01 +08:00
# @example
# ```
# 0dWtgJjjFWRNT41WdQMvrleejGgv7AynCVm3lmZ2:canvas-lms
# ```
register_expansion 'ToolConsumerInstance.guid' , [ ] ,
- > { @root_account . lti_guid } ,
default_name : 'tool_consumer_instance_guid'
2016-03-11 12:49:32 +08:00
# returns the canvas domain for the current context.
# @example
# ```
# canvas.instructure.com
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.api.domain' , [ ] ,
2016-10-28 03:57:01 +08:00
- > { HostUrl . context_host ( @root_account , @request . host ) } ,
CONTROLLER_GUARD
2015-01-08 01:54:38 +08:00
2016-06-25 00:21:16 +08:00
# returns the api url for the members of the collaboration
# @example
# ```
# https://canvas.instructure.com/api/v1/collaborations/1/members
# ```
register_expansion 'Canvas.api.collaborationMembers.url' , [ ] ,
- > { @controller . api_v1_collaboration_members_url ( @collaboration ) } ,
2016-10-28 03:57:01 +08:00
CONTROLLER_GUARD ,
2016-06-25 00:21:16 +08:00
COLLABORATION_GUARD
2016-03-11 12:49:32 +08:00
# returns the base URL for the current context.
# @example
# ```
# https://canvas.instructure.com
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.api.baseUrl' , [ ] ,
2016-10-28 03:57:01 +08:00
- > { " #{ @request . scheme } :// #{ HostUrl . context_host ( @root_account , @request . host ) } " } ,
CONTROLLER_GUARD
2015-01-08 01:54:38 +08:00
2017-03-29 05:03:07 +08:00
# returns the URL for the membership service associated with the current context.
#
# This variable is for future use only. Complete support for the IMS Membership Service has not been added to Canvas. This will be updated when we fully support and certify the IMS Membership Service.
2016-06-16 02:10:32 +08:00
# @example
# ```
# https://canvas.instructure.com/api/lti/courses/1/membership_service
# ```
register_expansion 'ToolProxyBinding.memberships.url' , [ ] ,
2016-04-29 03:29:56 +08:00
- > { @controller . polymorphic_url ( [ @context , :membership_service ] ) } ,
2016-10-28 03:57:01 +08:00
CONTROLLER_GUARD ,
2016-04-29 03:29:56 +08:00
- > { @context . is_a? ( Course ) || @context . is_a? ( Group ) }
2016-03-31 06:59:58 +08:00
2016-03-11 12:49:32 +08:00
# returns the account id for the current context.
# @example
# ```
# 1234
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.account.id' , [ ] ,
- > { lti_helper . account . id }
2016-03-11 12:49:32 +08:00
# returns the account name for the current context.
# @example
# ```
# School Name
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.account.name' , [ ] ,
- > { lti_helper . account . name }
2017-02-15 07:17:07 +08:00
# returns the account's sis source id for the current context.
2016-12-06 06:06:35 +08:00
# @example
# ```
# sis_account_id_1234
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.account.sisSourceId' , [ ] ,
- > { lti_helper . account . sis_source_id }
2016-03-11 12:49:32 +08:00
# returns the Root Account ID for the current context.
# @example
# ```
# 1234
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.rootAccount.id' , [ ] ,
- > { @root_account . id }
2017-02-15 07:17:07 +08:00
# returns the root account's sis source id for the current context.
2016-12-06 06:06:35 +08:00
# @example
# ```
# sis_account_id_1234
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.rootAccount.sisSourceId' , [ ] ,
- > { @root_account . sis_source_id }
2017-02-15 07:17:07 +08:00
# returns the URL for the external tool that was launched. Only available for LTI 1.
2016-03-11 12:49:32 +08:00
# @example
# ```
# http://example.url/path
# ```
2015-04-25 00:14:02 +08:00
register_expansion 'Canvas.externalTool.url' , [ ] ,
2016-08-24 03:22:00 +08:00
- > { @controller . named_context_url ( @tool . context , :api_v1_context_external_tools_update_url ,
2015-04-25 00:14:02 +08:00
@tool . id , include_host : true ) } ,
2016-10-28 03:57:01 +08:00
CONTROLLER_GUARD ,
2015-04-25 00:14:02 +08:00
LTI1_GUARD
2017-09-21 04:17:31 +08:00
# returns the URL to retrieve the brand config JSON for the launching context.
# @example
# ```
# http://example.url/path.json
# ```
register_expansion 'com.instructure.brandConfigJSON.url' , [ ] ,
2017-10-17 06:07:03 +08:00
- > { @controller . active_brand_config_url ( 'json' ) } ,
2017-09-21 04:17:31 +08:00
CONTROLLER_GUARD
2017-10-04 22:01:25 +08:00
# returns the brand config JSON itself for the launching context.
# @example
# ```
# {"ic-brand-primary-darkened-5":"#0087D7"}
# ```
register_expansion 'com.instructure.brandConfigJSON' , [ ] ,
- > { @controller . active_brand_config . try ( :to_json ) } ,
CONTROLLER_GUARD
2017-09-21 04:17:31 +08:00
# returns the URL to retrieve the brand config javascript for the launching context.
# This URL should be used as the src attribute for a script tag on the external tool
# provider's web page. It is configured to be used with the [instructure-ui node module](https://github.com/instructure/instructure-ui).
# More information on on how to use instructure ui react components can be found [here](http://instructure.github.io/instructure-ui/).
# @example
# ```
# http://example.url/path.js
# ```
register_expansion 'com.instructure.brandConfigJS.url' , [ ] ,
2017-10-17 06:07:03 +08:00
- > { @controller . active_brand_config_url ( 'js' ) } ,
2017-09-21 04:17:31 +08:00
CONTROLLER_GUARD
2017-02-15 07:17:07 +08:00
# returns the URL for the common css file.
2016-03-11 12:49:32 +08:00
# @example
# ```
# http://example.url/path.css
# ```
2015-07-11 00:28:43 +08:00
register_expansion 'Canvas.css.common' , [ ] ,
2018-01-16 13:49:45 +08:00
- > { URI . parse ( @request . url ) .
merge ( @controller . view_context . stylesheet_path ( @controller . css_url_for ( :common ) ) ) . to_s } ,
2016-10-28 03:57:01 +08:00
CONTROLLER_GUARD
2015-04-25 00:14:02 +08:00
2016-03-11 12:49:32 +08:00
# returns the shard id for the current context.
# @example
# ```
# 1234
# ```
2015-08-04 07:01:36 +08:00
register_expansion 'Canvas.shard.id' , [ ] ,
- > { Shard . current . id }
2016-03-11 12:49:32 +08:00
# returns the root account's global id for the current context.
2017-02-15 07:17:07 +08:00
# @duplicates Canvas.user.globalId
2016-03-11 12:49:32 +08:00
# @example
# ```
# 123400000000123
# ```
2015-08-04 07:01:36 +08:00
register_expansion 'Canvas.root_account.global_id' , [ ] ,
- > { @root_account . global_id }
2015-01-08 01:54:38 +08:00
2016-03-11 12:49:32 +08:00
# returns the root account id for the current context.
# @deprecated
# @example
# ```
# 1234
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.root_account.id' , [ ] ,
- > { @root_account . id }
2017-02-15 04:24:04 +08:00
# returns the account uuid for the current context.
# @example
# ```
# Ioe3sJPt0KZp9Pw6xAvcHuLCl0z4TvPKP0iIOLbo
# ```
register_expansion 'vnd.Canvas.root_account.uuid' , [ ] ,
- > { @root_account . uuid } ,
default_name : 'vnd_canvas_root_account_uuid'
2016-03-11 12:49:32 +08:00
# returns the root account sis source id for the current context.
# @deprecated
# @example
# ```
# 1234
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.root_account.sisSourceId' , [ ] ,
- > { @root_account . sis_source_id }
2016-03-11 12:49:32 +08:00
# returns the current course id.
# @example
# ```
# 1234
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.course.id' , [ ] ,
- > { @context . id } ,
COURSE_GUARD
2017-05-02 23:06:26 +08:00
# returns the current course uuid.
# @example
# ```
# S3vhRY2pBzG8iPdZ3OBPsPrEnqn5sdRoJOLXGbwc
# ```
register_expansion 'vnd.instructure.Course.uuid' , [ ] ,
- > { @context . uuid } ,
COURSE_GUARD
2017-01-31 06:36:37 +08:00
# returns the current course name.
# @example
# ```
# Course Name
# ```
register_expansion 'Canvas.course.name' , [ ] ,
- > { @context . name } ,
COURSE_GUARD
2016-03-11 12:49:32 +08:00
# returns the current course sis source id.
# @example
# ```
# 1234
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.course.sisSourceId' , [ ] ,
- > { @context . sis_source_id } ,
COURSE_GUARD
2016-03-11 12:49:32 +08:00
# returns the current course start date.
# @example
# ```
2016-12-06 06:06:35 +08:00
# YYY-MM-DD HH:MM:SS -0700
2016-03-11 12:49:32 +08:00
# ```
2015-04-23 23:08:26 +08:00
register_expansion 'Canvas.course.startAt' , [ ] ,
- > { @context . start_at } ,
COURSE_GUARD
2016-11-11 06:56:37 +08:00
# returns the current course workflow state. Workflow states of "claimed" or "created"
# indicate an unpublished course.
# @example
# ```
# active
# ```
register_expansion 'Canvas.course.workflowState' , [ ] ,
- > { @context . workflow_state } ,
COURSE_GUARD
2016-03-11 12:49:32 +08:00
# returns the current course's term start date.
# @example
# ```
2016-12-06 06:06:35 +08:00
# YYY-MM-DD HH:MM:SS -0700
2016-03-11 12:49:32 +08:00
# ```
2015-04-23 23:08:26 +08:00
register_expansion 'Canvas.term.startAt' , [ ] ,
- > { @context . enrollment_term . start_at } ,
TERM_START_DATE_GUARD
2017-11-18 01:23:54 +08:00
# returns the current course's term name.
# @example
# ```
# W1 2017
# ```
register_expansion 'Canvas.term.name' , [ ] ,
- > { @context . enrollment_term . name } ,
TERM_NAME_GUARD ,
default_name : 'canvas_term_name'
2016-12-06 06:06:35 +08:00
# returns the current course sis source id
# to return the section source id use Canvas.course.sectionIds
2017-02-15 07:17:07 +08:00
# @launch_parameter lis_course_section_sourcedid
2016-03-11 12:49:32 +08:00
# @example
# ```
# 1234
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'CourseSection.sourcedId' , [ ] ,
- > { @context . sis_source_id } ,
2017-02-08 04:51:01 +08:00
COURSE_GUARD ,
default_name : 'lis_course_section_sourcedid'
2015-01-08 01:54:38 +08:00
2016-03-11 12:49:32 +08:00
# returns the current course enrollment state
# @example
# ```
2016-12-06 06:06:35 +08:00
# active
2016-03-11 12:49:32 +08:00
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.enrollment.enrollmentState' , [ ] ,
- > { lti_helper . enrollment_state } ,
COURSE_GUARD
2018-08-16 02:37:55 +08:00
# returns true if the assignment has anonymous grading
# enabled.
# @example
# ```
# true
# ```
register_expansion 'com.instructure.Assignment.anonymous_grading' , [ ] ,
- > { @assignment . anonymous_grading } ,
ASSIGNMENT_GUARD ,
default_name : 'com_instructure_assignment_anonymous_grading'
2018-07-27 23:31:03 +08:00
# returns the current course membership roles
# using the LIS v2 vocabulary.
# @example
# ```
# http://purl.imsglobal.org/vocab/lis/v2/institution/person#Student
# ```
register_expansion 'com.Instructure.membership.roles' , [ ] ,
- > { lti_helper . current_canvas_roles_lis_v2 } ,
ROLES_GUARD ,
default_name : 'com_instructure_membership_roles'
2016-03-11 12:49:32 +08:00
# returns the current course membership roles
# @example
# ```
2016-12-06 06:06:35 +08:00
# StudentEnrollment
2016-03-11 12:49:32 +08:00
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.membership.roles' , [ ] ,
- > { lti_helper . current_canvas_roles } ,
2018-02-14 01:30:06 +08:00
ROLES_GUARD ,
default_name : 'canvas_membership_roles'
2015-01-08 01:54:38 +08:00
2016-03-11 12:49:32 +08:00
# This is a list of IMS LIS roles should have a different key
2016-12-06 06:06:35 +08:00
# @example
# ```
# urn:lti:sysrole:ims/lis/None
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.membership.concludedRoles' , [ ] ,
- > { lti_helper . concluded_lis_roles } ,
COURSE_GUARD
2017-12-21 03:46:18 +08:00
# With respect to the current course, returns the context ids of the courses from which content has been copied (excludes cartridge imports).
2017-02-15 07:17:07 +08:00
#
2016-03-11 12:49:32 +08:00
# @example
# ```
2017-12-21 03:46:18 +08:00
# 1234,4567
2016-03-11 12:49:32 +08:00
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.course.previousContextIds' , [ ] ,
- > { lti_helper . previous_lti_context_ids } ,
COURSE_GUARD
2017-12-21 03:46:18 +08:00
# With respect to the current course, recursively returns the context ids of the courses from which content has been copied (excludes cartridge imports).
#
# @example
# ```
# 1234,4567
# ```
register_expansion 'Canvas.course.previousContextIds.recursive' , [ ] ,
- > { lti_helper . recursively_fetch_previous_lti_context_ids } ,
COURSE_GUARD
# With respect to the current course, returns the course ids of the courses from which content has been copied (excludes cartridge imports).
2017-02-15 07:17:07 +08:00
#
2016-03-11 12:49:32 +08:00
# @example
# ```
# 1234
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.course.previousCourseIds' , [ ] ,
- > { lti_helper . previous_course_ids } ,
COURSE_GUARD
2017-02-15 07:17:07 +08:00
# Returns the full name of the launching user.
# @launch_parameter lis_person_name_full
2016-12-06 06:06:35 +08:00
# @example
# ```
# John Doe
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Person.name.full' , [ ] ,
- > { @current_user . name } ,
2017-02-08 04:51:01 +08:00
USER_GUARD ,
default_name : 'lis_person_name_full'
2015-01-08 01:54:38 +08:00
2017-12-05 03:32:53 +08:00
# Returns the display name of the launching user.
# @launch_parameter lis_person_name_full
# @example
# ```
# John Doe
# ```
register_expansion 'Person.name.display' , [ ] ,
- > { @current_user . short_name } ,
USER_GUARD ,
default_name : 'person_name_display'
2017-02-15 07:17:07 +08:00
# Returns the last name of the launching user.
# @launch_parameter lis_person_name_family
2016-12-06 06:06:35 +08:00
# @example
# ```
# Doe
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Person.name.family' , [ ] ,
- > { @current_user . last_name } ,
2017-02-08 04:51:01 +08:00
USER_GUARD ,
default_name : 'lis_person_name_family'
2015-01-08 01:54:38 +08:00
2017-02-15 07:17:07 +08:00
# Returns the first name of the launching user.
# @launch_parameter lis_person_name_given
2016-12-06 06:06:35 +08:00
# @example
# ```
# John
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Person.name.given' , [ ] ,
- > { @current_user . first_name } ,
2017-02-08 04:51:01 +08:00
USER_GUARD ,
default_name : 'lis_person_name_given'
2015-01-08 01:54:38 +08:00
2018-10-19 06:06:29 +08:00
# Returns the sortable name of the launching user.
# @launch_parameter com_instructure_person_name_sortable
# @example
# ```
# Doe, John
# ```
register_expansion 'com.instructure.Person.name_sortable' , [ ] ,
- > { @current_user . sortable_name } ,
USER_GUARD ,
default_name : 'com_instructure_person_name_sortable'
2017-02-15 07:17:07 +08:00
# Returns the primary email of the launching user.
# @launch_parameter lis_person_contact_email_primary
2016-12-06 06:06:35 +08:00
# @example
# ```
# john.doe@example.com
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Person.email.primary' , [ ] ,
2017-02-25 04:02:00 +08:00
- > { lti_helper . email } ,
2017-02-08 04:51:01 +08:00
USER_GUARD ,
default_name : 'lis_person_contact_email_primary'
2015-01-08 01:54:38 +08:00
2017-01-13 06:22:26 +08:00
2017-02-15 07:17:07 +08:00
# Returns the institution assigned email of the launching user.
2017-01-13 06:22:26 +08:00
# @example
# ```
# john.doe@example.com
# ```
register_expansion 'vnd.Canvas.Person.email.sis' , [ ] ,
2017-02-25 04:02:00 +08:00
- > { lti_helper . sis_email } , SIS_USER_GUARD
2017-01-13 06:22:26 +08:00
2017-02-15 07:17:07 +08:00
# Returns the name of the timezone of the launching user.
2016-12-06 06:06:35 +08:00
# @example
# ```
# America/Denver
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Person.address.timezone' , [ ] ,
- > { Time . zone . tzinfo . name } ,
USER_GUARD
2017-02-15 07:17:07 +08:00
# Returns the profile picture URL of the launching user.
# @launch_parameter user_image
2016-12-06 06:06:35 +08:00
# @example
# ```
# https://example.com/picture.jpg
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'User.image' , [ ] ,
- > { @current_user . avatar_url } ,
2017-02-08 04:51:01 +08:00
USER_GUARD ,
default_name : 'user_image'
2015-01-08 01:54:38 +08:00
2017-02-15 07:17:07 +08:00
# Returns the Canvas user_id of the launching user.
# @duplicates Canvas.user.id
# @launch_parameter user_id
2016-12-06 06:06:35 +08:00
# @example
# ```
# 420000000000042
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'User.id' , [ ] ,
- > { @current_user . id } ,
2017-02-08 04:51:01 +08:00
USER_GUARD ,
default_name : 'user_id'
2015-01-08 01:54:38 +08:00
2017-02-15 07:17:07 +08:00
# Returns the Canvas user_id of the launching user.
# @duplicates User.id
2016-12-06 06:06:35 +08:00
# @example
# ```
# 420000000000042
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.user.id' , [ ] ,
- > { @current_user . id } ,
USER_GUARD
2017-05-02 23:06:26 +08:00
# Returns the Canvas user_uuid of the launching user.
# @duplicates User.uuid
# @example
# ```
# N2ST123dQ9zyhurykTkBfXFa3Vn1RVyaw9Os6vu3
# ```
register_expansion 'vnd.instructure.User.uuid' , [ ] ,
- > { @current_user . uuid } ,
USER_GUARD
2017-02-15 07:17:07 +08:00
# Returns the users preference for high contrast colors (an accessibility feature).
2016-12-06 06:06:35 +08:00
# @example
# ```
# false
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.user.prefersHighContrast' , [ ] ,
- > { @current_user . prefers_high_contrast? ? 'true' : 'false' } ,
USER_GUARD
2018-02-14 03:16:18 +08:00
# returns the Canvas ids of all active groups in the current course.
# @example
# ```
# 23,24,...
# ```
register_expansion 'com.instructure.Course.groupIds' , [ ] ,
- > { @context . groups . active . pluck ( :id ) . join ( ',' ) } ,
COURSE_GUARD ,
default_name : 'com_instructure_course_groupids'
2016-06-16 02:10:32 +08:00
# returns the context ids for the groups the user belongs to in the course.
# @example
# ```
# 1c16f0de65a080803785ecb3097da99872616f0d,d4d8d6ae1611e2c7581ce1b2f5c58019d928b79d,...
# ```
register_expansion 'Canvas.group.contextIds' , [ ] ,
- > { @current_user . groups . active . where ( context_type : 'Course' , context_id : @context . id ) . map do | g |
Lti :: Asset . opaque_identifier_for ( g )
end . join ( ',' ) } ,
- > { @current_user && @context . is_a? ( Course ) }
2017-02-15 07:17:07 +08:00
# Returns the [IMS LTI membership service](https://www.imsglobal.org/specs/ltimemv1p0/specification-3) roles for filtering via query parameters.
# @launch_parameter roles
2016-12-06 06:06:35 +08:00
# @example
# ```
# http://purl.imsglobal.org/vocab/lis/v2/institution/person#Administrator
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Membership.role' , [ ] ,
- > { lti_helper . all_roles ( 'lis2' ) } ,
2017-02-08 04:51:01 +08:00
USER_GUARD ,
default_name : 'roles'
2015-01-08 01:54:38 +08:00
2017-02-15 07:17:07 +08:00
# Returns list of [LIS role full URNs](https://www.imsglobal.org/specs/ltiv1p0/implementation-guide#toc-16).
2018-02-24 12:19:34 +08:00
# Note that this will include all roles the user has.
# There are 3 different levels of roles defined: Context, Institution, System.
# Context role urns start with "urn:lti:ims" and include roles for the context where the launch occurred.
# Institution role urns start with "urn:lti:instrole" and include roles the user has in the institution. This
# will include roles they have in other courses or at the account level. Note that there is not a TA role at the
# Institution level. Instead Users with a TA enrollment will have an institution role of Instructor.
# System role urns start with "urn:lti:sysrole" and include roles for the entire system.
2017-02-15 07:17:07 +08:00
# @duplicates ext_roles which is sent by default
2016-12-06 06:06:35 +08:00
# @example
# ```
2017-02-15 07:17:07 +08:00
# urn:lti:instrole:ims/lis/Administrator,urn:lti:instrole:ims/lis/Instructor,urn:lti:sysrole:ims/lis/SysAdmin,urn:lti:sysrole:ims/lis/User
2016-12-06 06:06:35 +08:00
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.xuser.allRoles' , [ ] ,
- > { lti_helper . all_roles }
2017-02-15 07:17:07 +08:00
# Returns the Canvas global user_id of the launching user.
# @duplicates Canvas.root_account.global_id
2016-12-06 06:06:35 +08:00
# @example
# ```
# 420000000000042
# ```
2015-10-22 05:03:34 +08:00
register_expansion 'Canvas.user.globalId' , [ ] ,
- > { @current_user . global_id } ,
USER_GUARD
2017-02-15 07:17:07 +08:00
# Returns true for root account admins and false for all other roles.
2016-12-06 06:06:35 +08:00
# @example
# ```
# true
# ```
2016-11-17 23:36:15 +08:00
register_expansion 'Canvas.user.isRootAccountAdmin' , [ ] ,
- > { @current_user . roles ( @root_account ) . include? 'root_admin' } ,
USER_GUARD
2017-02-15 07:17:07 +08:00
# Username/Login ID for the primary pseudonym for the user for the account.
# This may not be the pseudonym the user is actually logged in with.
# @duplicates Canvas.user.loginId
# @example
2016-12-06 06:06:35 +08:00
# ```
# jdoe
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'User.username' , [ ] ,
- > { sis_pseudonym . unique_id } ,
PSEUDONYM_GUARD
2017-02-15 07:17:07 +08:00
# Username/Login ID for the primary pseudonym for the user for the account.
# This may not be the pseudonym the user is actually logged in with.
# @duplicates User.username
# @example
2016-12-06 06:06:35 +08:00
# ```
# jdoe
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.user.loginId' , [ ] ,
- > { sis_pseudonym . unique_id } ,
PSEUDONYM_GUARD
2016-12-06 06:06:35 +08:00
# Returns the sis source id for the primary pseudonym for the user for the account
2017-02-15 07:17:07 +08:00
# This may not be the pseudonym the user is actually logged in with.
# @duplicates Person.sourcedId
# @example
2016-12-06 06:06:35 +08:00
# ```
# sis_user_42
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.user.sisSourceId' , [ ] ,
- > { sis_pseudonym . sis_user_id } ,
PSEUDONYM_GUARD
2016-12-06 06:06:35 +08:00
# Returns the integration id for the primary pseudonym for the user for the account
2017-02-15 07:17:07 +08:00
# This may not be the pseudonym the user is actually logged in with.
# @example
2016-12-06 06:06:35 +08:00
# ```
# integration_user_42
# ```
2016-01-23 05:43:11 +08:00
register_expansion 'Canvas.user.sisIntegrationId' , [ ] ,
- > { sis_pseudonym . integration_id } ,
PSEUDONYM_GUARD
2016-12-06 06:06:35 +08:00
# Returns the sis source id for the primary pseudonym for the user for the account
2017-02-15 07:17:07 +08:00
# This may not be the pseudonym the user is actually logged in with.
# @duplicates Canvas.user.sisSourceId
# @example
2016-12-06 06:06:35 +08:00
# ```
# sis_user_42
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Person.sourcedId' , [ ] ,
- > { sis_pseudonym . sis_user_id } ,
2017-02-08 04:51:01 +08:00
PSEUDONYM_GUARD ,
default_name : 'lis_person_sourcedid'
2015-01-08 01:54:38 +08:00
2016-12-06 06:06:35 +08:00
# Returns the logout service url for the user.
# This is the pseudonym the user is actually logged in as.
# It may not hold all the sis info needed in other launch substitutions.
2017-02-15 07:17:07 +08:00
# @example
2016-12-06 06:06:35 +08:00
# ```
2017-02-15 07:17:07 +08:00
# https://<domain>.instructure.com/api/lti/v1/logout_service/<external_tool_id>-<user_id>-<current_unix_timestamp>-<opaque_string>
2016-12-06 06:06:35 +08:00
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.logoutService.url' , [ ] ,
- > { @controller . lti_logout_service_url ( Lti :: LogoutService . create_token ( @tool , @current_pseudonym ) ) } ,
2016-10-28 03:57:01 +08:00
CONTROLLER_GUARD ,
2015-01-08 01:54:38 +08:00
- > { @current_pseudonym && @tool }
2016-12-06 06:06:35 +08:00
# Returns the Canvas user_id for the masquerading user.
# This is the pseudonym the user is actually logged in as.
# It may not hold all the sis info needed in other launch substitutions.
2017-02-15 07:17:07 +08:00
#
# @example
2016-12-06 06:06:35 +08:00
# ```
# 420000000000042
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.masqueradingUser.id' , [ ] ,
2015-05-12 01:05:45 +08:00
- > { @controller . logged_in_user . id } ,
MASQUERADING_GUARD
2015-01-08 01:54:38 +08:00
2016-12-06 06:06:35 +08:00
# Returns the 40 character opaque user_id for masquerading user.
# This is the pseudonym the user is actually logged in as.
# It may not hold all the sis info needed in other launch substitutions.
2017-02-15 07:17:07 +08:00
#
# @example
2016-12-06 06:06:35 +08:00
# ```
# da12345678cb37ba1e522fc7c5ef086b7704eff9
# ```
2015-04-28 03:41:05 +08:00
register_expansion 'Canvas.masqueradingUser.userId' , [ ] ,
- > { @tool . opaque_identifier_for ( @controller . logged_in_user ) } ,
2015-05-12 01:05:45 +08:00
MASQUERADING_GUARD
2015-04-28 03:41:05 +08:00
2016-12-06 06:06:35 +08:00
# Returns the xapi url for the user.
2017-02-15 07:17:07 +08:00
# @example
2016-12-06 06:06:35 +08:00
# ```
# https://<domain>.instructure.com/api/lti/v1/xapi/<external_tool_id>-<user_id>-<course_id>-<current_unix_timestamp>-<opaque_id>
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.xapi.url' , [ ] ,
2015-01-28 04:33:11 +08:00
- > { @controller . lti_xapi_url ( Lti :: AnalyticsService . create_token ( @tool , @current_user , @context ) ) } ,
- > { @current_user && @context . is_a? ( Course ) && @tool }
2016-12-06 06:06:35 +08:00
# Returns the caliper url for the user.
2017-02-15 07:17:07 +08:00
# @example
2016-12-06 06:06:35 +08:00
# ```
# https://<domain>.instructure.com/api/lti/v1/caliper/<external_tool_id>-<user_id>-<course_id>-<current_unix_timestamp>-<opaque_id>
# ```
2015-02-24 06:49:19 +08:00
register_expansion 'Caliper.url' , [ ] ,
2015-01-28 04:33:11 +08:00
- > { @controller . lti_caliper_url ( Lti :: AnalyticsService . create_token ( @tool , @current_user , @context ) ) } ,
2016-10-28 03:57:01 +08:00
CONTROLLER_GUARD ,
2015-01-08 01:54:38 +08:00
- > { @current_user && @context . is_a? ( Course ) && @tool }
2016-12-06 06:06:35 +08:00
# Returns a comma separated list of section_id's that the user is enrolled in.
2017-02-15 07:17:07 +08:00
#
# @example
2016-12-06 06:06:35 +08:00
# ```
# 42, 43
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.course.sectionIds' , [ ] ,
- > { lti_helper . section_ids } ,
ENROLLMENT_GUARD
2016-12-06 06:06:35 +08:00
# Returns a comma separated list of section sis_id's that the user is enrolled in.
2017-02-15 07:17:07 +08:00
#
# @example
2016-12-06 06:06:35 +08:00
# ```
# section_sis_id_1, section_sis_id_2
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.course.sectionSisSourceIds' , [ ] ,
- > { lti_helper . section_sis_ids } ,
ENROLLMENT_GUARD
2017-05-04 02:27:39 +08:00
# Returns the course code
#
# @example
# ```
2017-05-04 04:15:23 +08:00
# CS 124
2017-05-04 02:27:39 +08:00
# ```
register_expansion 'com.instructure.contextLabel' , [ ] ,
- > { @context . course_code } ,
COURSE_GUARD ,
default_name : 'context_label'
2016-12-06 06:06:35 +08:00
# Returns the module_id that the module item was launched from.
2017-02-15 07:17:07 +08:00
#
# @example
2016-12-06 06:06:35 +08:00
# ```
# 1234
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.module.id' , [ ] ,
2015-06-26 04:56:13 +08:00
- > {
@content_tag . context_module_id
} ,
2015-01-08 01:54:38 +08:00
CONTENT_TAG_GUARD
2016-12-06 06:06:35 +08:00
# Returns the module_item_id of the module item that was launched.
2017-02-15 07:17:07 +08:00
#
# @example
2016-12-06 06:06:35 +08:00
# ```
# 1234
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.moduleItem.id' , [ ] ,
2015-06-26 04:56:13 +08:00
- > {
@content_tag . id
} ,
2015-01-08 01:54:38 +08:00
CONTENT_TAG_GUARD
2016-12-06 06:06:35 +08:00
# Returns the assignment_id of the assignment that was launched.
2017-02-15 07:17:07 +08:00
#
# @example
2016-12-06 06:06:35 +08:00
# ```
# 1234
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.assignment.id' , [ ] ,
- > { @assignment . id } ,
ASSIGNMENT_GUARD
2018-01-31 00:13:25 +08:00
# Returns the Canvas id of the group the current user is in if launching
# from a group assignment.
#
# @example
# ```
# 481
# ```
register_expansion 'com.instructure.Group.id' , [ ] ,
2018-09-04 23:02:03 +08:00
- > { @assignment . group_category && ( @assignment . group_category . groups & @current_user . groups ) . first & . id } ,
2018-01-31 00:13:25 +08:00
USER_GUARD ,
ASSIGNMENT_GUARD ,
default_name : 'vnd_canvas_group_id'
# Returns the name of the group the current user is in if launching
# from a group assignment.
#
# @example
# ```
# Group One
# ```
register_expansion 'com.instructure.Group.name' , [ ] ,
2018-09-04 23:02:03 +08:00
- > { @assignment . group_category && ( @assignment . group_category . groups & @current_user . groups ) . first & . name } ,
2018-01-31 00:13:25 +08:00
USER_GUARD ,
ASSIGNMENT_GUARD ,
default_name : 'vnd_canvas_group_name'
2016-12-06 06:06:35 +08:00
# Returns the title of the assignment that was launched.
2017-02-15 07:17:07 +08:00
#
# @example
2016-12-06 06:06:35 +08:00
# ```
# Deep thought experiment
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.assignment.title' , [ ] ,
- > { @assignment . title } ,
ASSIGNMENT_GUARD
2016-12-06 06:06:35 +08:00
# Returns the points possible of the assignment that was launched.
2017-02-15 07:17:07 +08:00
#
# @example
2016-12-06 06:06:35 +08:00
# ```
# 100
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'Canvas.assignment.pointsPossible' , [ ] ,
2016-05-11 22:03:11 +08:00
- > { TextHelper . round_if_whole ( @assignment . points_possible ) } ,
2015-01-08 01:54:38 +08:00
ASSIGNMENT_GUARD
2016-12-06 06:06:35 +08:00
2016-03-11 12:49:32 +08:00
# @deprecated in favor of ISO8601
2015-03-13 06:29:38 +08:00
register_expansion 'Canvas.assignment.unlockAt' , [ ] ,
- > { @assignment . unlock_at } ,
ASSIGNMENT_GUARD
2016-03-11 12:49:32 +08:00
# @deprecated in favor of ISO8601
2015-03-13 06:29:38 +08:00
register_expansion 'Canvas.assignment.lockAt' , [ ] ,
- > { @assignment . lock_at } ,
ASSIGNMENT_GUARD
2016-03-11 12:49:32 +08:00
# @deprecated in favor of ISO8601
2015-03-13 06:29:38 +08:00
register_expansion 'Canvas.assignment.dueAt' , [ ] ,
- > { @assignment . due_at } ,
ASSIGNMENT_GUARD
2017-02-15 07:17:07 +08:00
# Returns the `unlock_at` date of the assignment that was launched.
# Only available when launched as an assignment with an `unlock_at` set.
# @example
2016-12-06 06:06:35 +08:00
# ```
# YYYY-MM-DDT07:00:00Z
# ```
2015-08-26 05:07:33 +08:00
register_expansion 'Canvas.assignment.unlockAt.iso8601' , [ ] ,
- > { @assignment . unlock_at . utc . iso8601 } ,
2015-10-20 01:05:17 +08:00
- > { @assignment && @assignment . unlock_at . present? }
2015-08-26 05:07:33 +08:00
2017-02-15 07:17:07 +08:00
# Returns the `lock_at` date of the assignment that was launched.
# Only available when launched as an assignment with a `lock_at` set.
#
# @example
2016-12-06 06:06:35 +08:00
# ```
# YYYY-MM-DDT07:00:00Z
# ```
2015-08-26 05:07:33 +08:00
register_expansion 'Canvas.assignment.lockAt.iso8601' , [ ] ,
- > { @assignment . lock_at . utc . iso8601 } ,
2015-10-20 01:05:17 +08:00
- > { @assignment && @assignment . lock_at . present? }
2015-08-26 05:07:33 +08:00
2017-02-15 07:17:07 +08:00
# Returns the `due_at` date of the assignment that was launched.
# Only available when launched as an assignment with a `due_at` set.
#
# @example
2016-12-06 06:06:35 +08:00
# ```
# YYYY-MM-DDT07:00:00Z
# ```
2015-08-26 05:07:33 +08:00
register_expansion 'Canvas.assignment.dueAt.iso8601' , [ ] ,
- > { @assignment . due_at . utc . iso8601 } ,
2015-10-20 01:05:17 +08:00
- > { @assignment && @assignment . due_at . present? }
2015-08-26 05:07:33 +08:00
2017-02-15 07:17:07 +08:00
# Returns true if the assignment that was launched is published.
2016-12-06 06:06:35 +08:00
# Only available when launched as an assignment.
2017-02-15 07:17:07 +08:00
# @example
2016-12-06 06:06:35 +08:00
# ```
# true
# ```
2016-06-21 11:51:25 +08:00
register_expansion 'Canvas.assignment.published' , [ ] ,
- > { @assignment . workflow_state == 'published' } ,
2016-06-17 01:30:26 +08:00
ASSIGNMENT_GUARD
2016-12-06 06:06:35 +08:00
# Returns the endpoint url for accessing link-level tool settings
# Only available for LTI 2.0
2017-02-15 07:17:07 +08:00
# @example
2016-12-06 06:06:35 +08:00
# ```
# https://<domain>.instructure.com/api/lti/tool_settings/<link_id>
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'LtiLink.custom.url' , [ ] ,
- > { @controller . show_lti_tool_settings_url ( @tool_setting_link_id ) } ,
2016-10-28 03:57:01 +08:00
CONTROLLER_GUARD ,
2015-01-08 01:54:38 +08:00
- > { @tool_setting_link_id }
2016-12-06 06:06:35 +08:00
# Returns the endpoint url for accessing context-level tool settings
# Only available for LTI 2.0
2017-02-15 07:17:07 +08:00
# @example
2016-12-06 06:06:35 +08:00
# ```
# https://<domain>.instructure.com/api/lti/tool_settings/<binding_id>
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'ToolProxyBinding.custom.url' , [ ] ,
- > { @controller . show_lti_tool_settings_url ( @tool_setting_binding_id ) } ,
2016-10-28 03:57:01 +08:00
CONTROLLER_GUARD ,
2015-01-08 01:54:38 +08:00
- > { @tool_setting_binding_id }
2016-12-06 06:06:35 +08:00
# Returns the endpoint url for accessing system-wide tool settings
# Only available for LTI 2.0
2017-02-15 07:17:07 +08:00
# @example
2016-12-06 06:06:35 +08:00
# ```
# https://<domain>.instructure.com/api/lti/tool_settings/<proxy_id>
# ```
2015-01-08 01:54:38 +08:00
register_expansion 'ToolProxy.custom.url' , [ ] ,
- > { @controller . show_lti_tool_settings_url ( @tool_setting_proxy_id ) } ,
2016-10-28 03:57:01 +08:00
- > { ! ! @controller && @tool_setting_proxy_id }
2015-01-08 01:54:38 +08:00
2017-02-15 07:17:07 +08:00
# Returns the [Tool Consumer Profile](https://www.imsglobal.org/specs/ltiv2p0/implementation-guide#toc-46) url for the tool.
2016-12-06 06:06:35 +08:00
# Only available for LTI 2.0
2017-02-15 07:17:07 +08:00
# @example
2016-12-06 06:06:35 +08:00
# ```
# https://<domain>.instructure.com/api/lti/courses/<course_id>/tool_consumer_profile/<opaque_id>
# https://<domain>.instructure.com/api/lti/accounts/<account_id>/tool_consumer_profile/<opaque_id>
# ```
2015-01-16 02:47:16 +08:00
register_expansion 'ToolConsumerProfile.url' , [ ] ,
2017-06-21 03:48:02 +08:00
- > { @controller . polymorphic_url ( [ @tool . context , :tool_consumer_profile ] ) } ,
2016-10-28 03:57:01 +08:00
CONTROLLER_GUARD ,
2016-06-08 02:45:50 +08:00
- > { @tool && @tool . is_a? ( Lti :: ToolProxy ) }
2015-01-16 02:47:16 +08:00
2017-06-22 05:52:43 +08:00
# The originality report LTI2 service endpoint
# @launch_parameter vnd_canvas_originality_report_url
# @example
# ```
# api/lti/assignments/{assignment_id}/submissions/{submission_id}/originality_report
# ```
register_expansion 'vnd.Canvas.OriginalityReport.url' , [ ] ,
- > do
OriginalityReportsApiController :: SERVICE_DEFINITIONS . find do | s |
s [ :id ] == 'vnd.Canvas.OriginalityReport'
end [ :endpoint ]
end ,
default_name : 'vnd_canvas_originality_report_url'
# The submission LTI2 service endpoint
# @launch_parameter vnd_canvas_submission_url
# @example
# ```
# api/lti/assignments/{assignment_id}/submissions/{submission_id}
# ```
register_expansion 'vnd.Canvas.submission.url' , [ ] ,
- > do
2018-02-17 09:45:47 +08:00
Lti :: SubmissionsApiController :: SERVICE_DEFINITIONS . find do | s |
2017-06-22 05:52:43 +08:00
s [ :id ] == 'vnd.Canvas.submission'
end [ :endpoint ]
end ,
default_name : 'vnd_canvas_submission_url'
# The submission history LTI2 service endpoint
# @launch_parameter vnd_canvas_submission_history_url
# @example
# ```
# api/lti/assignments/{assignment_id}/submissions/{submission_id}/history
# ```
register_expansion 'vnd.Canvas.submission.history.url' , [ ] ,
- > do
2018-02-17 09:45:47 +08:00
Lti :: SubmissionsApiController :: SERVICE_DEFINITIONS . find do | s |
2017-06-22 05:52:43 +08:00
s [ :id ] == 'vnd.Canvas.submission.history'
end [ :endpoint ]
end ,
default_name : 'vnd_canvas_submission_history_url'
2015-02-11 07:40:06 +08:00
register_expansion 'Canvas.file.media.id' , [ ] ,
- > { ( @attachment . media_object && @attachment . media_object . media_id ) || @attachment . media_entry_id } ,
MEDIA_OBJECT_ID_GUARD
register_expansion 'Canvas.file.media.type' , [ ] ,
- > { @attachment . media_object . media_type } ,
MEDIA_OBJECT_GUARD
register_expansion 'Canvas.file.media.duration' , [ ] ,
- > { @attachment . media_object . duration } ,
MEDIA_OBJECT_GUARD
register_expansion 'Canvas.file.media.size' , [ ] ,
- > { @attachment . media_object . total_size } ,
MEDIA_OBJECT_GUARD
register_expansion 'Canvas.file.media.title' , [ ] ,
- > { @attachment . media_object . user_entered_title || @attachment . media_object . title } ,
MEDIA_OBJECT_GUARD
register_expansion 'Canvas.file.usageRights.name' , [ ] ,
- > { @attachment . usage_rights . license_name } ,
USAGE_RIGHTS_GUARD
register_expansion 'Canvas.file.usageRights.url' , [ ] ,
- > { @attachment . usage_rights . license_url } ,
USAGE_RIGHTS_GUARD
register_expansion 'Canvas.file.usageRights.copyrightText' , [ ] ,
- > { @attachment . usage_rights . legal_copyright } ,
USAGE_RIGHTS_GUARD
2015-01-08 01:54:38 +08:00
private
def sis_pseudonym
2017-04-07 05:00:25 +08:00
@sis_pseudonym || = SisPseudonym . for ( @current_user , @root_account , type : :trusted , require_sis : false ) if @current_user
2015-01-08 01:54:38 +08:00
end
2015-05-14 01:00:18 +08:00
def expand_substring_variables ( value )
value . to_s . scan ( SUBSTRING_REGEX ) . inject ( value ) do | v , match |
substring = " ${ #{ match } } "
v . gsub ( substring , ( self [ match ] || substring ) . to_s )
end
end
2015-01-08 01:54:38 +08:00
end
2015-05-14 01:00:18 +08:00
end