2017-04-28 04:04:26 +08:00
|
|
|
#
|
|
|
|
# Copyright (C) 2012 - present Instructure, Inc.
|
2014-12-12 23:50:57 +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/>.
|
|
|
|
#
|
|
|
|
module Lti
|
|
|
|
class AppCollator
|
|
|
|
|
2015-10-29 05:58:10 +08:00
|
|
|
def initialize(context, reregistration_url_builder = nil)
|
2014-12-12 23:50:57 +08:00
|
|
|
@context = context
|
2015-10-29 05:58:10 +08:00
|
|
|
@reregistration_url_builder = reregistration_url_builder
|
2014-12-12 23:50:57 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def bookmarked_collection
|
|
|
|
external_tools_scope = ContextExternalTool.all_tools_for(@context)
|
|
|
|
external_tools_collection = BookmarkedCollection.wrap(ExternalToolNameBookmarker, external_tools_scope)
|
2015-01-10 04:29:02 +08:00
|
|
|
tool_proxy_scope = ToolProxy.find_installed_proxies_for_context(@context)
|
2014-12-12 23:50:57 +08:00
|
|
|
tool_proxy_collection = BookmarkedCollection.wrap(ToolProxyNameBookmarker, tool_proxy_scope)
|
2018-09-27 06:33:18 +08:00
|
|
|
|
2014-12-12 23:50:57 +08:00
|
|
|
BookmarkedCollection.merge(
|
|
|
|
['external_tools', external_tools_collection],
|
2015-01-09 23:25:22 +08:00
|
|
|
['message_handlers', tool_proxy_collection]
|
2014-12-12 23:50:57 +08:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2017-01-19 05:59:53 +08:00
|
|
|
def app_definitions(collection, opts={})
|
2014-12-12 23:50:57 +08:00
|
|
|
collection.map do |o|
|
|
|
|
case o
|
2017-01-19 05:59:53 +08:00
|
|
|
when ContextExternalTool
|
|
|
|
hash = external_tool_definition(o)
|
2017-02-14 00:38:35 +08:00
|
|
|
if opts[:master_course_status]
|
|
|
|
hash.merge!(o.master_course_api_restriction_data(opts[:master_course_status]))
|
2017-01-19 05:59:53 +08:00
|
|
|
end
|
|
|
|
hash
|
|
|
|
when ToolProxy
|
|
|
|
tool_proxy_definition(o)
|
2014-12-12 23:50:57 +08:00
|
|
|
end
|
2019-03-14 07:06:35 +08:00
|
|
|
end.compact
|
2014-12-12 23:50:57 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def external_tool_definition(external_tool)
|
|
|
|
{
|
2018-09-27 06:33:18 +08:00
|
|
|
app_type: 'ContextExternalTool',
|
2014-12-12 23:50:57 +08:00
|
|
|
app_id: external_tool.id,
|
|
|
|
name: external_tool.name,
|
|
|
|
description: external_tool.description,
|
2015-01-09 23:30:53 +08:00
|
|
|
installed_locally: external_tool.context == @context,
|
2015-01-22 00:37:45 +08:00
|
|
|
enabled: true,
|
2015-07-22 23:10:52 +08:00
|
|
|
tool_configuration: external_tool.tool_configuration,
|
|
|
|
context: external_tool.context_type,
|
2015-10-24 00:32:18 +08:00
|
|
|
context_id: external_tool.context.id,
|
2015-10-29 05:58:10 +08:00
|
|
|
reregistration_url: nil,
|
2018-09-27 06:33:18 +08:00
|
|
|
has_update: nil,
|
2019-06-12 05:44:44 +08:00
|
|
|
lti_version: external_tool.use_1_3? ? '1.3' : '1.1',
|
|
|
|
deployment_id: external_tool.deployment_id
|
2014-12-12 23:50:57 +08:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def tool_proxy_definition(tool_proxy)
|
|
|
|
{
|
|
|
|
app_type: tool_proxy.class.name,
|
|
|
|
app_id: tool_proxy.id,
|
|
|
|
name: tool_proxy.name,
|
|
|
|
description: tool_proxy.description,
|
2015-01-09 23:30:53 +08:00
|
|
|
installed_locally: tool_proxy.context == @context,
|
2015-01-22 00:37:45 +08:00
|
|
|
enabled: tool_proxy.workflow_state == 'active',
|
2015-07-22 23:10:52 +08:00
|
|
|
tool_configuration: nil,
|
|
|
|
context: tool_proxy.context_type,
|
2015-10-24 00:32:18 +08:00
|
|
|
context_id: tool_proxy.context.id,
|
2015-10-29 05:58:10 +08:00
|
|
|
reregistration_url: build_reregistration_url(tool_proxy),
|
2018-09-27 06:33:18 +08:00
|
|
|
has_update: root_account.feature_enabled?(:lti2_rereg) ? tool_proxy.update? : nil,
|
|
|
|
lti_version: '2.0'
|
2014-12-12 23:50:57 +08:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2015-10-24 00:32:18 +08:00
|
|
|
def root_account
|
|
|
|
if @context.respond_to?(:root_account)
|
|
|
|
@context.root_account
|
|
|
|
else
|
|
|
|
@context.account.root_account
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-10-29 05:58:10 +08:00
|
|
|
def build_reregistration_url(tool_proxy)
|
|
|
|
if root_account.feature_enabled?(:lti2_rereg) && @reregistration_url_builder &&
|
|
|
|
tool_proxy.reregistration_message_handler
|
2014-12-12 23:50:57 +08:00
|
|
|
|
2015-10-29 05:58:10 +08:00
|
|
|
@reregistration_url_builder.call(@context, tool_proxy.id)
|
|
|
|
end
|
|
|
|
end
|
2014-12-12 23:50:57 +08:00
|
|
|
end
|
2017-01-19 05:59:53 +08:00
|
|
|
end
|