canvas_sync 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23899e5c41cb63d0267eb031be38b7810e84f58e
4
- data.tar.gz: 7e6c5093980d7e07d271a85a330c2fcae8d52b54
3
+ metadata.gz: 8a91540c9a7c6e087d7b9c3f21340e689c0b77da
4
+ data.tar.gz: 9aad571654e1fe0b167f2af732bb1f49f4204a1f
5
5
  SHA512:
6
- metadata.gz: 32803f19bc38b505ab67abcdbcc55b3b283a00b79541942fea14142306ce6e569ba1746efc2d6a1d55c6eccd2b6cf7046a4f1f200e9cda9a4cd01f749f22b839
7
- data.tar.gz: 83b5c340093e644dc26faf58ae297f937f207b0457c32b0991fad1c2194c773e49f0dff929aa0d9f4f39f6f2eafd028e1f6afc039bd240648e7b478ff03e141e
6
+ metadata.gz: 0654cbfc7984fca42f257a9ba0644fb21edf01b3d12d65ab53af9ca5698760c416168208162ab63b8fd98ce992c220ab26303218ed189f31b21d94539c5c0414
7
+ data.tar.gz: 9a256cb21575fb57108c39570a5259a967dfc4aa509e2bd48790e8f27aa35b72cc94f1cff7b15db877a72941e8ff7a1783b9635e1e7ecfb35f652e88f6ff6aca
data/README.md CHANGED
@@ -210,9 +210,23 @@ When adding to or updating this gem, make sure you do the following:
210
210
  - Write specs
211
211
  - If you modify the model or migration templates, run `bundle exec rake update_test_schema` to update them in the Rails Dummy application (and commit those changes)
212
212
 
213
+
214
+ ## Mapping Overrides
215
+
216
+ If your local database columns do not match up with those expected by CanvasSync you can define overrides.
217
+ In your Rails config folder, the canvas_sync_provisioning_mapping.yml file contains overrides for custom database column names
218
+
219
+ ```
220
+ users:
221
+ conflict_target: canvas_user_id # Represents the database column that will determine if we need to update
222
+ report_columns: # The keys specified here are the column names in the report CSV
223
+ canvas_user_id_column_name_in_report:
224
+ database_column_name: canvas_user_id_name_in_your_db
225
+ type: integer
226
+ ```
227
+
213
228
  ## TODO
214
229
 
215
230
  - Rethink how options are passed around. The current strategy of having "global_options" and per job options works
216
231
  decently, but can be confusing. The difficulty is representing the options in a way that is easily serializable
217
232
  by the queue adaptor and easily passed around.
218
- - Add support for defining "mappings" if your models don't match up with what CanvasSync expects.
@@ -0,0 +1,130 @@
1
+ users:
2
+ conflict_target: canvas_user_id
3
+ report_columns:
4
+ canvas_user_id:
5
+ database_column_name: canvas_user_id
6
+ type: integer
7
+ user_id:
8
+ database_column_name: sis_id
9
+ type: string
10
+ email:
11
+ database_column_name: email
12
+ type: string
13
+ first_name:
14
+ database_column_name: first_name
15
+ type: string
16
+ last_name:
17
+ database_column_name: last_name
18
+ type: string
19
+ status:
20
+ database_column_name: status
21
+ type: string
22
+ login_id:
23
+ database_column_name: login_id
24
+ type: string
25
+
26
+ courses:
27
+ conflict_target: canvas_course_id
28
+ report_columns:
29
+ canvas_course_id:
30
+ database_column_name: canvas_course_id
31
+ type: integer
32
+ course_id:
33
+ database_column_name: sis_id
34
+ type: string
35
+ short_name:
36
+ database_column_name: short_name
37
+ type: string
38
+ long_name:
39
+ database_column_name: long_name
40
+ type: string
41
+ canvas_account_id:
42
+ database_column_name: canvas_account_id
43
+ type: integer
44
+ canvas_term_id:
45
+ database_column_name: canvas_term_id
46
+ type: integer
47
+ term_id:
48
+ database_column_name: term_sis_id
49
+ type: string
50
+ start_date:
51
+ database_column_name: start_date
52
+ type: datetime
53
+ end_date:
54
+ database_column_name: end_date
55
+ type: datetime
56
+ status:
57
+ database_column_name: status
58
+ type: integer
59
+
60
+ enrollments:
61
+ conflict_target: canvas_enrollment_id
62
+ report_columns:
63
+ canvas_enrollment_id:
64
+ database_column_name: canvas_enrollment_id
65
+ type: integer
66
+ canvas_course_id:
67
+ database_column_name: canvas_course_id
68
+ type: integer
69
+ course_id:
70
+ database_column_name: course_sis_id
71
+ type: string
72
+ canvas_user_id:
73
+ database_column_name: canvas_user_id
74
+ type: integer
75
+ user_id:
76
+ database_column_name: user_sis_id
77
+ type: string
78
+ role:
79
+ database_column_name: role
80
+ type: string
81
+ role_id:
82
+ database_column_name: role_id
83
+ type: integer
84
+ canvas_section_id:
85
+ database_column_name: canvas_section_id
86
+ type: integer
87
+ section_id:
88
+ database_column_name: section_sis_id
89
+ type: string
90
+ status:
91
+ database_column_name: status
92
+ type: string
93
+ base_role_type:
94
+ database_column_name: base_role_type
95
+ type: string
96
+
97
+ sections:
98
+ conflict_target: canvas_section_id
99
+ report_columns:
100
+ canvas_section_id:
101
+ database_column_name: canvas_section_id
102
+ type: integer
103
+ section_id:
104
+ database_column_name: sis_id
105
+ type: string
106
+ canvas_course_id:
107
+ database_column_name: canvas_course_id
108
+ type: integer
109
+ name:
110
+ database_column_name: name
111
+ type: string
112
+ status:
113
+ database_column_name: status
114
+ type: string
115
+ start_date:
116
+ database_column_name: start_date
117
+ type: datetime
118
+ end_date:
119
+ database_column_name: end_date
120
+ type: datetime
121
+
122
+ xlist:
123
+ conflict_target: canvas_section_id
124
+ report_columns:
125
+ canvas_section_id:
126
+ database_column_name: canvas_section_id
127
+ type: integer
128
+ canvas_nonxlist_course_id:
129
+ database_column_name: canvas_nonxlist_course_id
130
+ type: integer
@@ -1,175 +1,11 @@
1
1
  require 'csv'
2
2
  require 'activerecord-import'
3
3
  require 'zip'
4
+ require 'yaml'
4
5
 
5
6
  module CanvasSync
6
7
  module Processors
7
8
  class ProvisioningReportProcessor
8
- # Used by the {CanvasSync::Importers::BulkImporter bulk importer}. The keys are
9
- # CSV columns and the values are the database columns.
10
- USERS_CSV_MAPPING = {
11
- canvas_user_id: {
12
- database_column_name: :canvas_user_id,
13
- type: :integer
14
- },
15
- user_id: {
16
- database_column_name: :sis_id,
17
- type: :string
18
- },
19
- email: {
20
- database_column_name: :email,
21
- type: :string
22
- },
23
- first_name: {
24
- database_column_name: :first_name,
25
- type: :string
26
- },
27
- last_name: {
28
- database_column_name: :last_name,
29
- type: :string
30
- },
31
- status: {
32
- database_column_name: :status,
33
- type: :string
34
- },
35
- login_id: {
36
- database_column_name: :login_id,
37
- type: :string
38
- }
39
- }
40
-
41
- COURSES_CSV_MAPPING = {
42
- canvas_course_id: {
43
- database_column_name: :canvas_course_id,
44
- type: :integer
45
- },
46
- course_id: {
47
- database_column_name: :sis_id,
48
- type: :string
49
- },
50
- short_name: {
51
- database_column_name: :short_name,
52
- type: :string
53
- },
54
- long_name: {
55
- database_column_name: :long_name,
56
- type: :string
57
- },
58
- canvas_account_id: {
59
- database_column_name: :canvas_account_id,
60
- type: :integer
61
- },
62
- canvas_term_id: {
63
- database_column_name: :canvas_term_id,
64
- type: :integer
65
- },
66
- term_id: {
67
- database_column_name: :term_sis_id,
68
- type: :string
69
- },
70
- start_date: {
71
- database_column_name: :start_date,
72
- type: :datetime
73
- },
74
- end_date: {
75
- database_column_name: :end_date,
76
- type: :datetime
77
- },
78
- status: {
79
- database_column_name: :status,
80
- type: :integer
81
- }
82
- }
83
-
84
- ENROLLMENTS_CSV_MAPPING = {
85
- canvas_enrollment_id: {
86
- database_column_name: :canvas_enrollment_id,
87
- type: :integer
88
- },
89
- canvas_course_id: {
90
- database_column_name: :canvas_course_id,
91
- type: :integer
92
- },
93
- course_id: {
94
- database_column_name: :course_sis_id,
95
- type: :string
96
- },
97
- canvas_user_id: {
98
- database_column_name: :canvas_user_id,
99
- type: :integer
100
- },
101
- user_id: {
102
- database_column_name: :user_sis_id,
103
- type: :string
104
- },
105
- role: {
106
- database_column_name: :role,
107
- type: :string
108
- },
109
- role_id: {
110
- database_column_name: :role_id,
111
- type: :integer
112
- },
113
- canvas_section_id: {
114
- database_column_name: :canvas_section_id,
115
- type: :integer
116
- },
117
- section_id: {
118
- database_column_name: :section_sis_id,
119
- type: :string
120
- },
121
- status: {
122
- database_column_name: :status,
123
- type: :string
124
- },
125
- base_role_type: {
126
- database_column_name: :base_role_type,
127
- type: :string
128
- }
129
- }
130
-
131
- SECTIONS_CSV_MAPPING = {
132
- canvas_section_id: {
133
- database_column_name: :canvas_section_id,
134
- type: :integer
135
- },
136
- section_id: {
137
- database_column_name: :sis_id,
138
- type: :string
139
- },
140
- canvas_course_id: {
141
- database_column_name: :canvas_course_id,
142
- type: :integer
143
- },
144
- name: {
145
- database_column_name: :name,
146
- type: :string
147
- },
148
- status: {
149
- database_column_name: :status,
150
- type: :string
151
- },
152
- start_date: {
153
- database_column_name: :start_date,
154
- type: :datetime
155
- },
156
- end_date: {
157
- database_column_name: :end_date,
158
- type: :datetime
159
- }
160
- }
161
-
162
- XLIST_CSV_MAPPING = {
163
- canvas_section_id: {
164
- database_column_name: :canvas_section_id,
165
- type: :integer
166
- },
167
- canvas_nonxlist_course_id: {
168
- database_column_name: :canvas_nonxlist_course_id,
169
- type: :integer
170
- }
171
- }
172
-
173
9
  # Processes a provisioning report using the bulk importer.
174
10
  #
175
11
  # options must contain a models key. If there is only one model
@@ -224,9 +60,9 @@ module CanvasSync
224
60
  def bulk_process_users(report_file_path)
225
61
  CanvasSync::Importers::BulkImporter.import(
226
62
  report_file_path,
227
- USERS_CSV_MAPPING,
63
+ mapping[:users][:report_columns],
228
64
  User,
229
- :canvas_user_id,
65
+ mapping[:users][:conflict_target].to_sym,
230
66
  true
231
67
  )
232
68
  end
@@ -234,18 +70,18 @@ module CanvasSync
234
70
  def bulk_process_courses(report_file_path)
235
71
  CanvasSync::Importers::BulkImporter.import(
236
72
  report_file_path,
237
- COURSES_CSV_MAPPING,
73
+ mapping[:courses][:report_columns],
238
74
  Course,
239
- :canvas_course_id
75
+ mapping[:courses][:conflict_target].to_sym
240
76
  )
241
77
  end
242
78
 
243
79
  def bulk_process_enrollments(report_file_path)
244
80
  CanvasSync::Importers::BulkImporter.import(
245
81
  report_file_path,
246
- ENROLLMENTS_CSV_MAPPING,
82
+ mapping[:enrollments][:report_columns],
247
83
  Enrollment,
248
- :canvas_enrollment_id,
84
+ mapping[:enrollments][:conflict_target].to_sym,
249
85
  true
250
86
  )
251
87
  end
@@ -253,20 +89,34 @@ module CanvasSync
253
89
  def bulk_process_sections(report_file_path)
254
90
  CanvasSync::Importers::BulkImporter.import(
255
91
  report_file_path,
256
- SECTIONS_CSV_MAPPING,
92
+ mapping[:sections][:report_columns],
257
93
  Section,
258
- :canvas_section_id
94
+ mapping[:sections][:conflict_target].to_sym
259
95
  )
260
96
  end
261
97
 
262
98
  def bulk_process_xlist(report_file_path)
263
99
  CanvasSync::Importers::BulkImporter.import(
264
100
  report_file_path,
265
- XLIST_CSV_MAPPING,
101
+ mapping[:xlist][:report_columns],
266
102
  Section,
267
- :canvas_section_id,
103
+ mapping[:xlist][:conflict_target].to_sym
268
104
  )
269
105
  end
106
+
107
+ def mapping
108
+ @mapping ||= begin
109
+ mapping = YAML::load_file(File.join(__dir__, 'model_mappings.yml')).deep_symbolize_keys!
110
+ override_filepath = Rails.root.join("config/canvas_sync_provisioning_mapping.yml")
111
+
112
+ if File.file?(override_filepath)
113
+ override = YAML::load_file(override_filepath).deep_symbolize_keys!
114
+ mapping = mapping.merge(override)
115
+ end
116
+
117
+ mapping
118
+ end
119
+ end
270
120
  end
271
121
  end
272
122
  end
@@ -1,3 +1,3 @@
1
1
  module CanvasSync
2
- VERSION = "0.2.4"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canvas_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nate Collings
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-08 00:00:00.000000000 Z
11
+ date: 2017-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -309,6 +309,7 @@ files:
309
309
  - lib/canvas_sync/jobs/sync_provisioning_report_job.rb
310
310
  - lib/canvas_sync/jobs/sync_terms_job.rb
311
311
  - lib/canvas_sync/jobs/sync_users_job.rb
312
+ - lib/canvas_sync/processors/model_mappings.yml
312
313
  - lib/canvas_sync/processors/provisioning_report_processor.rb
313
314
  - lib/canvas_sync/version.rb
314
315
  - spec/canvas_sync/canvas_sync_spec.rb