canvas_sync 0.9.4 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +8 -0
  3. data/lib/canvas_sync/api_syncable.rb +1 -0
  4. data/lib/canvas_sync/generators/install_generator.rb +3 -3
  5. data/lib/canvas_sync/generators/templates/migrations/create_accounts.rb +17 -0
  6. data/lib/canvas_sync/generators/templates/{models → migrations}/create_admins.rb +2 -2
  7. data/lib/canvas_sync/generators/templates/{models → migrations}/create_assignment_groups.rb +2 -2
  8. data/lib/canvas_sync/generators/templates/{models → migrations}/create_assignments.rb +7 -7
  9. data/lib/canvas_sync/generators/templates/{models → migrations}/create_context_module_items.rb +4 -4
  10. data/lib/canvas_sync/generators/templates/{models → migrations}/create_context_modules.rb +2 -2
  11. data/lib/canvas_sync/generators/templates/{models → migrations}/create_courses.rb +7 -8
  12. data/lib/canvas_sync/generators/templates/{models → migrations}/create_enrollments.rb +4 -6
  13. data/lib/canvas_sync/generators/templates/{models → migrations}/create_roles.rb +2 -2
  14. data/lib/canvas_sync/generators/templates/{models → migrations}/create_sections.rb +5 -5
  15. data/lib/canvas_sync/generators/templates/{models → migrations}/create_submissions.rb +2 -2
  16. data/lib/canvas_sync/generators/templates/{models → migrations}/create_terms.rb +2 -2
  17. data/lib/canvas_sync/generators/templates/{models → migrations}/create_users.rb +4 -4
  18. data/lib/canvas_sync/generators/templates/models/account.rb +4 -4
  19. data/lib/canvas_sync/generators/templates/models/admin.rb +4 -4
  20. data/lib/canvas_sync/generators/templates/models/assignment.rb +10 -9
  21. data/lib/canvas_sync/generators/templates/models/assignment_group.rb +5 -5
  22. data/lib/canvas_sync/generators/templates/models/context_module.rb +2 -2
  23. data/lib/canvas_sync/generators/templates/models/context_module_item.rb +3 -2
  24. data/lib/canvas_sync/generators/templates/models/course.rb +14 -14
  25. data/lib/canvas_sync/generators/templates/models/enrollment.rb +10 -9
  26. data/lib/canvas_sync/generators/templates/models/role.rb +3 -3
  27. data/lib/canvas_sync/generators/templates/models/section.rb +6 -6
  28. data/lib/canvas_sync/generators/templates/models/submission.rb +5 -5
  29. data/lib/canvas_sync/generators/templates/models/term.rb +4 -3
  30. data/lib/canvas_sync/generators/templates/models/user.rb +6 -6
  31. data/lib/canvas_sync/generators/templates/services/live_events/base_event.rb +4 -0
  32. data/lib/canvas_sync/generators/templates/services/live_events/course/course_event.rb +1 -1
  33. data/lib/canvas_sync/generators/templates/services/live_events/course_section/course_section_event.rb +4 -4
  34. data/lib/canvas_sync/generators/templates/services/live_events/module/module_event.rb +1 -1
  35. data/lib/canvas_sync/generators/templates/services/live_events/module_item/module_item_event.rb +3 -3
  36. data/lib/canvas_sync/generators/templates/services/live_events/user/user_event.rb +1 -1
  37. data/lib/canvas_sync/jobs/sync_provisioning_report_job.rb +7 -2
  38. data/lib/canvas_sync/jobs/sync_simple_table_job.rb +7 -2
  39. data/lib/canvas_sync/processors/model_mappings.yml +35 -41
  40. data/lib/canvas_sync/version.rb +1 -1
  41. data/spec/canvas_sync/jobs/sync_provisioning_report_job_spec.rb +4 -4
  42. data/spec/canvas_sync/jobs/sync_simple_table_job_spec.rb +3 -3
  43. data/spec/canvas_sync/models/accounts_spec.rb +2 -2
  44. data/spec/canvas_sync/models/admins_spec.rb +3 -3
  45. data/spec/canvas_sync/models/assignment_group_spec.rb +4 -4
  46. data/spec/canvas_sync/models/assignment_spec.rb +8 -8
  47. data/spec/canvas_sync/models/context_module_spec.rb +2 -2
  48. data/spec/canvas_sync/models/course_spec.rb +7 -8
  49. data/spec/canvas_sync/models/enrollment_spec.rb +5 -5
  50. data/spec/canvas_sync/models/roles_spec.rb +3 -3
  51. data/spec/canvas_sync/models/section_spec.rb +4 -4
  52. data/spec/canvas_sync/models/submission_spec.rb +5 -5
  53. data/spec/canvas_sync/models/term_spec.rb +7 -7
  54. data/spec/canvas_sync/models/user_spec.rb +4 -4
  55. data/spec/canvas_sync/processors/provisioning_report_processor_spec.rb +5 -5
  56. data/spec/canvas_sync/services/module_event_spec.rb +1 -1
  57. data/spec/canvas_sync/services/module_item_event_spec.rb +7 -7
  58. data/spec/dummy/app/models/account.rb +9 -1
  59. data/spec/dummy/app/models/admin.rb +4 -4
  60. data/spec/dummy/app/models/assignment.rb +23 -5
  61. data/spec/dummy/app/models/assignment_group.rb +15 -3
  62. data/spec/dummy/app/models/context_module.rb +2 -2
  63. data/spec/dummy/app/models/context_module_item.rb +3 -2
  64. data/spec/dummy/app/models/course.rb +20 -7
  65. data/spec/dummy/app/models/enrollment.rb +20 -4
  66. data/spec/dummy/app/models/role.rb +3 -3
  67. data/spec/dummy/app/models/section.rb +14 -3
  68. data/spec/dummy/app/models/submission.rb +16 -4
  69. data/spec/dummy/app/models/term.rb +4 -3
  70. data/spec/dummy/app/models/user.rb +15 -4
  71. data/spec/dummy/app/services/live_events/base_event.rb +4 -0
  72. data/spec/dummy/app/services/live_events/course_event.rb +1 -1
  73. data/spec/dummy/app/services/live_events/course_section_event.rb +4 -4
  74. data/spec/dummy/app/services/live_events/module_event.rb +1 -1
  75. data/spec/dummy/app/services/live_events/module_item_event.rb +3 -3
  76. data/spec/dummy/app/services/live_events/user_event.rb +1 -1
  77. data/spec/dummy/db/migrate/{20180216171618_create_submissions.rb → 20190521003447_create_submissions.rb} +4 -4
  78. data/spec/dummy/db/migrate/{20180103162102_create_roles.rb → 20190521003448_create_roles.rb} +2 -2
  79. data/spec/dummy/db/migrate/{20180109210452_create_admins.rb → 20190521003449_create_admins.rb} +2 -2
  80. data/spec/dummy/db/migrate/{20180222163506_create_assignment_groups.rb → 20190521003450_create_assignment_groups.rb} +2 -2
  81. data/spec/dummy/db/migrate/{20180411215348_create_context_modules.rb → 20190521003451_create_context_modules.rb} +2 -2
  82. data/spec/dummy/db/migrate/{20180215214227_create_assignments.rb → 20190603192310_create_assignments.rb} +11 -11
  83. data/spec/dummy/db/migrate/{20180605172338_create_context_module_items.rb → 20190603193502_create_context_module_items.rb} +4 -4
  84. data/spec/dummy/db/migrate/{20180509194201_create_users.rb → 20190603215718_create_users.rb} +4 -4
  85. data/spec/dummy/db/migrate/{20170906193506_create_terms.rb → 20190603215721_create_terms.rb} +2 -2
  86. data/spec/dummy/db/migrate/{20171107213207_create_sections.rb → 20190603215722_create_sections.rb} +5 -5
  87. data/spec/dummy/db/migrate/{20170914181345_create_courses.rb → 20190603220011_create_courses.rb} +7 -8
  88. data/spec/dummy/db/migrate/{20170905192509_create_enrollments.rb → 20190603220013_create_enrollments.rb} +4 -6
  89. data/spec/dummy/db/migrate/{20180220172559_create_accounts.rb → 20190604193942_create_accounts.rb} +6 -6
  90. data/spec/dummy/db/schema.rb +56 -58
  91. data/spec/dummy/log/test.log +1350 -0
  92. data/spec/factories/account_factory.rb +5 -5
  93. data/spec/factories/admin_factory.rb +1 -1
  94. data/spec/factories/assignment_factory.rb +1 -1
  95. data/spec/factories/assignment_group_factory.rb +1 -1
  96. data/spec/factories/context_module_factory.rb +2 -2
  97. data/spec/factories/context_module_item_factory.rb +1 -1
  98. data/spec/factories/course_factory.rb +5 -5
  99. data/spec/factories/enrollment_factory.rb +1 -1
  100. data/spec/factories/role_factory.rb +1 -1
  101. data/spec/factories/section_factory.rb +1 -1
  102. data/spec/factories/submission_factory.rb +1 -1
  103. data/spec/factories/term_factory.rb +1 -1
  104. data/spec/factories/user_factory.rb +1 -1
  105. data/spec/spec_helper.rb +1 -0
  106. metadata +41 -41
  107. data/lib/canvas_sync/generators/templates/models/create_accounts.rb +0 -17
@@ -16,7 +16,7 @@ RSpec.describe LiveEvents::ModuleEvent do
16
16
 
17
17
  describe "#perform" do
18
18
  context "the module already exists" do
19
- let!(:context_module) { FactoryGirl.create(:context_module, canvas_context_module_id: payload["body"][:module_id]) }
19
+ let!(:context_module) { FactoryGirl.create(:context_module, canvas_id: payload["body"][:module_id]) }
20
20
 
21
21
  it "updates it" do
22
22
  expect {
@@ -16,17 +16,17 @@ RSpec.describe LiveEvents::ModuleItemEvent do
16
16
 
17
17
  describe "#perform" do
18
18
  context "the module item already exists" do
19
- let!(:cmi) { FactoryGirl.create(:context_module_item, canvas_context_module_item_id: payload["body"][:module_item_id]) }
19
+ let!(:cmi) { FactoryGirl.create(:context_module_item, canvas_id: payload["body"][:module_item_id]) }
20
20
 
21
21
  it "updates it" do
22
22
  expect {
23
23
  LiveEvents::ModuleItemEvent.new.perform(payload)
24
24
  }.to_not change { ContextModuleItem.count }
25
- expect(cmi.reload.canvas_context_module_id).to eq(payload["body"][:module_item_id])
25
+ expect(cmi.reload.canvas_id).to eq(payload["body"][:module_item_id])
26
26
  expect(cmi.position).to eq(payload["body"][:position])
27
27
  expect(cmi.workflow_state).to eq(payload["body"][:workflow_state])
28
- expect(cmi.content_type).to eq("Assignment")
29
- expect(cmi.content_id).to eq(143)
28
+ expect(cmi.canvas_content_type).to eq("Assignment")
29
+ expect(cmi.canvas_content_id).to eq(143)
30
30
  end
31
31
  end
32
32
 
@@ -36,11 +36,11 @@ RSpec.describe LiveEvents::ModuleItemEvent do
36
36
  LiveEvents::ModuleItemEvent.new.perform(payload)
37
37
  }.to change { ContextModuleItem.count }.by(1)
38
38
  cmi = ContextModuleItem.last
39
- expect(cmi.canvas_context_module_id).to eq(payload["body"][:module_item_id])
39
+ expect(cmi.canvas_id).to eq(payload["body"][:module_item_id])
40
40
  expect(cmi.position).to eq(payload["body"][:position])
41
41
  expect(cmi.workflow_state).to eq(payload["body"][:workflow_state])
42
- expect(cmi.content_type).to eq("Assignment")
43
- expect(cmi.content_id).to eq(143)
42
+ expect(cmi.canvas_content_type).to eq("Assignment")
43
+ expect(cmi.canvas_content_id).to eq(143)
44
44
  end
45
45
  end
46
46
  end
@@ -7,5 +7,13 @@
7
7
 
8
8
 
9
9
  class Account < ApplicationRecord
10
- validates :canvas_account_id, uniqueness: true, presence: true
10
+ include CanvasSync::ApiSyncable
11
+
12
+ validates :canvas_id, uniqueness: true, presence: true
13
+
14
+ api_syncable({
15
+ name: :name,
16
+ workflow_state: :workflow_state,
17
+ canvas_parent_account_id: :parent_account_id,
18
+ }, -> (api) { api.account(canvas_id) })
11
19
  end
@@ -7,12 +7,12 @@
7
7
 
8
8
 
9
9
  class Admin < ApplicationRecord
10
- validates :canvas_admin_id, uniqueness: true, presence: true
11
- belongs_to :user, primary_key: :canvas_user_id, foreign_key: :canvas_user_id, optional: true
12
- belongs_to :role, primary_key: :canvas_role_id, foreign_key: :canvas_role_id, optional: true
10
+ validates :canvas_id, uniqueness: true, presence: true
11
+ belongs_to :user, primary_key: :canvas_id, foreign_key: :canvas_user_id, optional: true
12
+ belongs_to :role, primary_key: :canvas_id, foreign_key: :canvas_role_id, optional: true
13
13
 
14
14
  def self.create_or_update(admin_params)
15
- admin = Admin.find_or_initialize_by(canvas_admin_id: admin_params['id'])
15
+ admin = Admin.find_or_initialize_by(canvas_id: admin_params['id'])
16
16
 
17
17
  admin.assign_attributes(role_name: admin_params['role'],
18
18
  canvas_role_id: admin_params['role_id'],
@@ -7,10 +7,28 @@
7
7
 
8
8
 
9
9
  class Assignment < ApplicationRecord
10
- validates :canvas_assignment_id, uniqueness: true, presence: true
11
- belongs_to :context, polymorphic: true, optional: true, primary_key: :canvas_course_id
12
- belongs_to :assignment_group, optional: true, primary_key: :canvas_assignment_group_id, foreign_key: :canvas_assignment_group_id
13
- has_many :submissions, primary_key: :canvas_assignment_id, foreign_key: :canvas_assignment_id
14
- has_many :context_module_items, primary_key: :canvas_assignment_id, foreign_key: :content_id, dependent: :destroy
10
+ include CanvasSync::ApiSyncable
11
+
12
+ validates :canvas_id, uniqueness: true, presence: true
13
+ belongs_to :context, polymorphic: true, optional: true, primary_key: :canvas_id, foreign_key: :canvas_context_id, foreign_type: :canvas_context_type
14
+ belongs_to :assignment_group, optional: true, primary_key: :canvas_id, foreign_key: :canvas_assignment_group_id
15
+ has_many :submissions, primary_key: :canvas_id, foreign_key: :canvas_assignment_id
16
+
17
+ has_many :context_module_items, as: :content, primary_key: :canvas_id, foreign_key: :canvas_content_id, foreign_type: :canvas_content_type, dependent: :destroy
15
18
  has_many :context_modules, through: :context_module_items
19
+
20
+ api_syncable({
21
+ title: :name,
22
+ description: :description,
23
+ due_at: :due_at,
24
+ unlock_at: :unlock_at,
25
+ lock_at: :lock_at,
26
+ points_possible: :points_possible,
27
+ grading_type: :grading_type,
28
+ submission_types: lambda { |p| p["submission_types"].join(",") },
29
+ canvas_context_id: :course_id,
30
+ canvas_context_type: lambda { |_p| "Course" },
31
+ canvas_assignment_group_id: :assignment_group_id,
32
+ canvas_grading_standard_id: :grading_standard_id,
33
+ }, -> (api) { api.assignment(canvas_context_id, canvas_id) })
16
34
  end
@@ -7,7 +7,19 @@
7
7
 
8
8
 
9
9
  class AssignmentGroup < ApplicationRecord
10
- validates :canvas_assignment_group_id, uniqueness: true, presence: true
11
- belongs_to :course, primary_key: :canvas_course_id, foreign_key: :canvas_course_id, optional: true
12
- has_many :assignments, primary_key: :canvas_assignment_group_id, foreign_key: :canvas_assignment_group_id
10
+ include CanvasSync::ApiSyncable
11
+
12
+ validates :canvas_id, uniqueness: true, presence: true
13
+ belongs_to :course, primary_key: :canvas_id, foreign_key: :canvas_course_id, optional: true
14
+ has_many :assignments, primary_key: :canvas_id, foreign_key: :canvas_assignment_group_id
15
+
16
+ serialize :rules
17
+
18
+ api_syncable({
19
+ canvas_id: :id,
20
+ name: :name,
21
+ position: :position,
22
+ rules: :rules,
23
+ group_weight: :group_weight,
24
+ }, -> (api) { api.assignment(course_id, canvas_id) })
13
25
  end
@@ -10,7 +10,7 @@
10
10
  # 1 - Module is a reserved word in Rails and you can't call a model a Module
11
11
  # 2 - Canvas calls them ContextModules
12
12
  class ContextModule < ApplicationRecord
13
- belongs_to :canvas_context, polymorphic: true, optional: true
14
- has_many :context_module_items, primary_key: :canvas_context_module_id, foreign_key: :canvas_context_module_id
13
+ belongs_to :context, polymorphic: true, optional: true, primary_key: :canvas_id, foreign_key: :canvas_context_id, foreign_type: :canvas_context_type
14
+ has_many :context_module_items, primary_key: :canvas_id, foreign_key: :canvas_context_module_id
15
15
  has_many :assignments, through: :context_module_items
16
16
  end
@@ -7,6 +7,7 @@
7
7
 
8
8
 
9
9
  class ContextModuleItem < ApplicationRecord
10
- belongs_to :context_module, primary_key: :canvas_context_module_id, foreign_key: :canvas_context_module_id, optional: true
11
- belongs_to :assignment, foreign_key: :canvas_assignment_id, primary_key: :canvas_assignment_id
10
+ belongs_to :context_module, primary_key: :canvas_id, foreign_key: :canvas_context_module_id, optional: true
11
+ belongs_to :content, polymorphic: true, optional: true, primary_key: :canvas_id, foreign_key: :canvas_content_id, foreign_type: :canvas_content_type
12
+ belongs_to :assignment, foreign_key: :canvas_assignment_id, primary_key: :canvas_id
12
13
  end
@@ -7,11 +7,24 @@
7
7
 
8
8
 
9
9
  class Course < ApplicationRecord
10
- validates :canvas_course_id, uniqueness: true, presence: true
11
- belongs_to :term, foreign_key: :canvas_term_id, primary_key: :canvas_term_id, optional: true
12
- has_many :enrollments, primary_key: :canvas_course_id, foreign_key: :canvas_course_id
13
- has_many :sections, primary_key: :canvas_course_id, foreign_key: :canvas_course_id
14
- has_many :assignments, as: :context, primary_key: :canvas_course_id
15
- has_many :submissions, primary_key: :canvas_course_id, foreign_key: :canvas_course_id
16
- has_many :assignment_groups, primary_key: :canvas_course_id, foreign_key: :canvas_course_id
10
+ include CanvasSync::ApiSyncable
11
+
12
+ validates :canvas_id, uniqueness: true, presence: true
13
+ belongs_to :term, foreign_key: :canvas_term_id, primary_key: :canvas_id, optional: true
14
+ has_many :enrollments, primary_key: :canvas_id, foreign_key: :canvas_course_id
15
+ has_many :sections, primary_key: :canvas_id, foreign_key: :canvas_course_id
16
+ has_many :assignments, as: :context, primary_key: :canvas_id, foreign_key: :canvas_context_id, foreign_type: :canvas_context_type
17
+ has_many :submissions, primary_key: :canvas_id, foreign_key: :canvas_course_id
18
+ has_many :assignment_groups, primary_key: :canvas_id, foreign_key: :canvas_course_id
19
+
20
+ api_syncable({
21
+ sis_id: :sis_course_id,
22
+ course_code: :course_code,
23
+ name: :name,
24
+ workflow_state: :workflow_state,
25
+ canvas_term_id: :enrollment_term_id,
26
+ canvas_account_id: :account_id,
27
+ start_at: :start_at,
28
+ end_at: :end_at,
29
+ }, -> (api) { api.course(canvas_id) })
17
30
  end
@@ -7,8 +7,24 @@
7
7
 
8
8
 
9
9
  class Enrollment < ApplicationRecord
10
- validates :canvas_enrollment_id, uniqueness: true, presence: true
11
- belongs_to :user, primary_key: :canvas_user_id, foreign_key: :canvas_user_id, optional: true
12
- belongs_to :course, primary_key: :canvas_course_id, foreign_key: :canvas_course_id, optional: true
13
- belongs_to :section, primary_key: :canvas_section_id, foreign_key: :canvas_section_id, optional: true
10
+ include CanvasSync::ApiSyncable
11
+
12
+ validates :canvas_id, uniqueness: true, presence: true
13
+ belongs_to :user, primary_key: :canvas_id, foreign_key: :canvas_user_id, optional: true
14
+ belongs_to :role, primary_key: :canvas_id, foreign_key: :canvas_role_id, optional: true
15
+ belongs_to :course, primary_key: :canvas_id, foreign_key: :canvas_course_id, optional: true
16
+ belongs_to :section, primary_key: :canvas_id, foreign_key: :canvas_section_id, optional: true
17
+
18
+ api_syncable({
19
+ canvas_id: :id,
20
+ canvas_course_id: :course_id,
21
+ course_sis_id: :sis_course_id,
22
+ canvas_user_id: :user_id,
23
+ user_sis_id: :sis_user_id,
24
+ canvas_section_id: :course_section_id,
25
+ role: :role,
26
+ canvas_role_id: :role_id,
27
+ base_role_type: :type,
28
+ workflow_state: :enrollment_state,
29
+ }, -> (api) { api.enrollment("self", canvas_id) })
14
30
  end
@@ -7,11 +7,11 @@
7
7
 
8
8
 
9
9
  class Role < ApplicationRecord
10
- validates :canvas_role_id, uniqueness: true, presence: true
11
- has_many :admins, foreign_key: :canvas_role_id, primary_key: :canvas_role_id
10
+ validates :canvas_id, uniqueness: true, presence: true
11
+ has_many :admins, foreign_key: :canvas_role_id, primary_key: :canvas_id
12
12
 
13
13
  def self.create_or_update(role_params)
14
- role = Role.find_or_initialize_by(canvas_role_id: role_params['id'])
14
+ role = Role.find_or_initialize_by(canvas_id: role_params['id'])
15
15
 
16
16
  role.assign_attributes(label: role_params['label'],
17
17
  base_role_type: role_params['base_role_type'],
@@ -7,7 +7,18 @@
7
7
 
8
8
 
9
9
  class Section < ApplicationRecord
10
- validates :canvas_section_id, uniqueness: true, presence: true
11
- belongs_to :course, primary_key: :canvas_course_id, foreign_key: :canvas_course_id, optional: true
12
- has_many :enrollments, primary_key: :canvas_section_id, foreign_key: :canvas_section_id
10
+ include CanvasSync::ApiSyncable
11
+
12
+ validates :canvas_id, uniqueness: true, presence: true
13
+ belongs_to :course, primary_key: :canvas_id, foreign_key: :canvas_course_id, optional: true
14
+ has_many :enrollments, primary_key: :canvas_id, foreign_key: :canvas_section_id
15
+
16
+ api_syncable({
17
+ sis_id: :sis_section_id,
18
+ canvas_course_id: :course_id,
19
+ canvas_nonxlist_course_id: :nonxlist_course_id,
20
+ name: :name,
21
+ start_at: :start_at,
22
+ end_at: :end_at,
23
+ }, -> (api) { api.section(canvas_id) })
13
24
  end
@@ -7,8 +7,20 @@
7
7
 
8
8
 
9
9
  class Submission < ApplicationRecord
10
- validates :canvas_submission_id, uniqueness: true, presence: true
11
- belongs_to :assignment, primary_key: :canvas_assignment_id, foreign_key: :canvas_assignment_id, optional: true
12
- belongs_to :user, primary_key: :canvas_user_id, foreign_key: :canvas_user_id, optional: true
13
- belongs_to :course, primary_key: :canvas_course_id, foreign_key: :canvas_course_id, optional: true
10
+ include CanvasSync::ApiSyncable
11
+
12
+ validates :canvas_id, uniqueness: true, presence: true
13
+ belongs_to :assignment, primary_key: :canvas_id, foreign_key: :canvas_assignment_id, optional: true
14
+ belongs_to :user, primary_key: :canvas_id, foreign_key: :canvas_user_id, optional: true
15
+ belongs_to :course, primary_key: :canvas_id, foreign_key: :canvas_course_id, optional: true
16
+
17
+ api_syncable({
18
+ canvas_assignment_id: :assignment_id,
19
+ canvas_user_id: :user_id,
20
+ submitted_at: :submitted_at,
21
+ graded_at: :graded_at,
22
+ score: :score,
23
+ excused: :excused,
24
+ workflow_state: :workflow_state,
25
+ }, -> (api) { api.user_course_assignment_submission(assignment.context.canvas_id, canvas_assignment_id, canvas_user_id) })
14
26
  end
@@ -7,8 +7,8 @@
7
7
 
8
8
 
9
9
  class Term < ApplicationRecord
10
- validates :canvas_term_id, uniqueness: true, presence: true
11
- has_many :courses, foreign_key: :canvas_term_id, primary_key: :canvas_term_id
10
+ validates :canvas_id, uniqueness: true, presence: true
11
+ has_many :courses, foreign_key: :canvas_term_id, primary_key: :canvas_id
12
12
 
13
13
  # This is a sample scope created by the CanvasSync gem; feel
14
14
  # free to customize it for your tool's requirements.
@@ -19,7 +19,7 @@ class Term < ApplicationRecord
19
19
  }
20
20
 
21
21
  def self.create_or_update(term_params)
22
- term = Term.find_or_initialize_by(canvas_term_id: term_params['id'])
22
+ term = Term.find_or_initialize_by(canvas_id: term_params['id'])
23
23
 
24
24
  term.assign_attributes(name: term_params['name'],
25
25
  start_at: term_params['start_at'],
@@ -31,4 +31,5 @@ class Term < ApplicationRecord
31
31
  term.save! if term.changed?
32
32
  term
33
33
  end
34
+
34
35
  end
@@ -7,9 +7,20 @@
7
7
 
8
8
 
9
9
  class User < ApplicationRecord
10
- validates :canvas_user_id, uniqueness: true, presence: true
11
- has_many :enrollments, primary_key: :canvas_user_id, foreign_key: :canvas_user_id
12
- has_many :admins, foreign_key: :canvas_user_id, primary_key: :canvas_user_id
10
+ include CanvasSync::ApiSyncable
11
+
12
+ validates :canvas_id, uniqueness: true, presence: true
13
+ has_many :enrollments, primary_key: :canvas_id, foreign_key: :canvas_user_id
14
+ has_many :admins, primary_key: :canvas_id, foreign_key: :canvas_user_id
13
15
  has_many :admin_roles, through: :admins, source: :role
14
- has_many :submissions, primary_key: :canvas_user_id, foreign_key: :canvas_user_id
16
+ has_many :submissions, primary_key: :canvas_id, foreign_key: :canvas_user_id
17
+
18
+ api_syncable({
19
+ sis_id: :sis_user_id,
20
+ email: :email,
21
+ login_id: :login_id,
22
+ name: :name,
23
+ sortable_name: :sortable_name,
24
+ first_name: :short_name,
25
+ }, -> (api) { api.user_detail(canvas_id) })
15
26
  end
@@ -8,9 +8,13 @@
8
8
 
9
9
  module LiveEvents
10
10
  class BaseEvent < CanvasSync::Job
11
+ attr_accessor :raw_payload
11
12
  attr_accessor :payload
13
+ attr_accessor :metadata
12
14
 
13
15
  def perform(event_payload)
16
+ @raw_payload = event_payload
17
+ @metadata = HashWithIndifferentAccess.new(event_payload["attributes"])
14
18
  @payload = HashWithIndifferentAccess.new(event_payload["body"])
15
19
  end
16
20
 
@@ -24,7 +24,7 @@ module LiveEvents
24
24
  attrs = {
25
25
  canvas_course_id: local_canvas_id(payload[:course_id]),
26
26
  canvas_account_id: local_canvas_id(payload[:account_id]),
27
- long_name: payload[:name],
27
+ name: payload[:name],
28
28
  status: payload[:workflow_state],
29
29
  }
30
30
  create_or_update(attrs)
@@ -11,7 +11,7 @@ module LiveEvents
11
11
  # The following is provided in the live events call:
12
12
  # {
13
13
  # course_section_id: section.id,
14
- # sis_source_id: section.sis_source_id,
14
+ # sis_id: section.sis_id,
15
15
  # sis_batch_id: section.sis_batch_id,
16
16
  # course_id: section.course_id,
17
17
  # root_account_id: section.root_account_id,
@@ -35,9 +35,9 @@ module LiveEvents
35
35
  canvas_section_id: local_canvas_id(payload[:course_section_id]),
36
36
  canvas_course_id: local_canvas_id(payload[:course_id]),
37
37
  name: payload[:name],
38
- status: payload[:workflow_state],
39
- start_date: payload[:start_at],
40
- end_date: payload[:end_at],
38
+ workflow_state: payload[:workflow_state],
39
+ start_at: payload[:start_at],
40
+ end_at: payload[:end_at],
41
41
  canvas_nonxlist_course_id: payload[:nonxlist_course_id],
42
42
  }
43
43
  create_or_update(attrs)
@@ -27,7 +27,7 @@ module LiveEvents
27
27
 
28
28
  def create_or_update_from_api(payload)
29
29
  return unless payload["context_type"] == "Course"
30
- context_module = ContextModule.find_or_initialize_by(canvas_context_module_id: payload["module_id"])
30
+ context_module = ContextModule.find_or_initialize_by(canvas_id: payload["module_id"])
31
31
  api_params = canvas_sync_client.course_module(payload["context_id"], payload["module_id"])
32
32
 
33
33
  context_module.assign_attributes(
@@ -26,15 +26,15 @@ module LiveEvents
26
26
  private
27
27
 
28
28
  def create_or_update_from_api(payload)
29
- context_module_item = ContextModuleItem.find_or_initialize_by(canvas_context_module_item_id: payload["module_item_id"])
29
+ context_module_item = ContextModuleItem.find_or_initialize_by(canvas_id: payload["module_item_id"])
30
30
  api_params = canvas_sync_client.module_item(payload["context_id"], payload["module_id"], payload["module_item_id"])
31
31
 
32
32
  context_module_item.assign_attributes(
33
33
  canvas_context_module_id: payload["module_id"],
34
34
  position: payload["position"],
35
35
  workflow_state: payload["workflow_state"],
36
- content_id: api_params["content_id"],
37
- content_type: api_params["type"],
36
+ canvas_content_id: api_params["content_id"],
37
+ canvas_content_type: api_params["type"],
38
38
  )
39
39
 
40
40
  context_module_item.save! if context_module_item.changed?
@@ -23,7 +23,7 @@ module LiveEvents
23
23
  super
24
24
  attrs = {
25
25
  canvas_user_id: local_canvas_id(payload[:user_id]),
26
- full_name: payload[:name],
26
+ name: payload[:name],
27
27
  status: payload[:workflow_state],
28
28
  }
29
29
  create_or_update(attrs)
@@ -9,21 +9,21 @@
9
9
  class CreateSubmissions < ActiveRecord::Migration[5.1]
10
10
  def change
11
11
  create_table :submissions do |t|
12
- t.bigint :canvas_submission_id, null: false
12
+ t.bigint :canvas_id, null: false
13
13
  t.bigint :canvas_course_id
14
14
  t.bigint :canvas_assignment_id
15
15
  t.bigint :canvas_user_id
16
16
  t.datetime :submitted_at
17
17
  t.datetime :graded_at
18
- t.integer :score
19
- t.integer :points_possible
18
+ t.float :score
19
+ t.float :points_possible
20
20
  t.boolean :excused
21
21
  t.string :workflow_state
22
22
 
23
23
  t.timestamps
24
24
  end
25
25
 
26
- add_index :submissions, :canvas_submission_id, unique: true
26
+ add_index :submissions, :canvas_id, unique: true
27
27
  add_index :submissions, :canvas_assignment_id
28
28
  add_index :submissions, :canvas_course_id
29
29
  add_index :submissions, :canvas_user_id