added live events for assignments and submissions

* issueid: DS-595
* test plan:
  * create assignment and submission
  * update assignment and submission
  * ensure appropriate messages are in the kinesis queue

Change-Id: I0d7730c8a4ec01f780ae3b77581efb7b48c2733e
Reviewed-on: https://gerrit.instructure.com/68362
Tested-by: Jenkins
Reviewed-by: Simon Williams <simon@instructure.com>
QA-Review: August Thornton <august@instructure.com>
Product-Review: Linda Feng <lfeng@instructure.com>
This commit is contained in:
Matt Smith 2015-12-07 12:08:37 -07:00
parent 922b188051
commit 6ba9c9242d
4 changed files with 137 additions and 1 deletions

View File

@ -5,7 +5,9 @@ class LiveEventsObserver < ActiveRecord::Observer
:group,
:group_category,
:group_membership,
:wiki_page
:wiki_page,
:assignment,
:submission
def after_update(obj)
case obj
@ -18,6 +20,10 @@ class LiveEventsObserver < ActiveRecord::Observer
Canvas::LiveEvents.wiki_page_updated(obj, obj.title_changed? ? obj.title_was : nil,
obj.body_changed? ? obj.body_was : nil)
end
when Assignment
Canvas::LiveEvents.assignment_updated(obj)
when Submission
Canvas::LiveEvents.submission_updated(obj)
end
end
@ -35,6 +41,10 @@ class LiveEventsObserver < ActiveRecord::Observer
Canvas::LiveEvents.group_membership_created(obj)
when WikiPage
Canvas::LiveEvents.wiki_page_created(obj)
when Assignment
Canvas::LiveEvents.assignment_created(obj)
when Submission
Canvas::LiveEvents.submission_created(obj)
end
end

View File

@ -218,3 +218,62 @@ by `asset_type` and `asset_id`.
| `asset_type` | The type of asset being accessed. |
| `asset_id` | The Canvas id of the asset. |
| `asset_subtype` | See above. |
#### `assignment_created`
| Field | Description |
| ----- | ----------- |
| `assignment_id` | The Canvas id of the new assignment. |
| `title` | The title of the assignment (possibly truncated). |
| `description` | The description of the assignment (possibly truncated). |
| `due_at` | The due date for the assignment. |
| `unlock_at` | The unlock date (assignment is unlocked after this date) |
| `lock_at` | The lock date (assignment is locked after this date) |
| `updated_at` | The time at which this assignment was last modified in any way |
| `points_possible` | The maximum points possible for the assignment |
#### `assignment_updated`
| Field | Description |
| ----- | ----------- |
| `assignment_id` | The Canvas id of the new assignment. |
| `title` | The title of the assignment (possibly truncated). |
| `description` | The description of the assignment (possibly truncated). |
| `due_at` | The due date for the assignment. |
| `unlock_at` | The unlock date (assignment is unlocked after this date) |
| `lock_at` | The lock date (assignment is locked after this date) |
| `updated_at` | The time at which this assignment was last modified in any way |
| `points_possible` | The maximum points possible for the assignment |
#### `submission_created`
| Field | Description |
| ----- | ----------- |
| `submission_id` | The Canvas id of the new submission. |
| `assignment_id` | The Canvas id of the assignment being submitted. |
| `submitted_at` | The timestamp when the assignment was submitted. |
| `updated_at` | The time at which this assignment was last modified in any way |
| `score` | The raw score |
| `grade` | The grade for the submission, translated into the assignment grading scheme (so a letter grade, for example)|
| `submission_type` | The types of submission ex: ('online_text_entry'|'online_url'|'online_upload'|'media_recording') |
| `body` | The content of the submission, if it was submitted directly in a text field. (possibly truncated)|
| `url` | The URL of the submission (for 'online_url' submissions) |
| `attempt` | This is the submission attempt number.|
#### `submission_updated`
| Field | Description |
| ----- | ----------- |
| `submission_id` | The Canvas id of the new submission. |
| `assignment_id` | The Canvas id of the assignment being submitted. |
| `submitted_at` | The timestamp when the assignment was submitted. |
| `updated_at` | The time at which this assignment was last modified in any way |
| `score` | The raw score |
| `grade` | The grade for the submission, translated into the assignment grading scheme (so a letter grade, for example)|
| `submission_type` | The types of submission ex: ('online_text_entry'|'online_url'|'online_upload'|'media_recording') |
| `body` | The content of the submission, if it was submitted directly in a text field. (possibly truncated) |
| `url` | The URL of the submission (for 'online_url' submissions) |
| `attempt` | This is the submission attempt number.|

View File

@ -59,6 +59,50 @@ module Canvas::LiveEvents
})
end
def self.get_assignment_data(assignment)
{
assignment_id: assignment.global_id,
title: LiveEvents.truncate(assignment.title),
description: LiveEvents.truncate(assignment.description),
due_at: assignment.due_at,
unlock_at: assignment.unlock_at,
lock_at: assignment.lock_at,
updated_at: assignment.updated_at,
points_possible: assignment.points_possible
}
end
def self.get_submission_data(submission)
{
submission_id: submission.global_id,
assignment_id: submission.global_assignment_id,
submitted_at: submission.submitted_at,
updated_at: submission.updated_at,
score: submission.score,
grade: submission.grade,
submission_type: submission.submission_type,
body: LiveEvents.truncate(submission.body),
url: submission.url,
attempt: submission.attempt
}
end
def self.assignment_created(assignment)
LiveEvents.post_event('assignment_created', get_assignment_data(assignment))
end
def self.submission_created(submission)
LiveEvents.post_event('submission_created', get_submission_data(submission))
end
def self.assignment_updated(assignment)
LiveEvents.post_event('assignment_updated', get_assignment_data(assignment))
end
def self.submission_updated(submission)
LiveEvents.post_event('submission_updated', get_submission_data(submission))
end
def self.logged_in(session)
LiveEvents.post_event('logged_in', {
redirect_url: session[:return_to]

View File

@ -54,5 +54,28 @@ describe LiveEventsObserver do
Canvas::LiveEvents.expects(:discussion_topic_created).once
c.discussion_topics.create!(:message => 'test')
end
it "should post an event when an assignment is created" do
Canvas::LiveEvents.expects(:assignment_created).once
assignment_model
end
it "should post an event when an assignment is updated" do
Canvas::LiveEvents.expects(:assignment_updated).once
a = assignment_model
a.title="dirty"
a.save
end
it "should post an event when a submission is created" do
Canvas::LiveEvents.expects(:submission_created).once
submission_model
end
it "should post an event when a submission is updated" do
Canvas::LiveEvents.expects(:submission_updated).once
s = submission_model
s.touch
end
end