Add line_item extensions to line_item json

refs PLAT-4486

Test Plan:
 - create a line_item with the extension defined, should show up
   in the retrieval of that line_item

Change-Id: Ia379329dc3509c4d91b81d6e218afb9add7d9dc7
Reviewed-on: https://gerrit.instructure.com/198547
Tested-by: Jenkins
QA-Review: Marc Phillips <mphillips@instructure.com>
Product-Review: Marc Phillips <mphillips@instructure.com>
Reviewed-by: Weston Dransfield <wdransfield@instructure.com>
This commit is contained in:
Marc Phillips 2019-06-20 16:34:38 -06:00
parent 36aa198316
commit f0089b2346
6 changed files with 58 additions and 7 deletions

View File

@ -55,6 +55,11 @@ module Lti
# "description": "The resource link id the Line Item is attached to",
# "example": "50",
# "type": "string"
# },
# "https://canvas.instructure.com/lti/submission_type": {
# "description": "The extension that defines the submission_type of the line_item. Only returns if set through the line_item create endpoint.",
# "example": "{\n\t\"type\":\"external_tool\",\n\t\"external_tool_url\":\"https://my.launch.url\",\n}",
# "type": "string"
# }
# }
# }
@ -122,6 +127,7 @@ module Lti
# "external_tool_url": "https://my.launch.url"
# }
# }
#
# @returns LineItem
def create
new_line_item = LineItem.create_line_item!(

View File

@ -65,8 +65,7 @@ class Lti::LineItem < ApplicationRecord
url: submission_type[:external_tool_url]
}
# remove submission params from line item so it can save correctly
params = params.except(AGS_EXT_SUBMISSION_TYPE)
params = extract_extensions(params)
else
raise ActionController::BadRequest, "Invalid submission_type for new assignment: #{submission_type[:type]}"
end
@ -79,6 +78,13 @@ class Lti::LineItem < ApplicationRecord
end
end
def self.extract_extensions(params)
hsh = params.to_unsafe_h
hsh[:extensions] = { AGS_EXT_SUBMISSION_TYPE => hsh.delete(AGS_EXT_SUBMISSION_TYPE) }
hsh
end
private_class_method :extract_extensions
private
def resource_link_id_has_one_assignment

View File

@ -30,7 +30,7 @@ module Lti::Ims
resourceId: @line_item.resource_id,
tag: @line_item.tag,
resourceLinkId: @line_item.resource_link&.resource_link_id
}.compact
}.merge(@line_item.extensions).compact
end
end
end

View File

@ -0,0 +1,24 @@
#
# Copyright (C) 2019 - 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/>.
class AddLtiLineItemExtensions < ActiveRecord::Migration[5.1]
tag :predeploy
def change
add_column :lti_line_items, :extensions, :jsonb, default: {}
end
end

View File

@ -253,9 +253,14 @@ module Lti
it 'sets the assignment submission type to external tool' do
expect(item.assignment.submission_types).to eq 'external_tool'
end
it 'sets the assignment external url' do
expect(item.assignment.external_tool_tag.url).to eq "http://www.google.com"
end
it 'sets the extension on return' do
expect(json[LineItem::AGS_EXT_SUBMISSION_TYPE][:external_tool_url]).to eq "http://www.google.com"
end
end
context 'when submission type is invalid' do
@ -663,16 +668,25 @@ module Lti
end
end
xcontext 'when using the uncoupled model' do
context 'when using the uncoupled model' do
let(:line_item) do
line_item_model(
course: course,
tag: tag,
resource_id: resource_id
resource_id: resource_id,
client_id: developer_key.global_id
)
end
it_behaves_like 'the line item destroy endpoint'
it 'deletes the correct line item' do
send_request
expect(Lti::LineItem.active.find_by(id: line_item_id)).to be_nil
end
it 'responds with no content' do
send_request
expect(response).to be_no_content
end
end
end
end

View File

@ -33,7 +33,8 @@ module Factories
params = base_line_item_params_with_resource_link(assignment, overrides).merge(
overrides.except(:assignment, :course, :resource_link, :with_resource_link, :tool)
)
params[:client_id] = DeveloperKey.create!.id unless assignment.external_tool? || overrides[:with_resource_link]
params[:client_id] = overrides[:client_id]
params[:client_id] ||= DeveloperKey.create!.id unless assignment.external_tool? || overrides[:with_resource_link]
Lti::LineItem.create!(params)
end