2015-01-08 01:54:38 +08:00
|
|
|
#
|
|
|
|
# Copyright (C) 2015 Instructure, Inc.
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
|
|
|
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,
|
|
|
|
:collaboration
|
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 ||= {}
|
2016-10-28 03:57:01 +08:00
|
|
|
@expansions["$#{name}".to_sym] = VariableExpansion.new(name, permission_groups, expansion_proc, *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
|
|
|
|
|
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 }
|
2015-01-08 01:54:38 +08:00
|
|
|
USER_GUARD = -> { @current_user }
|
|
|
|
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 }
|
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
|
|
|
|
@lti_helper ||= Lti::SubstitutionsHelper.new(@context, @root_account, @current_user)
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
2016-06-16 02:10:32 +08:00
|
|
|
# returns the URL for the membership service associated with the current context
|
|
|
|
# @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 }
|
|
|
|
|
2016-03-11 12:49:32 +08:00
|
|
|
# returns the account's sis source id for the current context.
|
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 }
|
|
|
|
|
2016-03-11 12:49:32 +08:00
|
|
|
# returns the root account's sis source id for the current context.
|
2015-01-08 01:54:38 +08:00
|
|
|
register_expansion 'Canvas.rootAccount.sisSourceId', [],
|
|
|
|
-> { @root_account.sis_source_id }
|
|
|
|
|
2016-08-24 03:22:00 +08:00
|
|
|
# returns the API URL for the external tool that was launched.
|
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
|
|
|
|
|
2016-03-11 12:49:32 +08:00
|
|
|
# returns the URL for the external tool that was launched.
|
|
|
|
# @example
|
|
|
|
# ```
|
|
|
|
# http://example.url/path.css
|
|
|
|
# ```
|
2015-07-11 00:28:43 +08:00
|
|
|
register_expansion 'Canvas.css.common', [],
|
|
|
|
-> { URI.parse(@request.url)
|
2016-10-28 03:57:01 +08:00
|
|
|
.merge(@controller.view_context.stylesheet_path(@controller.css_url_for(:common))).to_s },
|
|
|
|
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.
|
|
|
|
# @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 }
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
# ```
|
|
|
|
# 1234
|
|
|
|
# ```
|
2015-04-23 23:08:26 +08:00
|
|
|
register_expansion 'Canvas.course.startAt', [],
|
|
|
|
-> { @context.start_at },
|
|
|
|
COURSE_GUARD
|
|
|
|
|
2016-03-11 12:49:32 +08:00
|
|
|
# returns the current course's term start date.
|
|
|
|
# @example
|
|
|
|
# ```
|
|
|
|
# 1234
|
|
|
|
# ```
|
2015-04-23 23:08:26 +08:00
|
|
|
register_expansion 'Canvas.term.startAt', [],
|
|
|
|
-> { @context.enrollment_term.start_at },
|
|
|
|
TERM_START_DATE_GUARD
|
|
|
|
|
2016-03-11 12:49:32 +08:00
|
|
|
# returns the current course section sis source id
|
|
|
|
# @example
|
|
|
|
# ```
|
|
|
|
# 1234
|
|
|
|
# ```
|
2015-01-08 01:54:38 +08:00
|
|
|
register_expansion 'CourseSection.sourcedId', [],
|
|
|
|
-> { @context.sis_source_id },
|
|
|
|
COURSE_GUARD
|
|
|
|
|
2016-03-11 12:49:32 +08:00
|
|
|
# returns the current course enrollment state
|
|
|
|
# @example
|
|
|
|
# ```
|
|
|
|
# 1234
|
|
|
|
# ```
|
2015-01-08 01:54:38 +08:00
|
|
|
register_expansion 'Canvas.enrollment.enrollmentState', [],
|
|
|
|
-> { lti_helper.enrollment_state },
|
|
|
|
COURSE_GUARD
|
|
|
|
|
2016-03-11 12:49:32 +08:00
|
|
|
# returns the current course membership roles
|
|
|
|
# @example
|
|
|
|
# ```
|
|
|
|
# 1234
|
|
|
|
# ```
|
2015-01-08 01:54:38 +08:00
|
|
|
register_expansion 'Canvas.membership.roles', [],
|
|
|
|
-> { lti_helper.current_canvas_roles },
|
2015-08-04 03:46:13 +08:00
|
|
|
ROLES_GUARD
|
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
|
2015-01-08 01:54:38 +08:00
|
|
|
register_expansion 'Canvas.membership.concludedRoles', [],
|
|
|
|
-> { lti_helper.concluded_lis_roles },
|
|
|
|
COURSE_GUARD
|
|
|
|
|
2016-03-11 12:49:32 +08:00
|
|
|
# returns the current course enrollment state
|
|
|
|
# @example
|
|
|
|
# ```
|
|
|
|
# 1234
|
|
|
|
# ```
|
2015-01-08 01:54:38 +08:00
|
|
|
register_expansion 'Canvas.course.previousContextIds', [],
|
|
|
|
-> { lti_helper.previous_lti_context_ids },
|
|
|
|
COURSE_GUARD
|
|
|
|
|
2016-03-11 12:49:32 +08:00
|
|
|
# returns the current course enrollment state
|
|
|
|
# @example
|
|
|
|
# ```
|
|
|
|
# 1234
|
|
|
|
# ```
|
2015-01-08 01:54:38 +08:00
|
|
|
register_expansion 'Canvas.course.previousCourseIds', [],
|
|
|
|
-> { lti_helper.previous_course_ids },
|
|
|
|
COURSE_GUARD
|
|
|
|
|
|
|
|
register_expansion 'Person.name.full', [],
|
|
|
|
-> { @current_user.name },
|
|
|
|
USER_GUARD
|
|
|
|
|
|
|
|
register_expansion 'Person.name.family', [],
|
|
|
|
-> { @current_user.last_name },
|
|
|
|
USER_GUARD
|
|
|
|
|
|
|
|
register_expansion 'Person.name.given', [],
|
|
|
|
-> { @current_user.first_name },
|
|
|
|
USER_GUARD
|
|
|
|
|
|
|
|
register_expansion 'Person.email.primary', [],
|
|
|
|
-> { @current_user.email },
|
|
|
|
USER_GUARD
|
|
|
|
|
|
|
|
register_expansion 'Person.address.timezone', [],
|
|
|
|
-> { Time.zone.tzinfo.name },
|
|
|
|
USER_GUARD
|
|
|
|
|
|
|
|
register_expansion 'User.image', [],
|
|
|
|
-> { @current_user.avatar_url },
|
|
|
|
USER_GUARD
|
|
|
|
|
|
|
|
register_expansion 'User.id', [],
|
|
|
|
-> { @current_user.id },
|
|
|
|
USER_GUARD
|
|
|
|
|
|
|
|
register_expansion 'Canvas.user.id', [],
|
|
|
|
-> { @current_user.id },
|
|
|
|
USER_GUARD
|
|
|
|
|
|
|
|
register_expansion 'Canvas.user.prefersHighContrast', [],
|
|
|
|
-> { @current_user.prefers_high_contrast? ? 'true' : 'false' },
|
|
|
|
USER_GUARD
|
|
|
|
|
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) }
|
|
|
|
|
2015-01-08 01:54:38 +08:00
|
|
|
register_expansion 'Membership.role', [],
|
|
|
|
-> { lti_helper.all_roles('lis2') },
|
|
|
|
USER_GUARD
|
|
|
|
|
|
|
|
register_expansion 'Canvas.xuser.allRoles', [],
|
|
|
|
-> { lti_helper.all_roles }
|
|
|
|
|
2015-10-22 05:03:34 +08:00
|
|
|
register_expansion 'Canvas.user.globalId', [],
|
|
|
|
-> { @current_user.global_id},
|
|
|
|
USER_GUARD
|
|
|
|
|
2015-01-08 01:54:38 +08:00
|
|
|
# Substitutions for the primary pseudonym for the user for the account
|
|
|
|
# This should hold all the SIS information for the user
|
|
|
|
# This may not be the pseudonym the user is actually gingged in with
|
|
|
|
register_expansion 'User.username', [],
|
|
|
|
-> { sis_pseudonym.unique_id },
|
|
|
|
PSEUDONYM_GUARD
|
|
|
|
|
|
|
|
register_expansion 'Canvas.user.loginId', [],
|
|
|
|
-> { sis_pseudonym.unique_id },
|
|
|
|
PSEUDONYM_GUARD
|
|
|
|
|
|
|
|
register_expansion 'Canvas.user.sisSourceId', [],
|
|
|
|
-> { sis_pseudonym.sis_user_id },
|
|
|
|
PSEUDONYM_GUARD
|
|
|
|
|
2016-01-23 05:43:11 +08:00
|
|
|
register_expansion 'Canvas.user.sisIntegrationId', [],
|
|
|
|
-> { sis_pseudonym.integration_id },
|
|
|
|
PSEUDONYM_GUARD
|
|
|
|
|
2015-01-08 01:54:38 +08:00
|
|
|
register_expansion 'Person.sourcedId', [],
|
|
|
|
-> { sis_pseudonym.sis_user_id },
|
|
|
|
PSEUDONYM_GUARD
|
|
|
|
|
|
|
|
# This is the pseudonym the user is actually logged in as
|
|
|
|
# it may not hold all the sis info needed in other launch substitutions
|
|
|
|
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 }
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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 }
|
|
|
|
|
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 }
|
|
|
|
|
|
|
|
register_expansion 'Canvas.course.sectionIds', [],
|
|
|
|
-> { lti_helper.section_ids },
|
|
|
|
ENROLLMENT_GUARD
|
|
|
|
|
|
|
|
register_expansion 'Canvas.course.sectionSisSourceIds', [],
|
|
|
|
-> { lti_helper.section_sis_ids },
|
|
|
|
ENROLLMENT_GUARD
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
register_expansion 'Canvas.assignment.id', [],
|
|
|
|
-> { @assignment.id },
|
|
|
|
ASSIGNMENT_GUARD
|
|
|
|
|
|
|
|
register_expansion 'Canvas.assignment.title', [],
|
|
|
|
-> { @assignment.title },
|
|
|
|
ASSIGNMENT_GUARD
|
|
|
|
|
|
|
|
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-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
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
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 }
|
|
|
|
|
|
|
|
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 }
|
|
|
|
|
|
|
|
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
|
|
|
|
2015-01-16 02:47:16 +08:00
|
|
|
register_expansion 'ToolConsumerProfile.url', [],
|
2015-10-29 05:58:10 +08:00
|
|
|
-> { @controller.polymorphic_url([@tool.context, :tool_consumer_profile], tool_consumer_profile_id: Lti::ToolConsumerProfileCreator::TCP_UUID)},
|
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
|
|
|
|
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
|
|
|
|
@sis_pseudonym ||= @current_user.find_pseudonym_for_account(@root_account) if @current_user
|
|
|
|
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
|