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.
- checksums.yaml +4 -4
- data/README.md +8 -0
- data/lib/canvas_sync/api_syncable.rb +1 -0
- data/lib/canvas_sync/generators/install_generator.rb +3 -3
- data/lib/canvas_sync/generators/templates/migrations/create_accounts.rb +17 -0
- data/lib/canvas_sync/generators/templates/{models → migrations}/create_admins.rb +2 -2
- data/lib/canvas_sync/generators/templates/{models → migrations}/create_assignment_groups.rb +2 -2
- data/lib/canvas_sync/generators/templates/{models → migrations}/create_assignments.rb +7 -7
- data/lib/canvas_sync/generators/templates/{models → migrations}/create_context_module_items.rb +4 -4
- data/lib/canvas_sync/generators/templates/{models → migrations}/create_context_modules.rb +2 -2
- data/lib/canvas_sync/generators/templates/{models → migrations}/create_courses.rb +7 -8
- data/lib/canvas_sync/generators/templates/{models → migrations}/create_enrollments.rb +4 -6
- data/lib/canvas_sync/generators/templates/{models → migrations}/create_roles.rb +2 -2
- data/lib/canvas_sync/generators/templates/{models → migrations}/create_sections.rb +5 -5
- data/lib/canvas_sync/generators/templates/{models → migrations}/create_submissions.rb +2 -2
- data/lib/canvas_sync/generators/templates/{models → migrations}/create_terms.rb +2 -2
- data/lib/canvas_sync/generators/templates/{models → migrations}/create_users.rb +4 -4
- data/lib/canvas_sync/generators/templates/models/account.rb +4 -4
- data/lib/canvas_sync/generators/templates/models/admin.rb +4 -4
- data/lib/canvas_sync/generators/templates/models/assignment.rb +10 -9
- data/lib/canvas_sync/generators/templates/models/assignment_group.rb +5 -5
- data/lib/canvas_sync/generators/templates/models/context_module.rb +2 -2
- data/lib/canvas_sync/generators/templates/models/context_module_item.rb +3 -2
- data/lib/canvas_sync/generators/templates/models/course.rb +14 -14
- data/lib/canvas_sync/generators/templates/models/enrollment.rb +10 -9
- data/lib/canvas_sync/generators/templates/models/role.rb +3 -3
- data/lib/canvas_sync/generators/templates/models/section.rb +6 -6
- data/lib/canvas_sync/generators/templates/models/submission.rb +5 -5
- data/lib/canvas_sync/generators/templates/models/term.rb +4 -3
- data/lib/canvas_sync/generators/templates/models/user.rb +6 -6
- data/lib/canvas_sync/generators/templates/services/live_events/base_event.rb +4 -0
- data/lib/canvas_sync/generators/templates/services/live_events/course/course_event.rb +1 -1
- data/lib/canvas_sync/generators/templates/services/live_events/course_section/course_section_event.rb +4 -4
- data/lib/canvas_sync/generators/templates/services/live_events/module/module_event.rb +1 -1
- data/lib/canvas_sync/generators/templates/services/live_events/module_item/module_item_event.rb +3 -3
- data/lib/canvas_sync/generators/templates/services/live_events/user/user_event.rb +1 -1
- data/lib/canvas_sync/jobs/sync_provisioning_report_job.rb +7 -2
- data/lib/canvas_sync/jobs/sync_simple_table_job.rb +7 -2
- data/lib/canvas_sync/processors/model_mappings.yml +35 -41
- data/lib/canvas_sync/version.rb +1 -1
- data/spec/canvas_sync/jobs/sync_provisioning_report_job_spec.rb +4 -4
- data/spec/canvas_sync/jobs/sync_simple_table_job_spec.rb +3 -3
- data/spec/canvas_sync/models/accounts_spec.rb +2 -2
- data/spec/canvas_sync/models/admins_spec.rb +3 -3
- data/spec/canvas_sync/models/assignment_group_spec.rb +4 -4
- data/spec/canvas_sync/models/assignment_spec.rb +8 -8
- data/spec/canvas_sync/models/context_module_spec.rb +2 -2
- data/spec/canvas_sync/models/course_spec.rb +7 -8
- data/spec/canvas_sync/models/enrollment_spec.rb +5 -5
- data/spec/canvas_sync/models/roles_spec.rb +3 -3
- data/spec/canvas_sync/models/section_spec.rb +4 -4
- data/spec/canvas_sync/models/submission_spec.rb +5 -5
- data/spec/canvas_sync/models/term_spec.rb +7 -7
- data/spec/canvas_sync/models/user_spec.rb +4 -4
- data/spec/canvas_sync/processors/provisioning_report_processor_spec.rb +5 -5
- data/spec/canvas_sync/services/module_event_spec.rb +1 -1
- data/spec/canvas_sync/services/module_item_event_spec.rb +7 -7
- data/spec/dummy/app/models/account.rb +9 -1
- data/spec/dummy/app/models/admin.rb +4 -4
- data/spec/dummy/app/models/assignment.rb +23 -5
- data/spec/dummy/app/models/assignment_group.rb +15 -3
- data/spec/dummy/app/models/context_module.rb +2 -2
- data/spec/dummy/app/models/context_module_item.rb +3 -2
- data/spec/dummy/app/models/course.rb +20 -7
- data/spec/dummy/app/models/enrollment.rb +20 -4
- data/spec/dummy/app/models/role.rb +3 -3
- data/spec/dummy/app/models/section.rb +14 -3
- data/spec/dummy/app/models/submission.rb +16 -4
- data/spec/dummy/app/models/term.rb +4 -3
- data/spec/dummy/app/models/user.rb +15 -4
- data/spec/dummy/app/services/live_events/base_event.rb +4 -0
- data/spec/dummy/app/services/live_events/course_event.rb +1 -1
- data/spec/dummy/app/services/live_events/course_section_event.rb +4 -4
- data/spec/dummy/app/services/live_events/module_event.rb +1 -1
- data/spec/dummy/app/services/live_events/module_item_event.rb +3 -3
- data/spec/dummy/app/services/live_events/user_event.rb +1 -1
- data/spec/dummy/db/migrate/{20180216171618_create_submissions.rb → 20190521003447_create_submissions.rb} +4 -4
- data/spec/dummy/db/migrate/{20180103162102_create_roles.rb → 20190521003448_create_roles.rb} +2 -2
- data/spec/dummy/db/migrate/{20180109210452_create_admins.rb → 20190521003449_create_admins.rb} +2 -2
- data/spec/dummy/db/migrate/{20180222163506_create_assignment_groups.rb → 20190521003450_create_assignment_groups.rb} +2 -2
- data/spec/dummy/db/migrate/{20180411215348_create_context_modules.rb → 20190521003451_create_context_modules.rb} +2 -2
- data/spec/dummy/db/migrate/{20180215214227_create_assignments.rb → 20190603192310_create_assignments.rb} +11 -11
- data/spec/dummy/db/migrate/{20180605172338_create_context_module_items.rb → 20190603193502_create_context_module_items.rb} +4 -4
- data/spec/dummy/db/migrate/{20180509194201_create_users.rb → 20190603215718_create_users.rb} +4 -4
- data/spec/dummy/db/migrate/{20170906193506_create_terms.rb → 20190603215721_create_terms.rb} +2 -2
- data/spec/dummy/db/migrate/{20171107213207_create_sections.rb → 20190603215722_create_sections.rb} +5 -5
- data/spec/dummy/db/migrate/{20170914181345_create_courses.rb → 20190603220011_create_courses.rb} +7 -8
- data/spec/dummy/db/migrate/{20170905192509_create_enrollments.rb → 20190603220013_create_enrollments.rb} +4 -6
- data/spec/dummy/db/migrate/{20180220172559_create_accounts.rb → 20190604193942_create_accounts.rb} +6 -6
- data/spec/dummy/db/schema.rb +56 -58
- data/spec/dummy/log/test.log +1350 -0
- data/spec/factories/account_factory.rb +5 -5
- data/spec/factories/admin_factory.rb +1 -1
- data/spec/factories/assignment_factory.rb +1 -1
- data/spec/factories/assignment_group_factory.rb +1 -1
- data/spec/factories/context_module_factory.rb +2 -2
- data/spec/factories/context_module_item_factory.rb +1 -1
- data/spec/factories/course_factory.rb +5 -5
- data/spec/factories/enrollment_factory.rb +1 -1
- data/spec/factories/role_factory.rb +1 -1
- data/spec/factories/section_factory.rb +1 -1
- data/spec/factories/submission_factory.rb +1 -1
- data/spec/factories/term_factory.rb +1 -1
- data/spec/factories/user_factory.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- metadata +41 -41
- 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,
|
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,
|
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.
|
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.
|
29
|
-
expect(cmi.
|
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.
|
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.
|
43
|
-
expect(cmi.
|
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
|
-
|
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 :
|
11
|
-
belongs_to :user, primary_key: :
|
12
|
-
belongs_to :role, primary_key: :
|
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(
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
11
|
-
|
12
|
-
|
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 :
|
14
|
-
has_many :context_module_items, primary_key: :
|
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: :
|
11
|
-
belongs_to :
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
has_many :
|
15
|
-
has_many :
|
16
|
-
has_many :
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
belongs_to :
|
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 :
|
11
|
-
has_many :admins, foreign_key: :canvas_role_id, primary_key: :
|
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(
|
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
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
belongs_to :
|
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 :
|
11
|
-
has_many :courses, foreign_key: :canvas_term_id, primary_key: :
|
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(
|
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
|
-
|
11
|
-
|
12
|
-
|
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: :
|
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
|
-
|
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
|
-
#
|
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
|
-
|
39
|
-
|
40
|
-
|
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(
|
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(
|
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
|
-
|
37
|
-
|
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?
|
@@ -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 :
|
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.
|
19
|
-
t.
|
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, :
|
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
|