Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/observers/live_events_observer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class LiveEventsObserver < ActiveRecord::Observer
:user_account_association,
:user,
:wiki_page,
"Lti::ResourceLink",
"MasterCourses::MasterTemplate",
"MasterCourses::MasterMigration",
"MasterCourses::ChildSubscription",
Expand Down
24 changes: 24 additions & 0 deletions lib/canvas/live_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,30 @@ def self.wiki_page_deleted(page)
})
end

def self.get_lti_resource_link_data(resource_link)
{
resource_link_id: resource_link.global_id,
resource_link_uuid: resource_link.resource_link_uuid,
lookup_uuid: resource_link.lookup_uuid,
context_id: resource_link.global_context_id,
context_type: resource_link.context_type,
context_external_tool_id: resource_link.original_context_external_tool&.global_id,
url: resource_link.url,
title: resource_link.title,
workflow_state: resource_link.workflow_state
}
end

def self.lti_resource_link_created(resource_link)
post_event_stringified("lti_resource_link_created",
get_lti_resource_link_data(resource_link))
end

def self.lti_resource_link_updated(resource_link)
post_event_stringified("lti_resource_link_updated",
get_lti_resource_link_data(resource_link))
end

def self.attachment_created(attachment)
post_event_stringified("attachment_created", get_attachment_data(attachment))
end
Expand Down
4 changes: 4 additions & 0 deletions lib/canvas/live_events_callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def self.after_create(obj)
Canvas::LiveEvents.group_membership_created(obj)
when WikiPage
Canvas::LiveEvents.wiki_page_created(obj)
when Lti::ResourceLink
Canvas::LiveEvents.lti_resource_link_created(obj)
when Assignment
Canvas::LiveEvents.assignment_created(obj)
when AssignmentGroup
Expand Down Expand Up @@ -135,6 +137,8 @@ def self.after_update(obj, changes)
changes["title"]&.first,
changes["body"]&.first)
end
when Lti::ResourceLink
Canvas::LiveEvents.lti_resource_link_updated(obj)
when Assignment
Canvas::LiveEvents.assignment_updated(obj)
when AssignmentGroup
Expand Down
56 changes: 56 additions & 0 deletions spec/lib/canvas/live_events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,62 @@ def body
end
end

describe ".lti_resource_link_created" do
before do
course_with_teacher
@tool = external_tool_model(context: @course)
@resource_link = Lti::ResourceLink.create!(
context: @course,
context_external_tool: @tool,
url: "http://example.com/launch",
title: "My Link"
)
end

it "posts the correct event and payload" do
expect_event("lti_resource_link_created", {
resource_link_id: @resource_link.global_id.to_s,
resource_link_uuid: @resource_link.resource_link_uuid,
lookup_uuid: @resource_link.lookup_uuid,
context_id: @resource_link.global_context_id.to_s,
context_type: "Course",
context_external_tool_id: @tool.global_id.to_s,
url: "http://example.com/launch",
title: "My Link",
workflow_state: "active"
})
Canvas::LiveEvents.lti_resource_link_created(@resource_link)
end
end

describe ".lti_resource_link_updated" do
before do
course_with_teacher
@tool = external_tool_model(context: @course)
@resource_link = Lti::ResourceLink.create!(
context: @course,
context_external_tool: @tool,
url: "http://example.com/launch",
title: "My Link"
)
end

it "posts the correct event and payload" do
expect_event("lti_resource_link_updated", {
resource_link_id: @resource_link.global_id.to_s,
resource_link_uuid: @resource_link.resource_link_uuid,
lookup_uuid: @resource_link.lookup_uuid,
context_id: @resource_link.global_context_id.to_s,
context_type: "Course",
context_external_tool_id: @tool.global_id.to_s,
url: "http://example.com/launch",
title: "My Link",
workflow_state: "active"
})
Canvas::LiveEvents.lti_resource_link_updated(@resource_link)
end
end

describe ".wiki_page_updated" do
before do
course_with_teacher
Expand Down
34 changes: 34 additions & 0 deletions spec/observers/live_events_observer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,40 @@
end
end

describe "lti_resource_link" do
let(:course) { Course.create!(name: "Course") }
let(:tool) { external_tool_model(context: course) }

it "posts lti_resource_link_created when a resource link is created" do
expect(Canvas::LiveEvents).to receive(:lti_resource_link_created).once
Lti::ResourceLink.create!(
context: course,
context_external_tool: tool,
url: "http://example.com/launch"
)
end

it "posts lti_resource_link_updated when a resource link is updated" do
resource_link = Lti::ResourceLink.create!(
context: course,
context_external_tool: tool,
url: "http://example.com/launch"
)
expect(Canvas::LiveEvents).to receive(:lti_resource_link_updated).once
resource_link.update!(title: "New Title")
end

it "posts lti_resource_link_updated (not deleted) when a resource link is soft deleted" do
resource_link = Lti::ResourceLink.create!(
context: course,
context_external_tool: tool,
url: "http://example.com/launch"
)
expect(Canvas::LiveEvents).to receive(:lti_resource_link_updated).once
resource_link.destroy
end
end

describe "wiki" do
it "posts create events" do
expect(Canvas::LiveEvents).to receive(:wiki_page_created).once
Expand Down