Class: PandaPal::Session
Defined Under Namespace
Classes: DataSerializer, RoleStore
Instance Method Summary
collapse
Instance Method Details
#[](key) ⇒ Object
9
10
11
12
13
14
15
|
# File 'app/models/panda_pal/session.rb', line 9
def [](key)
if column_names.include?(key.to_s)
super
else
data[key]
end
end
|
#[]=(key, value) ⇒ Object
17
18
19
20
21
22
23
|
# File 'app/models/panda_pal/session.rb', line 17
def []=(key, value)
if column_names.include?(key.to_s)
super
else
data[key] = value
end
end
|
#cache(key, &blk) ⇒ Object
25
26
27
28
|
# File 'app/models/panda_pal/session.rb', line 25
def cache(key, &blk)
data[:cache] ||= {}
data[:cache][key] ||= blk.call
end
|
#canvas_account_role_labels(account = 'self') ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'app/models/panda_pal/session.rb', line 70
def canvas_account_role_labels(account = 'self')
account = 'self' if account.to_s == "root"
account = account.canvas_id if account.respond_to?(:canvas_id)
if "::Admin".safe_constantize && ::Admin < ::ActiveRecord::Base
account = current_organization.canvas_account_id if account == 'self'
adm_query = ::Admin.where(canvas_account_id: account, workflow_state: "active")
adm_query.pluck(:role_name)
else
Rails.cache.fetch([self.class.name, "AccountAdminLinks", account, canvas_user_id], expires_in: 1.hour) do
admin_entries = canvas_sync_client.account_admins(account, user_id: [canvas_user_id])
admin_entries = admin_entries.select{|ent| ent[:workflow_state] == 'active' }
admin_entries.map{|ent| ent[:role] }
end
end
end
|
#canvas_role_labels ⇒ Object
65
66
67
68
|
# File 'app/models/panda_pal/session.rb', line 65
def canvas_role_labels
labels = get_lti_cust_param('custom_canvas_role')
labels.is_a?(String) ? labels.split(',') : []
end
|
#canvas_site_admin? ⇒ Boolean
91
92
93
|
# File 'app/models/panda_pal/session.rb', line 91
def canvas_site_admin?
lti_roles.system_roles.include?("sys_admin")
end
|
#custom_lti_params ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'app/models/panda_pal/session.rb', line 44
def custom_lti_params
custom_params = launch_params["https://purl.imsglobal.org/spec/lti/claim/custom"]
return custom_params if custom_params.present?
custom_params = {}
launch_params.each do |k, v|
next unless k.start_with?("custom_")
custom_params[k[7..-1]] = v
end
custom_params.with_indifferent_access
end
|
#get_lti_cust_param(key) ⇒ Object
59
60
61
62
63
|
# File 'app/models/panda_pal/session.rb', line 59
def get_lti_cust_param(key)
nkey = key.to_s.gsub(/^custom_/, '')
launch_params.dig("https://purl.imsglobal.org/spec/lti/claim/custom", nkey) || launch_params[nkey] || launch_params["custom_#{nkey}"]
end
|
#launch_params ⇒ Object
30
31
32
|
# File 'app/models/panda_pal/session.rb', line 30
def launch_params
data[:launch_params] || {}
end
|
#lti_launch_placement ⇒ Object
40
41
42
|
# File 'app/models/panda_pal/session.rb', line 40
def lti_launch_placement
launch_params['https://www.instructure.com/placement'] || launch_params[:launch_type]
end
|
34
35
36
37
38
|
# File 'app/models/panda_pal/session.rb', line 34
def lti_platform
return nil unless data[:lti_platform].present?
@lti_platform ||= Platform.from_serialized(data[:lti_platform])
end
|
#lti_roles ⇒ Object
87
88
89
|
# File 'app/models/panda_pal/session.rb', line 87
def lti_roles
@lti_roles ||= RoleStore.new(launch_params["https://purl.imsglobal.org/spec/lti/claim/roles"] || launch_params['ext_roles'] || '')
end
|