Allow canvas extension placements in LTI registration

fixes INTEROP-8301

flag = lti_dynamic_registration

test plan:
- specs pass

Change-Id: I7639e8bd92bdf8e37ed9f1c4e30b4a75d724044e
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/332641
Reviewed-by: Evan Battaglia <ebattaglia@instructure.com>
QA-Review: Tucker Mcknight <tmcknight@instructure.com>
Product-Review: Tucker Mcknight <tmcknight@instructure.com>
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
This commit is contained in:
Tucker McKnight 2023-11-12 22:54:06 -07:00 committed by Tucker Mcknight
parent 9dd2786a51
commit eee9314c77
2 changed files with 37 additions and 19 deletions

View File

@ -121,7 +121,7 @@ class Lti::IMS::Registration < ApplicationRecord
else
message["placements"].map do |placement|
{
placement:,
placement: canvas_placement_name(placement),
enabled: true,
message_type: message["type"],
target_link_uri: message["target_link_uri"],
@ -207,4 +207,14 @@ class Lti::IMS::Registration < ApplicationRecord
config_errors.is_a?(Hash) ? config_errors.to_json : config_errors
)
end
def canvas_placement_name(placement)
# IMS placement names that have different names in Canvas
return "link_selection" if placement == "ContentArea"
return "editor_button" if placement == "RichTextEditor"
# Otherwise, remove our URL prefix from the Canvas-specific placements
canvas_extension = "https://#{CANVAS_EXTENSION_LABEL}/lti/"
placement.start_with?(canvas_extension) ? placement.sub(canvas_extension, "") : placement
end
end

View File

@ -281,7 +281,13 @@ module Lti::IMS
"foo" => "bar"
},
icon_uri: "http://example.com/icon.png",
placements: ["global_navigation", "course_navigation"],
placements: [
"https://canvas.instructure.com/lti/assignment_edit",
"global_navigation",
"course_navigation",
"ContentArea",
"RichTextEditor",
],
}],
claims: []
}
@ -290,26 +296,28 @@ module Lti::IMS
subject { registration.placements }
context "convert messages to placements" do
it do
it "accepts valid placements" do
canvas_placement_hash = {
custom_fields: { "foo" => "bar" },
enabled: true,
icon_url: "http://example.com/icon.png",
message_type: "LtiResourceLinkRequest",
target_link_uri: "http://example.com/launch"
}
expect(subject).to eq [
{
custom_fields: { "foo" => "bar" },
enabled: true,
icon_url: "http://example.com/icon.png",
message_type: "LtiResourceLinkRequest",
placement: "global_navigation",
target_link_uri: "http://example.com/launch"
},
{
custom_fields: { "foo" => "bar" },
enabled: true,
icon_url: "http://example.com/icon.png",
message_type: "LtiResourceLinkRequest",
placement: "course_navigation",
target_link_uri: "http://example.com/launch"
}
canvas_placement_hash.merge(placement: "assignment_edit"),
canvas_placement_hash.merge(placement: "global_navigation"),
canvas_placement_hash.merge(placement: "course_navigation"),
canvas_placement_hash.merge(placement: "link_selection"),
canvas_placement_hash.merge(placement: "editor_button"),
]
end
it "rejects invalid placements" do
bad_placement_name = "course_navigationhttps://canvas.instructure.com/lti/"
registration.lti_tool_configuration["messages"].first["placements"] << bad_placement_name
expect { registration.save! }.to raise_error(ActiveRecord::RecordInvalid)
end
end
end