fix bug where turning on A2 breaks RCE LTI content embedding

TEST PLAN
* With Assignments 2 enabled create a course and add a student to it
* Create an assignment with an online upload submission type
* In the course navigate to settings -> app and add a test lti tool with
  a homework_submission placement
* Masquerade as the student and navigate to the assignment
* Click the more options button and select the tool from the modal tabs
* Submit a file from the tool
* The file should be added to the current submission draft for the
  assignment

* With Assignments 2 enabled create a course
* In the course navigate to settings -> app and add the YouTube LTI tool
* In the course create a new announcement
* In the RCE, click the youtube tool icon, select a video and embed
* The video should embed totally fine

fixes COMMS-2420
flag=assignments_2

Change-Id: Ibff4e91a78fa9424be0213dae204b01a728df144
Reviewed-on: https://gerrit.instructure.com/208717
Reviewed-by: Steven Burnett <sburnett@instructure.com>
Reviewed-by: Weston Dransfield <wdransfield@instructure.com>
Tested-by: Jenkins
QA-Review: Steven Burnett <sburnett@instructure.com>
Product-Review: Matthew Lemon <mlemon@instructure.com>
This commit is contained in:
Matthew Lemon 2019-09-09 14:13:45 -06:00
parent 9ab86d4c69
commit c5cf39e39d
5 changed files with 52 additions and 38 deletions

View File

@ -47,6 +47,20 @@ function dataReady(data, service_id) {
}
}
// Handles lti 1.0 responses for Assignments 2 which expects a
// vanilla JS event from LTI tools in the following form.
function a2DataReady(data) {
parentWindow.postMessage({
messageType: 'A2ExternalContentReady',
content_items: data,
msg: ENV.message,
log: ENV.log,
errormsg: ENV.error_message,
errorlog: ENV.error_log,
ltiEndpoint: ENV.lti_endpoint
}, ENV.DEEP_LINKING_POST_MESSAGE_ORIGIN)
}
const {lti_response_messages} = ENV
const {service_id} = ENV
const data = ENV.retrieved_data
@ -88,4 +102,5 @@ if (ENV.oembed) {
)
} else {
dataReady(data, service_id)
a2DataReady(data)
}

View File

@ -61,19 +61,16 @@ class ExternalContentController < ApplicationController
end
@headers = false
if @domain_root_account.feature_enabled?(:assignments_2)
js_env({
content_items: @retrieved_data,
message: params[:lti_msg],
log: params[:lti_log],
error_message: params[:lti_errormsg],
error_log: params[:lti_errorlog]
})
render template: 'lti/ims/deep_linking/deep_linking_response'
else
js_env(retrieved_data: (@retrieved_data || {}), lti_response_messages: lti_response_messages,
service: params[:service], service_id: params[:id])
end
js_env({
retrieved_data: (@retrieved_data || {}),
lti_response_messages: lti_response_messages,
service: params[:service],
service_id: params[:id],
message: params[:lti_msg],
log: params[:lti_log],
error_message: params[:lti_errormsg],
error_log: params[:lti_errorlog]
})
end
def normalize_deprecated_data!

View File

@ -73,7 +73,10 @@ export default class FileUpload extends Component {
}
handleLTIFiles = async e => {
if (e.data.messageType === 'LtiDeepLinkingResponse') {
if (
e.data.messageType === 'LtiDeepLinkingResponse' ||
e.data.messageType === 'A2ExternalContentReady'
) {
await this.handleDropAccepted(e.data.content_items)
}
}

View File

@ -42,7 +42,10 @@ class MoreOptions extends React.Component {
}
handleIframeTask = e => {
if (e.data.messageType === 'LtiDeepLinkingResponse') {
if (
e.data.messageType === 'LtiDeepLinkingResponse' ||
e.data.messageType === 'A2ExternalContentReady'
) {
if (this._isMounted) {
this.setState({open: false})
}

View File

@ -36,14 +36,19 @@ describe ExternalContentController do
it "js env is set correctly" do
c = course_factory
post(:success, params: {service: 'external_tool_dialog', course_id: c.id, lti_message_type: 'ContentItemSelection',
lti_version: 'LTI-1p0',
data: '',
content_items: File.read(File.join(Rails.root, 'spec', 'fixtures', 'lti', 'content_items.json')),
lti_msg: '',
lti_log: '',
lti_errormsg: '',
lti_errorlog: ''})
params = {
service: 'external_tool_dialog',
course_id: c.id,
lti_message_type: 'ContentItemSelection',
lti_version: 'LTI-1p0',
data: '',
content_items: File.read(File.join(Rails.root, 'spec', 'fixtures', 'lti', 'content_items.json')),
lti_msg: 'some lti message',
lti_log: 'some lti log',
lti_errormsg: 'some lti error message',
lti_errorlog: 'some lti error log'
}
post(:success, params: params)
data = controller.js_env[:retrieved_data]
expect(data).to_not be_nil
@ -65,21 +70,12 @@ describe ExternalContentController do
e = "external_tools/retrieve?display=borderless&url=http%3A%2F%2Flti-tool-provider-example.dev%2Fmessages%2Fblti"
expect(data.first.canvas_url).to end_with(e)
end
it 'renders the deep_linking_response template if assignments_2 is enabled' do
Account.default.enable_feature!(:assignments_2)
c = course_factory
post(:success, params: {service: 'external_tool_dialog', course_id: c.id, lti_message_type: 'ContentItemSelection',
lti_version: 'LTI-1p0',
data: '',
content_items: File.read(Rails.root.join('spec', 'fixtures', 'lti', 'content_items.json')),
lti_msg: '',
lti_log: '',
lti_errormsg: '',
lti_errorlog: ''})
expect(response).to render_template('lti/ims/deep_linking/deep_linking_response')
env = controller.js_env
expect(env[:service]).to eq(params[:service])
expect(env[:message]).to eq(params[:lti_msg])
expect(env[:log]).to eq(params[:lti_log])
expect(env[:error_message]).to eq(params[:lti_errormsg])
expect(env[:error_log]).to eq(params[:lti_errorlog])
end
context 'external_tool service_id' do