stringify global ids for live events
fixes CNVS-29727 test plan: - enable live events - ensure that all global ids come through as strings Change-Id: I54d1105d442dc92b0d973777fd745864bea1f232 Reviewed-on: https://gerrit.instructure.com/81428 Reviewed-by: Cody Cutrer <cody@instructure.com> Tested-by: Jenkins QA-Review: Benjamin Christian Nelson <bcnelson@instructure.com> Product-Review: Simon Williams <simon@instructure.com>
This commit is contained in:
parent
70d525fc6d
commit
98ffdcf6ad
|
@ -2089,6 +2089,7 @@ class ApplicationController < ActionController::Base
|
||||||
ctx[:session_id] = tctx[:session_id]
|
ctx[:session_id] = tctx[:session_id]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
StringifyIds.recursively_stringify_ids(ctx)
|
||||||
LiveEvents.set_context(ctx)
|
LiveEvents.set_context(ctx)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -50,11 +50,13 @@ Delayed::Worker.lifecycle.around(:perform) do |worker, job, &block|
|
||||||
:session_id => worker.name,
|
:session_id => worker.name,
|
||||||
}
|
}
|
||||||
|
|
||||||
LiveEvents.set_context({
|
live_events_ctx = {
|
||||||
:root_account_id => job.respond_to?(:global_account_id) ? job.global_account_id : nil,
|
:root_account_id => job.respond_to?(:global_account_id) ? job.global_account_id : nil,
|
||||||
:job_id => job.global_id,
|
:job_id => job.global_id,
|
||||||
:job_tag => job.tag
|
:job_tag => job.tag
|
||||||
})
|
}
|
||||||
|
StringifyIds.recursively_stringify_ids(live_events_ctx)
|
||||||
|
LiveEvents.set_context(live_events_ctx)
|
||||||
|
|
||||||
starting_mem = Canvas.sample_memory()
|
starting_mem = Canvas.sample_memory()
|
||||||
starting_cpu = Process.times()
|
starting_cpu = Process.times()
|
||||||
|
|
|
@ -35,14 +35,14 @@ event originated as part of a web request:
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| ---- | ---- | ----------- |
|
| ---- | ---- | ----------- |
|
||||||
| `user_id` | Number | The Canvas id of the currently logged in user. |
|
| `user_id` | String | The Canvas id of the currently logged in user. |
|
||||||
| `real_user_id` | Number | If the current user is being masqueraded, this is the Canvas id of the masquerading user. |
|
| `real_user_id` | String | If the current user is being masqueraded, this is the Canvas id of the masquerading user. |
|
||||||
| `user_login` | String | The login of the current user. |
|
| `user_login` | String | The login of the current user. |
|
||||||
| `user_agent` | String | The User-Agent sent by the browser making the request. |
|
| `user_agent` | String | The User-Agent sent by the browser making the request. |
|
||||||
| `root_account_id` | Number | The Canvas id of the root account associated with the current user. |
|
| `root_account_id` | String | The Canvas id of the root account associated with the current user. |
|
||||||
| `root_account_lti_guid` | String | The Canvas lti_guid of the root account associated with the current user. |
|
| `root_account_lti_guid` | String | The Canvas lti_guid of the root account associated with the current user. |
|
||||||
| `context_type` | String | The type of context where the event happened. |
|
| `context_type` | String | The type of context where the event happened. |
|
||||||
| `context_id` | Number | The Canvas id of the current context. Always use the `context_type` when using this id to lookup the object. |
|
| `context_id` | String | The Canvas id of the current context. Always use the `context_type` when using this id to lookup the object. |
|
||||||
| `role` | String | The role of the current user in the current context. |
|
| `role` | String | The role of the current user in the current context. |
|
||||||
| `hostname` | String | The hostname of the current request |
|
| `hostname` | String | The hostname of the current request |
|
||||||
| `request_id` | String | The identifier for this request. |
|
| `request_id` | String | The identifier for this request. |
|
||||||
|
@ -53,7 +53,7 @@ fields may be set:
|
||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| ---- | ---- | ----------- |
|
| ---- | ---- | ----------- |
|
||||||
| `job_id` | Number | The identifier for the asynchronous job. |
|
| `job_id` | String | The identifier for the asynchronous job. |
|
||||||
| `job_tag` | String | A string identifying the type of job being performed. |
|
| `job_tag` | String | A string identifying the type of job being performed. |
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ fields may be set:
|
||||||
The `body` object will have key/value pairs with information specific to
|
The `body` object will have key/value pairs with information specific to
|
||||||
each event, as described below.
|
each event, as described below.
|
||||||
|
|
||||||
Note: All Canvas ids are "global" identifiers.
|
Note: All Canvas ids are "global" identifiers, returned as strings.
|
||||||
|
|
||||||
|
|
||||||
### Supported Events
|
### Supported Events
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
module Canvas::LiveEvents
|
module Canvas::LiveEvents
|
||||||
|
def self.post_event_stringified(event_name, payload)
|
||||||
|
StringifyIds.recursively_stringify_ids(payload)
|
||||||
|
LiveEvents.post_event(event_name, payload)
|
||||||
|
end
|
||||||
|
|
||||||
def self.course_syllabus_updated(course, old_syllabus_body)
|
def self.course_syllabus_updated(course, old_syllabus_body)
|
||||||
LiveEvents.post_event('syllabus_updated', {
|
post_event_stringified('syllabus_updated', {
|
||||||
course_id: course.global_id,
|
course_id: course.global_id,
|
||||||
syllabus_body: LiveEvents.truncate(course.syllabus_body),
|
syllabus_body: LiveEvents.truncate(course.syllabus_body),
|
||||||
old_syllabus_body: LiveEvents.truncate(old_syllabus_body)
|
old_syllabus_body: LiveEvents.truncate(old_syllabus_body)
|
||||||
|
@ -20,11 +25,11 @@ module Canvas::LiveEvents
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
LiveEvents.post_event('discussion_entry_created', payload)
|
post_event_stringified('discussion_entry_created', payload)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.discussion_topic_created(topic)
|
def self.discussion_topic_created(topic)
|
||||||
LiveEvents.post_event('discussion_topic_created', {
|
post_event_stringified('discussion_topic_created', {
|
||||||
discussion_topic_id: topic.global_id,
|
discussion_topic_id: topic.global_id,
|
||||||
is_announcement: topic.is_announcement,
|
is_announcement: topic.is_announcement,
|
||||||
title: LiveEvents.truncate(topic.title),
|
title: LiveEvents.truncate(topic.title),
|
||||||
|
@ -33,7 +38,7 @@ module Canvas::LiveEvents
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.group_membership_created(membership)
|
def self.group_membership_created(membership)
|
||||||
LiveEvents.post_event('group_membership_created', {
|
post_event_stringified('group_membership_created', {
|
||||||
group_membership_id: membership.global_id,
|
group_membership_id: membership.global_id,
|
||||||
user_id: membership.global_user_id,
|
user_id: membership.global_user_id,
|
||||||
group_id: membership.global_group_id,
|
group_id: membership.global_group_id,
|
||||||
|
@ -44,14 +49,14 @@ module Canvas::LiveEvents
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.group_category_created(group_category)
|
def self.group_category_created(group_category)
|
||||||
LiveEvents.post_event('group_category_created', {
|
post_event_stringified('group_category_created', {
|
||||||
group_category_id: group_category.global_id,
|
group_category_id: group_category.global_id,
|
||||||
group_category_name: group_category.name
|
group_category_name: group_category.name
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.group_created(group)
|
def self.group_created(group)
|
||||||
LiveEvents.post_event('group_created', {
|
post_event_stringified('group_created', {
|
||||||
group_category_id: group.global_group_category_id,
|
group_category_id: group.global_group_category_id,
|
||||||
group_category_name: group.group_category.try(:name),
|
group_category_name: group.group_category.try(:name),
|
||||||
group_id: group.global_id,
|
group_id: group.global_id,
|
||||||
|
@ -89,41 +94,41 @@ module Canvas::LiveEvents
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.assignment_created(assignment)
|
def self.assignment_created(assignment)
|
||||||
LiveEvents.post_event('assignment_created', get_assignment_data(assignment))
|
post_event_stringified('assignment_created', get_assignment_data(assignment))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.submission_created(submission)
|
def self.submission_created(submission)
|
||||||
LiveEvents.post_event('submission_created', get_submission_data(submission))
|
post_event_stringified('submission_created', get_submission_data(submission))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.assignment_updated(assignment)
|
def self.assignment_updated(assignment)
|
||||||
LiveEvents.post_event('assignment_updated', get_assignment_data(assignment))
|
post_event_stringified('assignment_updated', get_assignment_data(assignment))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.submission_updated(submission)
|
def self.submission_updated(submission)
|
||||||
LiveEvents.post_event('submission_updated', get_submission_data(submission))
|
post_event_stringified('submission_updated', get_submission_data(submission))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.logged_in(session)
|
def self.logged_in(session)
|
||||||
LiveEvents.post_event('logged_in', {
|
post_event_stringified('logged_in', {
|
||||||
redirect_url: session[:return_to]
|
redirect_url: session[:return_to]
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.logged_out
|
def self.logged_out
|
||||||
LiveEvents.post_event('logged_out', {})
|
post_event_stringified('logged_out', {})
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.quiz_submitted(submission)
|
def self.quiz_submitted(submission)
|
||||||
# TODO: include score, for automatically graded portions?
|
# TODO: include score, for automatically graded portions?
|
||||||
LiveEvents.post_event('quiz_submitted', {
|
post_event_stringified('quiz_submitted', {
|
||||||
submission_id: submission.global_id,
|
submission_id: submission.global_id,
|
||||||
quiz_id: submission.global_quiz_id
|
quiz_id: submission.global_quiz_id
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.wiki_page_created(page)
|
def self.wiki_page_created(page)
|
||||||
LiveEvents.post_event('wiki_page_created', {
|
post_event_stringified('wiki_page_created', {
|
||||||
wiki_page_id: page.global_id,
|
wiki_page_id: page.global_id,
|
||||||
title: LiveEvents.truncate(page.title),
|
title: LiveEvents.truncate(page.title),
|
||||||
body: LiveEvents.truncate(page.body)
|
body: LiveEvents.truncate(page.body)
|
||||||
|
@ -145,11 +150,11 @@ module Canvas::LiveEvents
|
||||||
payload[:old_body] = old_body
|
payload[:old_body] = old_body
|
||||||
end
|
end
|
||||||
|
|
||||||
LiveEvents.post_event('wiki_page_updated', payload)
|
post_event_stringified('wiki_page_updated', payload)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.wiki_page_deleted(page)
|
def self.wiki_page_deleted(page)
|
||||||
LiveEvents.post_event('wiki_page_deleted', {
|
post_event_stringified('wiki_page_deleted', {
|
||||||
wiki_page_id: page.global_id,
|
wiki_page_id: page.global_id,
|
||||||
title: LiveEvents.truncate(page.title)
|
title: LiveEvents.truncate(page.title)
|
||||||
})
|
})
|
||||||
|
@ -161,7 +166,7 @@ module Canvas::LiveEvents
|
||||||
grader_id = submission.global_grader_id
|
grader_id = submission.global_grader_id
|
||||||
end
|
end
|
||||||
|
|
||||||
LiveEvents.post_event('grade_change', {
|
post_event_stringified('grade_change', {
|
||||||
submission_id: submission.global_id,
|
submission_id: submission.global_id,
|
||||||
assignment_id: submission.global_assignment_id,
|
assignment_id: submission.global_assignment_id,
|
||||||
grade: submission.grade,
|
grade: submission.grade,
|
||||||
|
@ -181,7 +186,7 @@ module Canvas::LiveEvents
|
||||||
asset_obj = asset
|
asset_obj = asset
|
||||||
end
|
end
|
||||||
|
|
||||||
LiveEvents.post_event('asset_accessed', {
|
post_event_stringified('asset_accessed', {
|
||||||
asset_type: asset_obj.class.reflection_type_name,
|
asset_type: asset_obj.class.reflection_type_name,
|
||||||
asset_id: asset_obj.global_id,
|
asset_id: asset_obj.global_id,
|
||||||
asset_subtype: asset_subtype,
|
asset_subtype: asset_subtype,
|
||||||
|
|
|
@ -33,7 +33,7 @@ describe Canvas::LiveEvents do
|
||||||
|
|
||||||
it "should not set old_title or old_body if they don't change" do
|
it "should not set old_title or old_body if they don't change" do
|
||||||
LiveEvents.expects(:post_event).with('wiki_page_updated', {
|
LiveEvents.expects(:post_event).with('wiki_page_updated', {
|
||||||
wiki_page_id: @page.global_id,
|
wiki_page_id: @page.global_id.to_s,
|
||||||
title: "old title",
|
title: "old title",
|
||||||
body: "old body"
|
body: "old body"
|
||||||
})
|
})
|
||||||
|
@ -45,7 +45,7 @@ describe Canvas::LiveEvents do
|
||||||
@page.title = "new title"
|
@page.title = "new title"
|
||||||
|
|
||||||
LiveEvents.expects(:post_event).with('wiki_page_updated', {
|
LiveEvents.expects(:post_event).with('wiki_page_updated', {
|
||||||
wiki_page_id: @page.global_id,
|
wiki_page_id: @page.global_id.to_s,
|
||||||
title: "new title",
|
title: "new title",
|
||||||
old_title: "old title",
|
old_title: "old title",
|
||||||
body: "old body"
|
body: "old body"
|
||||||
|
@ -58,7 +58,7 @@ describe Canvas::LiveEvents do
|
||||||
@page.body = "new body"
|
@page.body = "new body"
|
||||||
|
|
||||||
LiveEvents.expects(:post_event).with('wiki_page_updated', {
|
LiveEvents.expects(:post_event).with('wiki_page_updated', {
|
||||||
wiki_page_id: @page.global_id,
|
wiki_page_id: @page.global_id.to_s,
|
||||||
title: "old title",
|
title: "old title",
|
||||||
body: "new body",
|
body: "new body",
|
||||||
old_body: "old body"
|
old_body: "old body"
|
||||||
|
@ -73,13 +73,13 @@ describe Canvas::LiveEvents do
|
||||||
quiz_with_graded_submission([])
|
quiz_with_graded_submission([])
|
||||||
|
|
||||||
LiveEvents.expects(:post_event).with('grade_change', {
|
LiveEvents.expects(:post_event).with('grade_change', {
|
||||||
submission_id: @quiz_submission.submission.global_id,
|
submission_id: @quiz_submission.submission.global_id.to_s,
|
||||||
assignment_id: @quiz_submission.submission.global_assignment_id,
|
assignment_id: @quiz_submission.submission.global_assignment_id.to_s,
|
||||||
grade: @quiz_submission.submission.grade,
|
grade: @quiz_submission.submission.grade,
|
||||||
old_grade: 0,
|
old_grade: 0,
|
||||||
grader_id: nil,
|
grader_id: nil,
|
||||||
student_id: @quiz_submission.user.global_id,
|
student_id: @quiz_submission.user.global_id.to_s,
|
||||||
user_id: @quiz_submission.user.global_id
|
user_id: @quiz_submission.user.global_id.to_s
|
||||||
})
|
})
|
||||||
|
|
||||||
Canvas::LiveEvents.grade_changed(@quiz_submission.submission, 0)
|
Canvas::LiveEvents.grade_changed(@quiz_submission.submission, 0)
|
||||||
|
@ -90,13 +90,13 @@ describe Canvas::LiveEvents do
|
||||||
submission = @course.assignments.first.submissions.first
|
submission = @course.assignments.first.submissions.first
|
||||||
|
|
||||||
LiveEvents.expects(:post_event).with('grade_change', {
|
LiveEvents.expects(:post_event).with('grade_change', {
|
||||||
submission_id: submission.global_id,
|
submission_id: submission.global_id.to_s,
|
||||||
assignment_id: submission.global_assignment_id,
|
assignment_id: submission.global_assignment_id.to_s,
|
||||||
grade: '10',
|
grade: '10',
|
||||||
old_grade: 0,
|
old_grade: 0,
|
||||||
grader_id: @teacher.global_id,
|
grader_id: @teacher.global_id.to_s,
|
||||||
student_id: @student.global_id,
|
student_id: @student.global_id.to_s,
|
||||||
user_id: @student.global_id
|
user_id: @student.global_id.to_s
|
||||||
})
|
})
|
||||||
|
|
||||||
submission.grader = @teacher
|
submission.grader = @teacher
|
||||||
|
@ -110,8 +110,8 @@ describe Canvas::LiveEvents do
|
||||||
|
|
||||||
LiveEvents.expects(:post_event).with('grade_change',
|
LiveEvents.expects(:post_event).with('grade_change',
|
||||||
has_entries(
|
has_entries(
|
||||||
assignment_id: submission.global_assignment_id,
|
assignment_id: submission.global_assignment_id.to_s,
|
||||||
user_id: @student.global_id
|
user_id: @student.global_id.to_s
|
||||||
))
|
))
|
||||||
Canvas::LiveEvents.grade_changed(submission, 0)
|
Canvas::LiveEvents.grade_changed(submission, 0)
|
||||||
end
|
end
|
||||||
|
@ -124,8 +124,8 @@ describe Canvas::LiveEvents do
|
||||||
|
|
||||||
LiveEvents.expects(:post_event).with('submission_updated',
|
LiveEvents.expects(:post_event).with('submission_updated',
|
||||||
has_entries(
|
has_entries(
|
||||||
user_id: @student.global_id,
|
user_id: @student.global_id.to_s,
|
||||||
assignment_id: submission.global_assignment_id
|
assignment_id: submission.global_assignment_id.to_s
|
||||||
))
|
))
|
||||||
Canvas::LiveEvents.submission_updated(submission)
|
Canvas::LiveEvents.submission_updated(submission)
|
||||||
end
|
end
|
||||||
|
@ -137,7 +137,7 @@ describe Canvas::LiveEvents do
|
||||||
|
|
||||||
LiveEvents.expects(:post_event).with('asset_accessed', {
|
LiveEvents.expects(:post_event).with('asset_accessed', {
|
||||||
asset_type: 'course',
|
asset_type: 'course',
|
||||||
asset_id: @course.global_id,
|
asset_id: @course.global_id.to_s,
|
||||||
asset_subtype: nil,
|
asset_subtype: nil,
|
||||||
category: 'category',
|
category: 'category',
|
||||||
role: 'role',
|
role: 'role',
|
||||||
|
@ -152,7 +152,7 @@ describe Canvas::LiveEvents do
|
||||||
|
|
||||||
LiveEvents.expects(:post_event).with('asset_accessed', {
|
LiveEvents.expects(:post_event).with('asset_accessed', {
|
||||||
asset_type: 'course',
|
asset_type: 'course',
|
||||||
asset_id: @course.global_id,
|
asset_id: @course.global_id.to_s,
|
||||||
asset_subtype: 'assignments',
|
asset_subtype: 'assignments',
|
||||||
category: 'category',
|
category: 'category',
|
||||||
role: 'role',
|
role: 'role',
|
||||||
|
|
Loading…
Reference in New Issue