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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ea56aa1b7bf0b7e65519d1405021705021cff4d51754b3cad619b399350fec9
4
- data.tar.gz: 67cfa628a75892751cc515560f8d6a6fd8f1832473e0280f2967bfc4a1007ae5
3
+ metadata.gz: efb7341f8d1643d211f53ffde7c7fbaf9c7e0b89359d83ffa12e293f8e977863
4
+ data.tar.gz: 4919a841fc27a2b85cb0049f03a18a46f27d1c5928345eaf2dd3460fba764f06
5
5
  SHA512:
6
- metadata.gz: 590e2a9fad154c55824eb6d3bf158973b81e971e59a2f8c9ce2db4f46ae88ce9d93721c29c479390f7df474a070a1fc939311c0a5b7d784c972b55798766638e
7
- data.tar.gz: 1e53b3b933b1e9255ab448dc9585172cf4af183176492b407d2228997864f376da06847750c366283c47f0b51fca2f48a8742ac90f20b22d59ea1bad0a2a7204
6
+ metadata.gz: ae1217a2ab3c9f5168cd759372ac0d306e906bf185a3f6684c208443f9611ce494d7cd8d6ccd732e11425ddf3711c5886fb43b7caa881d1d9064ab10e6d85c9c
7
+ data.tar.gz: 619b4f60710761a1381074d1d058fb49e6b09f79264b7ed57f97143f2bcab468fb0e1eb0571591aaedd7b9536b5318acc7463a01a3732014b974fc33457c5dc0
data/README.md CHANGED
@@ -237,6 +237,14 @@ end
237
237
 
238
238
  ## Legacy Support
239
239
 
240
+ ### Legacy Mappings
241
+
242
+ CanvasSync 0.10.0+, by default, changes Canvas primary-keys from `:canvas_MODEL_id` to just `:canvas_id`.
243
+ Because CanvasSync primarily consists of templates, this change shouldn't require any large changes in your app, but you will need to
244
+ apply the `model_mappings_legacy.yml` (located in the root of this repo) to your model mappings - see [Mapping Overrides](#mapping-overrides).
245
+
246
+ ### Row-by-Row Syncing
247
+
240
248
  If you have an old style tool that needs to sync data on a row by row basis, you can pass in the `legacy_support: true` option. In order for this to work, your models must have a `create_or_update_from_csv` class method defined that accepts a row argument. This method will get passed each row from the CSV, and it's up to you to persist it.
241
249
 
242
250
  Example:
@@ -44,6 +44,7 @@ module CanvasSync::ApiSyncable
44
44
  api_response
45
45
  rescue Faraday::Error::ResourceNotFound, Footrest::HttpError::NotFound => e
46
46
  api_mark_deleted
47
+ save! if changed?
47
48
  nil
48
49
  end
49
50
 
@@ -4,7 +4,7 @@ require "rails/generators/migration"
4
4
  module CanvasSync
5
5
  class InstallGenerator < Rails::Generators::Base
6
6
  include Rails::Generators::Migration
7
- source_root File.expand_path("../templates/models", __FILE__)
7
+ source_root File.expand_path("../templates", __FILE__)
8
8
  class_option :models, type: :string, required: true
9
9
 
10
10
  def self.next_migration_number(path)
@@ -46,8 +46,8 @@ module CanvasSync
46
46
  CanvasSync.validate_models!(models)
47
47
 
48
48
  models.each do |model|
49
- migration_template "create_#{model}.rb", "db/migrate/create_#{model}.rb"
50
- template "#{model.singularize}.rb", "app/models/#{model.singularize}.rb"
49
+ migration_template "migrations/create_#{model}.rb", "db/migrate/create_#{model}.rb"
50
+ template "models/#{model.singularize}.rb", "app/models/#{model.singularize}.rb"
51
51
  end
52
52
  end
53
53
  end
@@ -0,0 +1,17 @@
1
+ <%= autogenerated_migration_warning %>
2
+
3
+ class CreateAccounts < ActiveRecord::Migration[5.1]
4
+ def change
5
+ create_table :accounts do |t|
6
+ t.bigint :canvas_id, null: false
7
+ t.string :sis_id
8
+ t.bigint :canvas_parent_account_id
9
+ t.string :sis_parent_account_id
10
+ t.string :name
11
+ t.string :workflow_state
12
+
13
+ t.timestamps
14
+ end
15
+ add_index :accounts, :canvas_id, unique: true
16
+ end
17
+ end
@@ -3,7 +3,7 @@
3
3
  class CreateAdmins < ActiveRecord::Migration[5.1]
4
4
  def change
5
5
  create_table :admins do |t|
6
- t.bigint :canvas_admin_id, null: false
6
+ t.bigint :canvas_id, null: false
7
7
  t.string :role_name
8
8
  t.bigint :canvas_role_id, null: false
9
9
  t.json :user_data
@@ -12,6 +12,6 @@ class CreateAdmins < ActiveRecord::Migration[5.1]
12
12
 
13
13
  t.timestamps
14
14
  end
15
- add_index :admins, :canvas_admin_id, unique: true
15
+ add_index :admins, :canvas_id, unique: true
16
16
  end
17
17
  end
@@ -3,7 +3,7 @@
3
3
  class CreateAssignmentGroups < ActiveRecord::Migration[5.1]
4
4
  def change
5
5
  create_table :assignment_groups do |t|
6
- t.bigint :canvas_assignment_group_id, null: false
6
+ t.bigint :canvas_id, null: false
7
7
  t.bigint :canvas_course_id
8
8
  t.string :name
9
9
  t.text :rules
@@ -16,7 +16,7 @@ class CreateAssignmentGroups < ActiveRecord::Migration[5.1]
16
16
  t.timestamps
17
17
  end
18
18
 
19
- add_index :assignment_groups, :canvas_assignment_group_id, unique: true
19
+ add_index :assignment_groups, :canvas_id, unique: true
20
20
  add_index :assignment_groups, :canvas_course_id
21
21
  end
22
22
  end
@@ -3,7 +3,7 @@
3
3
  class CreateAssignments < ActiveRecord::Migration[5.1]
4
4
  def change
5
5
  create_table :assignments do |t|
6
- t.bigint :canvas_assignment_id, null: false
6
+ t.bigint :canvas_id, null: false
7
7
  t.string :title
8
8
  t.text :description
9
9
  t.datetime :due_at
@@ -16,16 +16,16 @@ class CreateAssignments < ActiveRecord::Migration[5.1]
16
16
  t.string :grading_type
17
17
  t.string :submission_types
18
18
  t.string :workflow_state
19
- t.integer :context_id
20
- t.string :context_type
19
+ t.integer :canvas_context_id
20
+ t.string :canvas_context_type
21
21
  t.integer :canvas_assignment_group_id
22
- t.integer :grading_scheme_id
23
- t.integer :grading_standard_id
22
+ t.integer :canvas_grading_scheme_id
23
+ t.integer :canvas_grading_standard_id
24
24
 
25
25
  t.timestamps
26
26
  end
27
27
 
28
- add_index :assignments, :canvas_assignment_id, unique: true
29
- add_index :assignments, [:context_id, :context_type]
28
+ add_index :assignments, :canvas_id, unique: true
29
+ add_index :assignments, [:canvas_context_id, :canvas_context_type]
30
30
  end
31
31
  end
@@ -3,18 +3,18 @@
3
3
  class CreateContextModuleItems < ActiveRecord::Migration[5.1]
4
4
  def change
5
5
  create_table :context_module_items do |t|
6
- t.bigint :canvas_context_module_item_id
6
+ t.bigint :canvas_id
7
7
  t.bigint :canvas_context_module_id
8
8
  t.integer :position
9
- t.string :content_type
10
- t.bigint :content_id
9
+ t.bigint :canvas_content_id
10
+ t.string :canvas_content_type
11
11
  t.bigint :canvas_assignment_id
12
12
  t.string :workflow_state
13
13
 
14
14
  t.timestamps
15
15
  end
16
16
 
17
- add_index :context_module_items, :canvas_context_module_item_id, unique: true
17
+ add_index :context_module_items, :canvas_id, unique: true
18
18
  add_index :context_module_items, :canvas_context_module_id
19
19
  end
20
20
  end
@@ -3,7 +3,7 @@
3
3
  class CreateContextModules < ActiveRecord::Migration[5.1]
4
4
  def change
5
5
  create_table :context_modules do |t|
6
- t.bigint :canvas_context_module_id
6
+ t.bigint :canvas_id
7
7
  t.bigint :canvas_context_id
8
8
  t.string :canvas_context_type
9
9
  t.integer :position
@@ -14,7 +14,7 @@ class CreateContextModules < ActiveRecord::Migration[5.1]
14
14
  t.timestamps
15
15
  end
16
16
 
17
- add_index :context_modules, :canvas_context_module_id, unique: true
17
+ add_index :context_modules, :canvas_id, unique: true
18
18
  add_index :context_modules, [:canvas_context_id, :canvas_context_type], name: "index_context_modules_on_context"
19
19
  end
20
20
  end
@@ -3,20 +3,19 @@
3
3
  class CreateCourses < ActiveRecord::Migration[5.1]
4
4
  def change
5
5
  create_table :courses do |t|
6
- t.bigint :canvas_course_id, null: false
6
+ t.bigint :canvas_id, null: false
7
7
  t.string :sis_id
8
- t.string :short_name
9
- t.string :long_name
10
- t.string :status
8
+ t.string :course_code
9
+ t.string :name
10
+ t.string :workflow_state
11
11
  t.integer :canvas_account_id
12
12
  t.integer :canvas_term_id
13
- t.integer :term_sis_id
14
- t.datetime :start_date
15
- t.datetime :end_date
13
+ t.datetime :start_at
14
+ t.datetime :end_at
16
15
 
17
16
  t.timestamps
18
17
  end
19
18
 
20
- add_index :courses, :canvas_course_id, unique: true
19
+ add_index :courses, :canvas_id, unique: true
21
20
  end
22
21
  end
@@ -3,23 +3,21 @@
3
3
  class CreateEnrollments < ActiveRecord::Migration[5.1]
4
4
  def change
5
5
  create_table :enrollments do |t|
6
- t.bigint :canvas_enrollment_id, null: false
6
+ t.bigint :canvas_id, null: false
7
7
  t.bigint :canvas_course_id
8
8
  t.string :course_sis_id
9
9
  t.bigint :canvas_user_id
10
10
  t.string :user_sis_id
11
11
  t.string :role
12
- t.integer :role_id
12
+ t.integer :canvas_role_id
13
13
  t.bigint :canvas_section_id
14
- t.string :section_sis_id
15
- t.string :status
14
+ t.string :workflow_state
16
15
  t.string :base_role_type
17
16
 
18
-
19
17
  t.timestamps
20
18
  end
21
19
 
22
- add_index :enrollments, :canvas_enrollment_id, unique: true
20
+ add_index :enrollments, :canvas_id, unique: true
23
21
  add_index :enrollments, :canvas_course_id
24
22
  add_index :enrollments, :canvas_user_id
25
23
  end
@@ -3,7 +3,7 @@
3
3
  class CreateRoles < ActiveRecord::Migration[5.1]
4
4
  def change
5
5
  create_table :roles do |t|
6
- t.integer :canvas_role_id, null: false
6
+ t.integer :canvas_id, null: false
7
7
  t.string :label, null: false
8
8
  t.string :base_role_type, null: false
9
9
  t.json :account
@@ -12,6 +12,6 @@ class CreateRoles < ActiveRecord::Migration[5.1]
12
12
 
13
13
  t.timestamps
14
14
  end
15
- add_index :roles, :canvas_role_id, unique: true
15
+ add_index :roles, :canvas_id, unique: true
16
16
  end
17
17
  end
@@ -3,19 +3,19 @@
3
3
  class CreateSections < ActiveRecord::Migration[5.1]
4
4
  def change
5
5
  create_table :sections do |t|
6
- t.bigint :canvas_section_id, null: false
6
+ t.bigint :canvas_id, null: false
7
7
  t.string :sis_id
8
8
  t.bigint :canvas_course_id
9
9
  t.bigint :canvas_nonxlist_course_id
10
10
  t.string :name
11
- t.string :status
12
- t.datetime :start_date
13
- t.datetime :end_date
11
+ t.string :workflow_state
12
+ t.datetime :start_at
13
+ t.datetime :end_at
14
14
 
15
15
  t.timestamps
16
16
  end
17
17
 
18
- add_index :sections, :canvas_section_id, unique: true
18
+ add_index :sections, :canvas_id, unique: true
19
19
  add_index :sections, :canvas_course_id
20
20
  end
21
21
  end
@@ -3,7 +3,7 @@
3
3
  class CreateSubmissions < ActiveRecord::Migration[5.1]
4
4
  def change
5
5
  create_table :submissions do |t|
6
- t.bigint :canvas_submission_id, null: false
6
+ t.bigint :canvas_id, null: false
7
7
  t.bigint :canvas_course_id
8
8
  t.bigint :canvas_assignment_id
9
9
  t.bigint :canvas_user_id
@@ -17,7 +17,7 @@ class CreateSubmissions < ActiveRecord::Migration[5.1]
17
17
  t.timestamps
18
18
  end
19
19
 
20
- add_index :submissions, :canvas_submission_id, unique: true
20
+ add_index :submissions, :canvas_id, unique: true
21
21
  add_index :submissions, :canvas_assignment_id
22
22
  add_index :submissions, :canvas_course_id
23
23
  add_index :submissions, :canvas_user_id
@@ -3,7 +3,7 @@
3
3
  class CreateTerms < ActiveRecord::Migration[5.1]
4
4
  def change
5
5
  create_table :terms do |t|
6
- t.integer :canvas_term_id, null: false
6
+ t.integer :canvas_id, null: false
7
7
  t.string :name
8
8
  t.datetime :start_at
9
9
  t.datetime :end_at
@@ -13,6 +13,6 @@ class CreateTerms < ActiveRecord::Migration[5.1]
13
13
 
14
14
  t.timestamps
15
15
  end
16
- add_index :terms, :canvas_term_id, unique: true
16
+ add_index :terms, :canvas_id, unique: true
17
17
  end
18
18
  end
@@ -3,19 +3,19 @@
3
3
  class CreateUsers < ActiveRecord::Migration[5.1]
4
4
  def change
5
5
  create_table :users do |t|
6
- t.bigint :canvas_user_id, null: false
6
+ t.bigint :canvas_id, null: false
7
7
  t.string :sis_id
8
8
  t.string :email
9
9
  t.string :first_name
10
10
  t.string :last_name
11
- t.string :status
11
+ t.string :workflow_state
12
12
  t.string :login_id
13
- t.string :full_name
13
+ t.string :name
14
14
  t.string :sortable_name
15
15
 
16
16
  t.timestamps
17
17
  end
18
18
 
19
- add_index :users, :canvas_user_id, unique: true
19
+ add_index :users, :canvas_id, unique: true
20
20
  end
21
21
  end
@@ -3,11 +3,11 @@
3
3
  class Account < ApplicationRecord
4
4
  include CanvasSync::ApiSyncable
5
5
 
6
- validates :canvas_account_id, uniqueness: true, presence: true
6
+ validates :canvas_id, uniqueness: true, presence: true
7
7
 
8
8
  api_syncable({
9
9
  name: :name,
10
- status: :workflow_state,
11
- canvas_parent_id: :parent_account_id,
12
- }, -> (api) { api.account(canvas_account_id) })
10
+ workflow_state: :workflow_state,
11
+ canvas_parent_account_id: :parent_account_id,
12
+ }, -> (api) { api.account(canvas_id) })
13
13
  end
@@ -1,12 +1,12 @@
1
1
  <%= autogenerated_model_warning %>
2
2
 
3
3
  class Admin < ApplicationRecord
4
- validates :canvas_admin_id, uniqueness: true, presence: true
5
- belongs_to :user, primary_key: :canvas_user_id, foreign_key: :canvas_user_id, optional: true
6
- belongs_to :role, primary_key: :canvas_role_id, foreign_key: :canvas_role_id, optional: true
4
+ validates :canvas_id, uniqueness: true, presence: true
5
+ belongs_to :user, primary_key: :canvas_id, foreign_key: :canvas_user_id, optional: true
6
+ belongs_to :role, primary_key: :canvas_id, foreign_key: :canvas_role_id, optional: true
7
7
 
8
8
  def self.create_or_update(admin_params)
9
- admin = Admin.find_or_initialize_by(canvas_admin_id: admin_params['id'])
9
+ admin = Admin.find_or_initialize_by(canvas_id: admin_params['id'])
10
10
 
11
11
  admin.assign_attributes(role_name: admin_params['role'],
12
12
  canvas_role_id: admin_params['role_id'],
@@ -3,11 +3,12 @@
3
3
  class Assignment < ApplicationRecord
4
4
  include CanvasSync::ApiSyncable
5
5
 
6
- validates :canvas_assignment_id, uniqueness: true, presence: true
7
- belongs_to :context, polymorphic: true, optional: true, primary_key: :canvas_course_id
8
- belongs_to :assignment_group, optional: true, primary_key: :canvas_assignment_group_id, foreign_key: :canvas_assignment_group_id
9
- has_many :submissions, primary_key: :canvas_assignment_id, foreign_key: :canvas_assignment_id
10
- has_many :context_module_items, primary_key: :canvas_assignment_id, foreign_key: :content_id, dependent: :destroy
6
+ validates :canvas_id, uniqueness: true, presence: true
7
+ belongs_to :context, polymorphic: true, optional: true, primary_key: :canvas_id, foreign_key: :canvas_context_id, foreign_type: :canvas_context_type
8
+ belongs_to :assignment_group, optional: true, primary_key: :canvas_id, foreign_key: :canvas_assignment_group_id
9
+ has_many :submissions, primary_key: :canvas_id, foreign_key: :canvas_assignment_id
10
+
11
+ has_many :context_module_items, as: :content, primary_key: :canvas_id, foreign_key: :canvas_content_id, foreign_type: :canvas_content_type, dependent: :destroy
11
12
  has_many :context_modules, through: :context_module_items
12
13
 
13
14
  api_syncable({
@@ -19,9 +20,9 @@ class Assignment < ApplicationRecord
19
20
  points_possible: :points_possible,
20
21
  grading_type: :grading_type,
21
22
  submission_types: lambda { |p| p["submission_types"].join(",") },
22
- context_id: :course_id,
23
- context_type: lambda { |_p| "Course" },
23
+ canvas_context_id: :course_id,
24
+ canvas_context_type: lambda { |_p| "Course" },
24
25
  canvas_assignment_group_id: :assignment_group_id,
25
- grading_standard_id: :grading_standard_id,
26
- }, -> (api) { api.assignment(context_id, canvas_assignment_id) })
26
+ canvas_grading_standard_id: :grading_standard_id,
27
+ }, -> (api) { api.assignment(canvas_context_id, canvas_id) })
27
28
  end
@@ -3,17 +3,17 @@
3
3
  class AssignmentGroup < ApplicationRecord
4
4
  include CanvasSync::ApiSyncable
5
5
 
6
- validates :canvas_assignment_group_id, uniqueness: true, presence: true
7
- belongs_to :course, primary_key: :canvas_course_id, foreign_key: :canvas_course_id, optional: true
8
- has_many :assignments, primary_key: :canvas_assignment_group_id, foreign_key: :canvas_assignment_group_id
6
+ validates :canvas_id, uniqueness: true, presence: true
7
+ belongs_to :course, primary_key: :canvas_id, foreign_key: :canvas_course_id, optional: true
8
+ has_many :assignments, primary_key: :canvas_id, foreign_key: :canvas_assignment_group_id
9
9
 
10
10
  serialize :rules
11
11
 
12
12
  api_syncable({
13
- canvas_assignment_group_id: :id,
13
+ canvas_id: :id,
14
14
  name: :name,
15
15
  position: :position,
16
16
  rules: :rules,
17
17
  group_weight: :group_weight,
18
- }, -> (api) { api.assignment(course_id, canvas_assignment_group_id) })
18
+ }, -> (api) { api.assignment(course_id, canvas_id) })
19
19
  end
@@ -4,7 +4,7 @@
4
4
  # 1 - Module is a reserved word in Rails and you can't call a model a Module
5
5
  # 2 - Canvas calls them ContextModules
6
6
  class ContextModule < ApplicationRecord
7
- belongs_to :canvas_context, polymorphic: true, optional: true
8
- has_many :context_module_items, primary_key: :canvas_context_module_id, foreign_key: :canvas_context_module_id
7
+ belongs_to :context, polymorphic: true, optional: true, primary_key: :canvas_id, foreign_key: :canvas_context_id, foreign_type: :canvas_context_type
8
+ has_many :context_module_items, primary_key: :canvas_id, foreign_key: :canvas_context_module_id
9
9
  has_many :assignments, through: :context_module_items
10
10
  end