canvas_sync 0.18.7 → 0.18.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/canvas_sync/concerns/ability_helper.rb +64 -67
- data/lib/canvas_sync/concerns/sync_mapping.rb +4 -0
- data/lib/canvas_sync/engine.rb +8 -5
- data/lib/canvas_sync/job_batches/batch.rb +4 -6
- data/lib/canvas_sync/job_batches/jobs/managed_batch_job.rb +3 -1
- data/lib/canvas_sync/job_batches/redis_model.rb +2 -2
- data/lib/canvas_sync/jobs/sync_provisioning_report_job.rb +1 -1
- data/lib/canvas_sync/processors/report_processor.rb +1 -1
- data/lib/canvas_sync/version.rb +1 -1
- data/lib/canvas_sync.rb +7 -0
- data/spec/canvas_sync/processors/provisioning_report_processor_spec.rb +2 -0
- data/spec/dummy/log/test.log +38927 -0
- data/spec/job_batching/integration_helper.rb +2 -2
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 490c7e8d4a1b61e5bd17dd938a0387f68718789bb05ad8c071d1a7dca83374ac
|
4
|
+
data.tar.gz: 06e933489bb8fd39f8af4a2c8498032faf7edf064a1df5cf882659823fa0f597
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43fb1c9a539c970093c742ef2dd8cb1737a46f3b47ed1958b25fb3e3703ca3195677024d62d438d101ac913a53dbd86291fdaa3bd290c78e0b318064f6c27ddf
|
7
|
+
data.tar.gz: a08e7076c32de83470a32d2238ed0ac77055d3afa65411c0663330803e58b7edf2c9fa6a3b121c2835ec2347a23c40499248d35199c83de3f99347c71d7e77c9
|
@@ -43,73 +43,6 @@ module CanvasSync::Concerns
|
|
43
43
|
lti_roles.system_roles.include?("sys_admin")
|
44
44
|
end
|
45
45
|
|
46
|
-
# Middle Domain
|
47
|
-
|
48
|
-
def launch_context
|
49
|
-
@launch_context ||= begin
|
50
|
-
if lti_launch_placement == "global_navigation"
|
51
|
-
:global
|
52
|
-
elsif get_lti_cust_param('custom_canvas_course_id').present?
|
53
|
-
::Course.find_by(canvas_id: get_lti_cust_param('custom_canvas_course_id'))
|
54
|
-
else
|
55
|
-
::Account.find_by(canvas_id: get_lti_cust_param('custom_canvas_account_id'))
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def launch_account
|
61
|
-
@launch_account ||= launch_context.respond_to?(:account) ? launch_context.account : ::Account.find_by(canvas_id: get_lti_cust_param('custom_canvas_account_id'))
|
62
|
-
end
|
63
|
-
|
64
|
-
# CanvasSync Domain
|
65
|
-
|
66
|
-
def canvas_permissions
|
67
|
-
panda_pal_session[:canvas_permissions] ||= ::Role.role_permissions(canvas_roles)
|
68
|
-
end
|
69
|
-
|
70
|
-
def canvas_roles
|
71
|
-
@canvas_roles ||= Role.for_labels(canvas_role_labels, launch_account)
|
72
|
-
end
|
73
|
-
|
74
|
-
def canvas_root_account_roles
|
75
|
-
role_labels = if "::Admin".safe_constantize && ::Admin < ::ActiveRecord::Base
|
76
|
-
adm_query = ::Admin.where(canvas_account_id: current_organization.canvas_account_id, workflow_state: "active")
|
77
|
-
adm_query.pluck(:role_name)
|
78
|
-
else
|
79
|
-
Rails.cache.fetch([self.class.name, "RootAccountAdminLinks", canvas_user_id], expires_in: 1.hour) do
|
80
|
-
admin_entries = canvas_sync_client.account_admins('self', user_id: [canvas_user_id])
|
81
|
-
admin_entries = admin_entries.select{|ent| ent[:workflow_state] == 'active' }
|
82
|
-
admin_entries.map{|ent| ent[:role] }
|
83
|
-
end
|
84
|
-
end
|
85
|
-
::Role.for_labels(role_labels, ::Account.find_by(canvas_parent_account_id: nil))
|
86
|
-
end
|
87
|
-
|
88
|
-
def canvas_account_roles
|
89
|
-
canvas_roles.where(base_role_type: 'AccountMembership')
|
90
|
-
end
|
91
|
-
|
92
|
-
def canvas_course_roles
|
93
|
-
canvas_roles.where.not(base_role_type: 'AccountMembership')
|
94
|
-
end
|
95
|
-
|
96
|
-
def canvas_super_user?
|
97
|
-
cache_on_session(:canvas_super_user?) do
|
98
|
-
canvas_site_admin? || canvas_root_account_roles.map(&:label).include?("Account Admin")
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def canvas_user_id
|
103
|
-
user&.canvas_id
|
104
|
-
end
|
105
|
-
|
106
|
-
private
|
107
|
-
|
108
|
-
def cache_on_session(key, &blk)
|
109
|
-
panda_pal_session[:ability_cache] ||= {}
|
110
|
-
panda_pal_session[:ability_cache][key] ||= blk.call
|
111
|
-
end
|
112
|
-
|
113
46
|
class RoleStore
|
114
47
|
ContextTypeURN = 'urn:lti:context-type:ims/lis/'.freeze
|
115
48
|
|
@@ -181,5 +114,69 @@ module CanvasSync::Concerns
|
|
181
114
|
end
|
182
115
|
end
|
183
116
|
|
117
|
+
# Middle Domain
|
118
|
+
|
119
|
+
def launch_context
|
120
|
+
@launch_context ||= begin
|
121
|
+
if lti_launch_placement == "global_navigation"
|
122
|
+
:global
|
123
|
+
elsif get_lti_cust_param('custom_canvas_course_id').present?
|
124
|
+
::Course.find_by(canvas_id: get_lti_cust_param('custom_canvas_course_id'))
|
125
|
+
else
|
126
|
+
::Account.find_by(canvas_id: get_lti_cust_param('custom_canvas_account_id'))
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def launch_account
|
132
|
+
@launch_account ||= launch_context.respond_to?(:account) ? launch_context.account : ::Account.find_by(canvas_id: get_lti_cust_param('custom_canvas_account_id'))
|
133
|
+
end
|
134
|
+
|
135
|
+
def cache_on_session(key, &blk)
|
136
|
+
panda_pal_session[:ability_cache] ||= {}
|
137
|
+
panda_pal_session[:ability_cache][key] ||= blk.call
|
138
|
+
end
|
139
|
+
|
140
|
+
# CanvasSync Domain
|
141
|
+
|
142
|
+
def canvas_permissions
|
143
|
+
panda_pal_session[:canvas_permissions] ||= ::Role.role_permissions(canvas_roles)
|
144
|
+
end
|
145
|
+
|
146
|
+
def canvas_roles
|
147
|
+
@canvas_roles ||= Role.for_labels(canvas_role_labels, launch_account)
|
148
|
+
end
|
149
|
+
|
150
|
+
def canvas_root_account_roles
|
151
|
+
role_labels = if "::Admin".safe_constantize && ::Admin < ::ActiveRecord::Base
|
152
|
+
adm_query = ::Admin.where(canvas_account_id: current_organization.canvas_account_id, workflow_state: "active")
|
153
|
+
adm_query.pluck(:role_name)
|
154
|
+
else
|
155
|
+
Rails.cache.fetch([self.class.name, "RootAccountAdminLinks", canvas_user_id], expires_in: 1.hour) do
|
156
|
+
admin_entries = canvas_sync_client.account_admins('self', user_id: [canvas_user_id])
|
157
|
+
admin_entries = admin_entries.select{|ent| ent[:workflow_state] == 'active' }
|
158
|
+
admin_entries.map{|ent| ent[:role] }
|
159
|
+
end
|
160
|
+
end
|
161
|
+
::Role.for_labels(role_labels, ::Account.find_by(canvas_parent_account_id: nil))
|
162
|
+
end
|
163
|
+
|
164
|
+
def canvas_account_roles
|
165
|
+
canvas_roles.where(base_role_type: 'AccountMembership')
|
166
|
+
end
|
167
|
+
|
168
|
+
def canvas_course_roles
|
169
|
+
canvas_roles.where.not(base_role_type: 'AccountMembership')
|
170
|
+
end
|
171
|
+
|
172
|
+
def canvas_super_user?
|
173
|
+
cache_on_session(:canvas_super_user?) do
|
174
|
+
canvas_site_admin? || canvas_root_account_roles.map(&:label).include?("Account Admin")
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def canvas_user_id
|
179
|
+
user&.canvas_id
|
180
|
+
end
|
184
181
|
end
|
185
182
|
end
|
@@ -2,6 +2,10 @@ module CanvasSync::Concerns
|
|
2
2
|
module SyncMapping
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
+
def self.mapping_for(model, key = nil)
|
6
|
+
model.try(:get_sync_mapping, key) || Mapping.default_mappings[key || Mapping.normalize_model_name(model)]
|
7
|
+
end
|
8
|
+
|
5
9
|
class_methods do
|
6
10
|
def sync_mapping(key = nil, reset: false, &blk)
|
7
11
|
key ||= Mapping.normalize_model_name(self)
|
data/lib/canvas_sync/engine.rb
CHANGED
@@ -8,10 +8,14 @@ module CanvasSync
|
|
8
8
|
initializer "canvas_sync.safe_yaml_classes" do |app|
|
9
9
|
app.config.active_record.yaml_column_permitted_classes ||= []
|
10
10
|
app.config.active_record.yaml_column_permitted_classes |= [Symbol, ActiveSupport::HashWithIndifferentAccess]
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
|
12
|
+
Rails.application.config.after_initialize do
|
13
|
+
if ActiveRecord::Base.respond_to?(:yaml_column_permitted_classes)
|
14
|
+
ActiveRecord::Base.yaml_column_permitted_classes |= app.config.active_record.yaml_column_permitted_classes
|
15
|
+
end
|
16
|
+
if ActiveRecord.respond_to?(:yaml_column_permitted_classes)
|
17
|
+
ActiveRecord.yaml_column_permitted_classes |= app.config.active_record.yaml_column_permitted_classes
|
18
|
+
end
|
15
19
|
end
|
16
20
|
rescue
|
17
21
|
end
|
@@ -52,7 +56,6 @@ module CanvasSync
|
|
52
56
|
Bearcat::Client.new(
|
53
57
|
prefix: org.canvas_url,
|
54
58
|
token: org.canvas_api_token,
|
55
|
-
master_rate_limit: (Rails.env.production? && !!defined?(Redis) && ENV['REDIS_URL'].present?),
|
56
59
|
)
|
57
60
|
end
|
58
61
|
end
|
@@ -45,7 +45,7 @@ module CanvasSync
|
|
45
45
|
redis_attr :created_at
|
46
46
|
redis_attr :callback_queue, read_only: false
|
47
47
|
redis_attr :callback_params, :json
|
48
|
-
redis_attr :allow_context_changes
|
48
|
+
redis_attr :allow_context_changes, :bool
|
49
49
|
|
50
50
|
def context
|
51
51
|
return @context if defined?(@context)
|
@@ -402,20 +402,18 @@ module CanvasSync
|
|
402
402
|
|
403
403
|
if Thread.current[:job_batches_redis]
|
404
404
|
yield Thread.current[:job_batches_redis]
|
405
|
-
|
406
|
-
::
|
405
|
+
else
|
406
|
+
::Bearcat.redis do |r|
|
407
407
|
Thread.current[:job_batches_redis] = r
|
408
408
|
yield r
|
409
409
|
ensure
|
410
410
|
Thread.current[:job_batches_redis] = nil
|
411
411
|
end
|
412
|
-
else
|
413
|
-
# TODO
|
414
412
|
end
|
415
413
|
end
|
416
414
|
|
417
415
|
def logger
|
418
|
-
|
416
|
+
::CanvasSync.logger
|
419
417
|
end
|
420
418
|
|
421
419
|
def push_callbacks(args, queue)
|
@@ -20,7 +20,7 @@ module CanvasSync
|
|
20
20
|
Batch.redis do |r|
|
21
21
|
r.multi do |r|
|
22
22
|
r.hset("MNGBID-#{man_batch_id}", "root_bid", root_batch.bid)
|
23
|
-
r.hset("MNGBID-#{man_batch_id}", "ordered", ordered)
|
23
|
+
r.hset("MNGBID-#{man_batch_id}", "ordered", ordered ? 1 : 0)
|
24
24
|
r.hset("MNGBID-#{man_batch_id}", "concurrency", concurrency)
|
25
25
|
r.expire("MNGBID-#{man_batch_id}", Batch::BID_EXPIRE_TTL)
|
26
26
|
|
@@ -93,6 +93,8 @@ module CanvasSync
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
+
ordered = CanvasSync::MiscHelper.to_boolean(ordered)
|
97
|
+
|
96
98
|
next_job_json = Batch.redis do |r|
|
97
99
|
if ordered
|
98
100
|
r.lpop("MNGBID-#{man_batch_id}-jobs")
|
@@ -41,13 +41,13 @@ module CanvasSync
|
|
41
41
|
if @initialized || @existing
|
42
42
|
redis do |r|
|
43
43
|
r.multi do |r|
|
44
|
-
r.hset(redis_key, attribute, value)
|
44
|
+
r.hset(redis_key, attribute, value.to_s)
|
45
45
|
r.expire(redis_key, Batch::BID_EXPIRE_TTL)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
else
|
49
49
|
@pending_attrs ||= {}
|
50
|
-
@pending_attrs[attribute] = value
|
50
|
+
@pending_attrs[attribute] = value.to_s
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -18,7 +18,7 @@ module CanvasSync
|
|
18
18
|
|
19
19
|
# Make sure the report also checks last_activity_at when checking updated_at
|
20
20
|
if options[:models].include?("enrollments")
|
21
|
-
if (%w[last_activity_at total_activity_time] & Enrollment
|
21
|
+
if (%w[last_activity_at total_activity_time] & CanvasSync::Concerns::SyncMapping.mapping_for(Enrollment)[:columns].keys).present? && merged_params.dig(:parameters, :include_last_activity) == nil
|
22
22
|
merged_params[:parameters][:include_last_activity] = true
|
23
23
|
end
|
24
24
|
end
|
@@ -9,7 +9,7 @@ module CanvasSync
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def mapping_for(model, key = nil)
|
12
|
-
|
12
|
+
CanvasSync::Concerns::SyncMapping.mapping_for(model, key)
|
13
13
|
end
|
14
14
|
|
15
15
|
def do_bulk_import(report_file_path, model, options: {}, mapping_key: nil, &blk)
|
data/lib/canvas_sync/version.rb
CHANGED
data/lib/canvas_sync.rb
CHANGED
@@ -324,6 +324,13 @@ module CanvasSync
|
|
324
324
|
raise "Invalid live event(s) specified: #{invalid.join(', ')}. Only #{SUPPORTED_LIVE_EVENTS.join(', ')} are supported."
|
325
325
|
end
|
326
326
|
|
327
|
+
def logger
|
328
|
+
return @logger if defined? @logger
|
329
|
+
@logger = Logger.new(STDOUT)
|
330
|
+
@logger.level = Logger::DEBUG
|
331
|
+
@logger
|
332
|
+
end
|
333
|
+
|
327
334
|
def redis(*args, &blk)
|
328
335
|
JobBatches::Batch.redis(*args, &blk)
|
329
336
|
end
|
@@ -15,11 +15,13 @@ RSpec.describe CanvasSync::Processors::ProvisioningReportProcessor do
|
|
15
15
|
self.use_transactional_tests = false
|
16
16
|
ActiveRecord::Migration.add_column :users, :sis_id, :string
|
17
17
|
User.reset_column_information
|
18
|
+
User.instance_variable_set(:@schema_columns_hash, nil)
|
18
19
|
end
|
19
20
|
|
20
21
|
after do
|
21
22
|
ActiveRecord::Migration.remove_column :users, :sis_id
|
22
23
|
User.reset_column_information
|
24
|
+
User.instance_variable_set(:@schema_columns_hash, nil)
|
23
25
|
self.use_transactional_tests = true
|
24
26
|
end
|
25
27
|
|