canvas_sync 0.3.23 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +2 -0
- data/lib/canvas_sync.rb +11 -1
- data/lib/canvas_sync/generators/templates/services/live_events/assignment/assignment_created_event.rb +5 -4
- data/lib/canvas_sync/generators/templates/services/live_events/assignment/assignment_event.rb +40 -49
- data/lib/canvas_sync/generators/templates/services/live_events/assignment/assignment_updated_event.rb +5 -3
- data/lib/canvas_sync/generators/templates/services/live_events/base_event.rb +12 -19
- data/lib/canvas_sync/generators/templates/services/live_events/course/course_created_event.rb +5 -3
- data/lib/canvas_sync/generators/templates/services/live_events/course/course_event.rb +32 -38
- data/lib/canvas_sync/generators/templates/services/live_events/course/course_updated_event.rb +5 -3
- data/lib/canvas_sync/generators/templates/services/live_events/enrollment/enrollment_created_event.rb +5 -3
- data/lib/canvas_sync/generators/templates/services/live_events/enrollment/enrollment_event.rb +53 -56
- data/lib/canvas_sync/generators/templates/services/live_events/enrollment/enrollment_updated_event.rb +5 -3
- data/lib/canvas_sync/generators/templates/services/live_events/grade/grade_changed_event.rb +5 -3
- data/lib/canvas_sync/generators/templates/services/live_events/grade/grade_event.rb +47 -48
- data/lib/canvas_sync/generators/templates/services/live_events/module/module_created_event.rb +6 -0
- data/lib/canvas_sync/generators/templates/services/live_events/module/module_event.rb +39 -0
- data/lib/canvas_sync/generators/templates/services/live_events/module/module_updated_event.rb +6 -0
- data/lib/canvas_sync/generators/templates/services/live_events/submission/submission_created_event.rb +5 -3
- data/lib/canvas_sync/generators/templates/services/live_events/submission/submission_event.rb +40 -45
- data/lib/canvas_sync/generators/templates/services/live_events/submission/submission_updated_event.rb +5 -3
- data/lib/canvas_sync/generators/templates/services/live_events/syllabus/syllabus_event.rb +29 -30
- data/lib/canvas_sync/generators/templates/services/live_events/syllabus/syllabus_updated_event.rb +4 -2
- data/lib/canvas_sync/generators/templates/services/live_events/user/user_created_event.rb +5 -3
- data/lib/canvas_sync/generators/templates/services/live_events/user/user_event.rb +5 -8
- data/lib/canvas_sync/generators/templates/services/live_events/user/user_updated_event.rb +5 -3
- data/lib/canvas_sync/version.rb +1 -1
- data/spec/canvas_sync/services/module_event_spec.rb +42 -0
- data/spec/dummy/app/services/live_events/assignment_created_event.rb +12 -0
- data/spec/dummy/app/services/live_events/assignment_event.rb +60 -0
- data/spec/dummy/app/services/live_events/assignment_updated_event.rb +12 -0
- data/spec/dummy/app/services/live_events/base_event.rb +22 -0
- data/spec/dummy/app/services/live_events/course_created_event.rb +12 -0
- data/spec/dummy/app/services/live_events/course_event.rb +42 -0
- data/spec/dummy/app/services/live_events/course_updated_event.rb +12 -0
- data/spec/dummy/app/services/live_events/enrollment_created_event.rb +12 -0
- data/spec/dummy/app/services/live_events/enrollment_event.rb +61 -0
- data/spec/dummy/app/services/live_events/enrollment_updated_event.rb +12 -0
- data/spec/dummy/app/services/live_events/grade_changed_event.rb +12 -0
- data/spec/dummy/app/services/live_events/grade_event.rb +61 -0
- data/spec/dummy/app/services/live_events/module_created_event.rb +12 -0
- data/spec/dummy/app/services/live_events/module_event.rb +45 -0
- data/spec/dummy/app/services/live_events/module_updated_event.rb +12 -0
- data/spec/dummy/app/services/live_events/submission_created_event.rb +12 -0
- data/spec/dummy/app/services/live_events/submission_event.rb +58 -0
- data/spec/dummy/app/services/live_events/submission_updated_event.rb +12 -0
- data/spec/dummy/app/services/live_events/syllabus_event.rb +40 -0
- data/spec/dummy/app/services/live_events/syllabus_updated_event.rb +12 -0
- data/spec/dummy/app/services/live_events/user_created_event.rb +12 -0
- data/spec/dummy/app/services/live_events/user_event.rb +38 -0
- data/spec/dummy/app/services/live_events/user_updated_event.rb +12 -0
- data/spec/dummy/log/development.log +666 -0
- data/spec/dummy/log/test.log +3758 -0
- data/spec/support/fake_canvas.rb +4 -0
- data/spec/support/fixtures/canvas_responses/module.json +12 -0
- metadata +57 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9134dcc286332c0330b16783033e524f75b69f7039455d2e0aab562a50709181
|
4
|
+
data.tar.gz: 6575d7cb108b9977015db6f0e55c9de6fc3d7e0c8753e18889b381384d87b6e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d21d1deaec48dc3eb4c008eacdf0336373a4aa3a0e0bf4d9e68050b65b7529be883756408b97999aa13a78d6c1c158412beaf3413fef87ece53a1623651be91b
|
7
|
+
data.tar.gz: f8e73459889128a11793ecb0d9edf423edc3504c071eec4ed8728b79764f803395aa71a9a348108e38604eab1aedeba815cd023f75cfaa740686c22a5adec181
|
data/Rakefile
CHANGED
@@ -10,6 +10,8 @@ desc 'This updates the models and migrations used by the testing Rails Dummy app
|
|
10
10
|
task :update_test_schema do
|
11
11
|
puts "Updating test models and migration files..."
|
12
12
|
stream_command("spec/dummy/bin/rails generate canvas_sync:install --models all --force")
|
13
|
+
puts "Updating live event files..."
|
14
|
+
stream_command("spec/dummy/bin/rails generate canvas_sync:install_live_events --events all --force")
|
13
15
|
puts "Updating the test database and schema..."
|
14
16
|
stream_command("cd spec/dummy; bundle exec rake db:drop; bundle exec rake db:create; bundle exec rake db:migrate")
|
15
17
|
end
|
data/lib/canvas_sync.rb
CHANGED
@@ -36,7 +36,17 @@ module CanvasSync
|
|
36
36
|
context_module_items
|
37
37
|
xlist
|
38
38
|
].freeze
|
39
|
-
|
39
|
+
|
40
|
+
SUPPORTED_LIVE_EVENTS = %w[
|
41
|
+
course
|
42
|
+
enrollment
|
43
|
+
submission
|
44
|
+
assignment
|
45
|
+
user
|
46
|
+
syllabus
|
47
|
+
grade
|
48
|
+
module
|
49
|
+
].freeze
|
40
50
|
|
41
51
|
# Runs a standard provisioning sync job with no extra report types.
|
42
52
|
# Terms will be synced first using the API. If you are syncing users/roles/admins
|
data/lib/canvas_sync/generators/templates/services/live_events/assignment/assignment_event.rb
CHANGED
@@ -1,63 +1,54 @@
|
|
1
|
-
<%= autogenerated_event_warning %>
|
1
|
+
# <%= autogenerated_event_warning %>
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
3
|
+
module LiveEvents
|
4
|
+
class AssignmentEvent < LiveEvents::BaseEvent
|
5
|
+
# The following is provided in the live events call:
|
6
|
+
# {
|
7
|
+
# assignment_id: assignment.global_id,
|
8
|
+
# context_id: assignment.global_context_id,
|
9
|
+
# context_type: assignment.context_type,
|
10
|
+
# workflow_state: assignment.workflow_state,
|
11
|
+
# title: LiveEvents.truncate(assignment.title),
|
12
|
+
# description: LiveEvents.truncate(assignment.description),
|
13
|
+
# due_at: assignment.due_at,
|
14
|
+
# unlock_at: assignment.unlock_at,
|
15
|
+
# lock_at: assignment.lock_at,
|
16
|
+
# updated_at: assignment.updated_at,
|
17
|
+
# points_possible: assignment.points_possible
|
18
|
+
# }
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
def perform(event_payload)
|
21
|
+
super
|
22
|
+
attrs = {
|
22
23
|
canvas_assignment_id: local_canvas_id(payload[:assignment_id]),
|
23
|
-
|
24
|
-
name: payload[:title],
|
24
|
+
title: payload[:title],
|
25
25
|
workflow_state: payload[:workflow_state],
|
26
26
|
description: payload[:description],
|
27
27
|
due_at: payload[:due_at],
|
28
28
|
unlock_at: payload[:unlock_at],
|
29
29
|
lock_at: payload[:lock_at],
|
30
30
|
points_possible: payload[:points_possible],
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
rescue => e
|
35
|
-
log_error e
|
36
|
-
ensure
|
37
|
-
true
|
38
|
-
end
|
31
|
+
}
|
32
|
+
create_or_update(attrs)
|
33
|
+
end
|
39
34
|
|
40
|
-
|
41
|
-
def create_or_update(attrs)
|
42
|
-
assignment = Assignment.where(canvas_assignment_id: attrs[:canvas_assignment_id]).first_or_initialize
|
43
|
-
assignment.assign_attributes(attrs)
|
44
|
-
assignment.save!
|
45
|
-
assignment
|
46
|
-
end
|
35
|
+
private
|
47
36
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
37
|
+
def create_or_update(attrs)
|
38
|
+
assignment = Assignment.where(canvas_assignment_id: attrs[:canvas_assignment_id]).first_or_initialize
|
39
|
+
assignment.assign_attributes(attrs)
|
40
|
+
assignment.save!
|
41
|
+
assignment
|
42
|
+
end
|
52
43
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
if canvas_course_id.present?
|
57
|
-
@course = Course.find_by(canvas_course_id: canvas_course_id)
|
58
|
-
end
|
44
|
+
# This could be nil if the context type for this assignment is not 'Course' of if a local course was not found
|
45
|
+
def canvas_course_id
|
46
|
+
payload[:context_type] == "Course" ? local_canvas_id(payload[:context_id]) : nil
|
59
47
|
end
|
60
|
-
@course
|
61
|
-
end
|
62
48
|
|
63
|
-
|
49
|
+
# This could be nil if the context type for this assignment is not 'Course' of if a local course was not found
|
50
|
+
def course
|
51
|
+
@course ||= Course.find_by(canvas_course_id: canvas_course_id)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -1,23 +1,16 @@
|
|
1
|
-
<%= autogenerated_event_warning %>
|
1
|
+
# <%= autogenerated_event_warning %>
|
2
2
|
|
3
|
-
|
3
|
+
module LiveEvents
|
4
|
+
class BaseEvent < CanvasSync::Job
|
5
|
+
attr_accessor :payload
|
4
6
|
|
5
|
-
|
7
|
+
def perform(event_payload)
|
8
|
+
@payload = HashWithIndifferentAccess.new(event_payload["body"])
|
9
|
+
end
|
6
10
|
|
7
|
-
|
8
|
-
|
11
|
+
# Live events will use a canvas global ID (cross shard) for any ID's provided. This method will return the local ID.
|
12
|
+
def local_canvas_id(id)
|
13
|
+
id.to_i % 10_000_000_000_000
|
14
|
+
end
|
9
15
|
end
|
10
|
-
|
11
|
-
# Live events will use a canvas global ID (cross shard) for any ID's provided. This method will return the local ID.
|
12
|
-
def local_canvas_id(id)
|
13
|
-
id.to_i % 10_000_000_000_000
|
14
|
-
end
|
15
|
-
|
16
|
-
def log_error(e)
|
17
|
-
Rails.logger.error "Error processing Live Event: #{self.class.name}"
|
18
|
-
Rails.logger.error "#{payload}"
|
19
|
-
Rails.logger.error e.message
|
20
|
-
Rails.logger.error e.backtrace.join("\n")
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
16
|
+
end
|
@@ -1,42 +1,36 @@
|
|
1
|
-
<%= autogenerated_event_warning %>
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
attrs = {
|
1
|
+
# <%= autogenerated_event_warning %>
|
2
|
+
|
3
|
+
module LiveEvents
|
4
|
+
class CourseEvent < LiveEvents::BaseEvent
|
5
|
+
# The following is provided in the live events call:
|
6
|
+
# {
|
7
|
+
# course_id: course.global_id,
|
8
|
+
# uuid: course.uuid,
|
9
|
+
# account_id: course.global_account_id,
|
10
|
+
# name: course.name,
|
11
|
+
# created_at: course.created_at,
|
12
|
+
# updated_at: course.updated_at,
|
13
|
+
# workflow_state: course.workflow_state
|
14
|
+
# }
|
15
|
+
|
16
|
+
def perform(event_payload)
|
17
|
+
super
|
18
|
+
attrs = {
|
20
19
|
canvas_course_id: local_canvas_id(payload[:course_id]),
|
21
20
|
canvas_account_id: local_canvas_id(payload[:account_id]),
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
21
|
+
long_name: payload[:name],
|
22
|
+
status: payload[:workflow_state],
|
23
|
+
}
|
24
|
+
create_or_update(attrs)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def create_or_update(attrs)
|
30
|
+
course = Course.where(canva_course_id: attrs[:canva_course_id]).first_or_initialize
|
31
|
+
course.assign_attributes(attrs)
|
32
|
+
course.save!
|
33
|
+
course
|
34
|
+
end
|
30
35
|
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def create_or_update(attrs)
|
35
|
-
course = Course.where(canva_course_id: attrs[:canva_course_id]).first_or_initialize
|
36
|
-
course.assign_attributes(attrs)
|
37
|
-
course.save!
|
38
|
-
course
|
39
|
-
end
|
40
|
-
|
41
36
|
end
|
42
|
-
|
data/lib/canvas_sync/generators/templates/services/live_events/enrollment/enrollment_event.rb
CHANGED
@@ -1,58 +1,55 @@
|
|
1
|
-
<%= autogenerated_event_warning %>
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
1
|
+
# <%= autogenerated_event_warning %>
|
2
|
+
|
3
|
+
module LiveEvents
|
4
|
+
class EnrollmentEvent < LiveEvents::BaseEvent
|
5
|
+
# The following is provided in the live events call:
|
6
|
+
# {
|
7
|
+
#
|
8
|
+
# enrollment_id: enrollment.global_id,
|
9
|
+
# course_id: enrollment.global_course_id,
|
10
|
+
# user_id: enrollment.global_user_id,
|
11
|
+
# user_name: enrollment.user_name,
|
12
|
+
# type: enrollment.type,
|
13
|
+
# created_at: enrollment.created_at,
|
14
|
+
# updated_at: enrollment.updated_at,
|
15
|
+
# limit_privileges_to_course_section: enrollment.limit_privileges_to_course_section,
|
16
|
+
# course_section_id: enrollment.global_course_section_id,
|
17
|
+
# workflow_state: enrollment.workflow_state
|
18
|
+
# }
|
19
|
+
|
20
|
+
def perform(payload)
|
21
|
+
super
|
22
|
+
return if course.nil? || section.nil? || user.nil?
|
23
|
+
attrs = {
|
25
24
|
canvas_enrollment_id: local_canvas_id(payload[:enrollment_id]),
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
def user
|
56
|
-
@user ||= User.find_by(canvas_user_id: local_canvas_id(payload[:user_id]))
|
25
|
+
canvas_course_id: course.try(:id),
|
26
|
+
canvas_user_id: user.try(:id),
|
27
|
+
role: payload[:type],
|
28
|
+
canvas_section_id: section.try(:id),
|
29
|
+
status: payload[:workflow_state],
|
30
|
+
}
|
31
|
+
create_or_update(attrs)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def create_or_update(attrs)
|
37
|
+
enrollment = Enrollment.where(canvas_enrollment_id: attrs[:canvas_enrollment_id]).first_or_initialize
|
38
|
+
enrollment.assign_attributes(attrs)
|
39
|
+
enrollment.save!
|
40
|
+
enrollment
|
41
|
+
end
|
42
|
+
|
43
|
+
def course
|
44
|
+
@course ||= Course.find_by(canvas_course_id: local_canvas_id(payload[:course_id]))
|
45
|
+
end
|
46
|
+
|
47
|
+
def section
|
48
|
+
@section ||= Section.find_by(canvas_section_id: local_canvas_id(payload[:section_id]))
|
49
|
+
end
|
50
|
+
|
51
|
+
def user
|
52
|
+
@user ||= User.find_by(canvas_user_id: local_canvas_id(payload[:user_id]))
|
53
|
+
end
|
57
54
|
end
|
58
|
-
end
|
55
|
+
end
|
@@ -1,56 +1,55 @@
|
|
1
|
-
<%= autogenerated_event_warning %>
|
1
|
+
# <%= autogenerated_event_warning %>
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
3
|
+
module LiveEvents
|
4
|
+
class GradeEvent < LiveEvents::BaseEvent
|
5
|
+
# The following is provided in the live events call:
|
6
|
+
# {
|
7
|
+
# submission_id: submission.global_id,
|
8
|
+
# assignment_id: submission.global_assignment_id,
|
9
|
+
# grade: submission.grade,
|
10
|
+
# old_grade: old_submission.try(:grade),
|
11
|
+
# score: submission.score,
|
12
|
+
# old_score: old_submission.try(:score),
|
13
|
+
# points_possible: submission.assignment.points_possible,
|
14
|
+
# old_points_possible: old_assignment.points_possible,
|
15
|
+
# grader_id: grader_id,
|
16
|
+
# student_id: submission.global_user_id,
|
17
|
+
# user_id: submission.global_user_id,
|
18
|
+
# grading_complete: submission.graded?,
|
19
|
+
# muted: submission.muted_assignment?
|
20
|
+
# }
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
log_error e
|
36
|
-
ensure
|
37
|
-
true
|
38
|
-
end
|
22
|
+
def perform(event_payload)
|
23
|
+
super
|
24
|
+
attrs = {
|
25
|
+
submission_id: submission.try(:id),
|
26
|
+
assignment_id: assignment.try(:id),
|
27
|
+
score: payload[:score],
|
28
|
+
points_possible: payload[:points_possible],
|
29
|
+
grader_id: payload[:grader_id],
|
30
|
+
user_id: user.try(:id),
|
31
|
+
grading_complete: payload[:grading_complete],
|
32
|
+
muted: payload[:muted],
|
33
|
+
}
|
34
|
+
create_or_update(attrs)
|
35
|
+
end
|
39
36
|
|
40
|
-
|
41
|
-
def create_or_update(attrs)
|
42
|
-
# Todo: add your code here
|
43
|
-
end
|
37
|
+
private
|
44
38
|
|
45
|
-
|
46
|
-
|
47
|
-
|
39
|
+
def create_or_update(attrs)
|
40
|
+
# TODO: add your code here
|
41
|
+
end
|
48
42
|
|
49
|
-
|
50
|
-
|
51
|
-
|
43
|
+
def submission
|
44
|
+
Submission.find_by(canvas_submission_id: local_canvas_id(payload[:submission_id]))
|
45
|
+
end
|
46
|
+
|
47
|
+
def assignment
|
48
|
+
Assignment.find_by(canvas_assignment_id: local_canvas_id(payload[:assignment_id]))
|
49
|
+
end
|
52
50
|
|
53
|
-
|
54
|
-
|
51
|
+
def user
|
52
|
+
User.find_by(canvas_user_id: local_canvas_id(payload[:user_id]))
|
53
|
+
end
|
55
54
|
end
|
56
55
|
end
|