Set ENV and loading screen

Closes PLAT-4061

Test Plan:
- Use the test tool to do a deep linking response request
  to the RCE.
- Verify Canvas sets the sent content items and messages
  in the JS ENV.
- Verify the modal displays a 'retrieveing content'
  message.

Change-Id: I443ed67ab55e68f362860bd75d796e1b3bb5ec22
Reviewed-on: https://gerrit.instructure.com/174523
Tested-by: Jenkins
Reviewed-by: Marc Phillips <mphillips@instructure.com>
QA-Review: Marc Phillips <mphillips@instructure.com>
Product-Review: Jesse Poulos <jpoulos@instructure.com>
This commit is contained in:
wdransfield 2018-12-06 09:21:58 -07:00 committed by Weston Dransfield
parent 980f8c86bc
commit 0a8bf9d557
8 changed files with 156 additions and 3 deletions

View File

@ -20,10 +20,13 @@ module Lti::Ims::Concerns
extend ActiveSupport::Concern
def validate_jwt
deep_linking_jwt = DeepLinkingJwt.new(params[:JWT], @context)
render_error(deep_linking_jwt.errors.first) and return unless deep_linking_jwt.valid?
end
def deep_linking_jwt
@deep_linking_jwt ||= DeepLinkingJwt.new(params[:JWT], @context)
end
def render_error(message)
render json: { error: message }, status: :bad_request
end

View File

@ -20,6 +20,8 @@ require 'json/jwt'
module Lti
module Ims
class DeepLinkingController < ApplicationController
CLAIM_PREFIX = 'https://purl.imsglobal.org/spec/lti-dl/claim/'.freeze
protect_from_forgery except: [:deep_linking_response], with: :exception
include Concerns::DeepLinkingServices
@ -28,7 +30,16 @@ module Lti
before_action :validate_jwt
def deep_linking_response
render json: { test: 'value' }
# Set content items and messaging values in JS env
js_env(
content_items: deep_linking_jwt["#{CLAIM_PREFIX}content_items"],
message: deep_linking_jwt["#{CLAIM_PREFIX}msg"],
log: '',
error_message: deep_linking_jwt["#{CLAIM_PREFIX}errormsg"],
error_log: ''
)
render layout: 'bare'
end
end
end

View File

@ -0,0 +1,21 @@
/*
* Copyright (C) 2018 - present 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/>.
*/
import DeepLinkingResponse from '../deep_linking/DeepLinkingResponse'
DeepLinkingResponse.mount()

View File

@ -0,0 +1,50 @@
/*
* Copyright (C) 2018 - present 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/>.
*/
import I18n from 'i18n!external_content.success'
import React from 'react'
import ReactDOM from 'react-dom'
import Spinner from '@instructure/ui-elements/lib/components/Spinner'
import Text from '@instructure/ui-elements/lib/components/Text'
import Flex, {FlexItem} from '@instructure/ui-layout/lib/components/Flex'
export class RetrievingContent extends React.Component {
render() {
const message = I18n.t('Retrieving Content')
return (
<div>
<Flex justifyItems="center" margin="x-large 0 large 0">
<FlexItem>
<Spinner title={message} size="large"/>
</FlexItem>
</Flex>
<Flex justifyItems="center" margin="0 0 large">
<FlexItem>
<Text size="x-large" fontStyle="italic">{message}</Text>
</FlexItem>
</Flex>
</div>
)
}
}
export default class DeepLinkingResponse {
static mount() {
ReactDOM.render(<RetrievingContent />, document.getElementById('deepLinkingContent'))
}
}

View File

@ -0,0 +1,33 @@
/*
* Copyright (C) 2018 - present 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/>.
*/
import React from 'react'
import { mount } from 'enzyme'
import Text from '@instructure/ui-elements/lib/components/Text'
import {RetrievingContent} from '../DeepLinkingResponse'
let wrapper = 'empty wrapper'
afterEach(() => {
wrapper.unmount()
})
it('renders an informative message', () => {
wrapper = mount(<RetrievingContent />)
expect(wrapper.find(Text).html()).toContain("Retrieving Content")
})

View File

@ -0,0 +1,20 @@
<%
# Copyright (C) 2018 - present 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/>.
%>
<% js_bundle(:deep_linking_response) %>
<div id="deepLinkingContent"></div>

View File

@ -478,6 +478,11 @@ CanvasRails::Application.routes.draw do
get 'external_content/retrieve/oembed' => 'external_content#oembed_retrieve', as: :external_content_oembed_retrieve
get 'external_content/cancel/:service' => 'external_content#cancel', as: :external_content_cancel
%w(account course).each do |context|
prefix = "#{context}s/:#{context}_id"
post "#{prefix}/deep_linking_response", controller: 'lti/ims/deep_linking', action: :deep_linking_response, as: "#{context}_deep_linking_response"
end
%w(account course group user).each do |context|
match "#{context.pluralize}/:#{context}_id/external_content/success/:service" => 'external_content#success', as: "#{context}_external_content_success", via: [:get, :post]
match "#{context.pluralize}/:#{context}_id/external_content/success/:service/:id" => 'external_content#success', as: "#{context}_external_content_update", via: [:get, :post]
@ -2206,7 +2211,6 @@ CanvasRails::Application.routes.draw do
%w(course account).each do |context|
prefix = "#{context}s/:#{context}_id"
post "#{prefix}/deep_linking_response", controller: 'lti/ims/deep_linking', action: :deep_linking_response, as: "#{context}_deep_linking_response"
post "#{prefix}/authorize", controller: 'lti/ims/authorization', action: :authorize, as: "#{context}_lti_oauth2_authorize"
get "#{prefix}/tool_consumer_profile(/:tool_consumer_profile_id)", controller: 'lti/ims/tool_consumer_profile',
action: 'show', as: "#{context}_tool_consumer_profile"

View File

@ -30,6 +30,17 @@ module Lti
it { is_expected.to be_ok }
it 'sets the JS ENV' do
expect(controller).to receive(:js_env).with(
content_items: content_items,
message: message,
log: '',
error_message: error_message,
error_log: ''
)
subject
end
shared_examples_for 'errors' do
let(:response_message) { raise 'set in examples' }