panda_pal 5.6.8 → 5.6.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/panda_pal/api_call.rb +1 -1
- data/app/models/panda_pal/organization.rb +12 -4
- data/app/models/panda_pal/platform/canvas.rb +73 -37
- data/app/models/panda_pal/platform.rb +5 -6
- data/lib/panda_pal/version.rb +1 -1
- data/spec/dummy/log/test.log +1046 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c935b2a3eae094ada04fdc46e45f25414c61b2e9afbf9c77d81ae611343548a
|
4
|
+
data.tar.gz: 96a098c934a92e921dc951ea0c492a0af5a5c2d8ebfbe57028a344a025c4e718
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e63f7e0b91ce15a03e1baa5f64ec479fb28a921f1301daaac2c5376f3da8aea0728c0639f25836ef9e5e228fe7dd82424935df92511c50d3ad6ca0afa10c55c4
|
7
|
+
data.tar.gz: 3e8ffeff4dc35b093d8c2a2b243a1f5a496902508e3207a564285617b7465c803e7d875a21703e452c5afd53529ceb2f660f7e77bfdecd479178be9567f805c0
|
@@ -52,7 +52,7 @@ module PandaPal
|
|
52
52
|
}
|
53
53
|
if expiration.present?
|
54
54
|
expiration = DateTime.parse(expiration) if expiration.is_a?(String)
|
55
|
-
payload[:exp] = expiration.
|
55
|
+
payload[:exp] = expiration.to_i
|
56
56
|
end
|
57
57
|
::JWT.encode(payload, Rails.application.secret_key_base, 'HS256')
|
58
58
|
end
|
@@ -72,10 +72,6 @@ module PandaPal
|
|
72
72
|
find_by_name(Apartment::Tenant.current)
|
73
73
|
end
|
74
74
|
|
75
|
-
PandaPal.resolved_extensions_for(self).each do |ext|
|
76
|
-
include ext
|
77
|
-
end
|
78
|
-
|
79
75
|
def create_api(logic, expiration: nil, uses: nil, host: nil)
|
80
76
|
switch_tenant do
|
81
77
|
logic = "current_organization.#{logic}" if logic.is_a?(Symbol)
|
@@ -102,6 +98,14 @@ module PandaPal
|
|
102
98
|
switch_tenant if do_switch
|
103
99
|
end
|
104
100
|
|
101
|
+
def platform_extensions(platform_type)
|
102
|
+
return self unless defined?(platform_type::OrgExtension)
|
103
|
+
return self if self.class < platform_type::OrgExtension
|
104
|
+
|
105
|
+
scl = platform_type.org_subclass
|
106
|
+
scl ? becomes(scl) : self
|
107
|
+
end
|
108
|
+
|
105
109
|
if !PandaPal.lti_options[:platform].present? || PandaPal.lti_options[:platform].is_a?(String)
|
106
110
|
platform_cls = Platform.resolve_platform_class(nil) rescue nil
|
107
111
|
if platform_cls && defined?(platform_cls::OrgExtension)
|
@@ -109,6 +113,10 @@ module PandaPal
|
|
109
113
|
end
|
110
114
|
end
|
111
115
|
|
116
|
+
PandaPal.resolved_extensions_for(self).each do |ext|
|
117
|
+
include ext
|
118
|
+
end
|
119
|
+
|
112
120
|
private
|
113
121
|
|
114
122
|
def create_schema
|
@@ -28,54 +28,77 @@ module PandaPal
|
|
28
28
|
module OrgExtension
|
29
29
|
extend ActiveSupport::Concern
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
included do
|
32
|
+
define_model_callbacks :lti_install
|
33
|
+
end
|
33
34
|
|
35
|
+
def _parse_lti_context(context)
|
34
36
|
context = context.to_s
|
35
37
|
context = 'account/self' if context == 'root_account'
|
36
38
|
cid, ctype = context.split(/[\.\/]/).reverse
|
37
39
|
ctype ||= 'account'
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
-
lti[:consumer_key] == self.key
|
42
|
-
end
|
41
|
+
[ctype, cid]
|
42
|
+
end
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
description: PandaPal.lti_options[:description],
|
47
|
-
consumer_key: self.key,
|
48
|
-
shared_secret: self.secret,
|
49
|
-
privacy_level: "public",
|
50
|
-
config_type: 'by_url',
|
51
|
-
config_url: PandaPal::LaunchUrlHelpers.resolve_route(:v1p0_config_url, host: host),
|
52
|
-
}
|
44
|
+
def install_lti(host: nil, context: :root_account, version: 'v1p3', exists: :error, dedicated_deployment: false)
|
45
|
+
raise "Automatically installing this LTI requires Bearcat." unless defined?(Bearcat)
|
53
46
|
|
54
|
-
|
55
|
-
|
56
|
-
ekey = _ensure_lti_v1p3_key(exists: exists)
|
47
|
+
run_callbacks :lti_install do
|
48
|
+
ctype, cid = _parse_lti_context(context)
|
57
49
|
|
58
|
-
|
59
|
-
|
60
|
-
|
50
|
+
if version == 'v1p0'
|
51
|
+
existing_installs = _find_existing_installs(exists: exists) do |lti|
|
52
|
+
lti[:consumer_key] == self.key
|
53
|
+
end
|
61
54
|
|
62
|
-
|
63
|
-
|
64
|
-
|
55
|
+
conf = {
|
56
|
+
name: PandaPal.lti_options[:title],
|
57
|
+
description: PandaPal.lti_options[:description],
|
58
|
+
consumer_key: self.key,
|
59
|
+
shared_secret: self.secret,
|
60
|
+
privacy_level: "public",
|
61
|
+
config_type: 'by_url',
|
62
|
+
config_url: PandaPal::LaunchUrlHelpers.resolve_route(:v1p0_config_url, host: host),
|
63
|
+
}
|
64
|
+
|
65
|
+
api_result = existing_installs[0] ? bearcat_client.send(:"edit_#{ctype}_external_tool", cid, existing_installs[0][:id], conf) : bearcat_client.send(:"create_#{ctype}_external_tool", cid, conf)
|
66
|
+
|
67
|
+
@new_lti_installation = api_result
|
68
|
+
elsif version == 'v1p3'
|
69
|
+
ekey = _ensure_lti_v1p3_key(exists: exists, host: host)
|
70
|
+
|
71
|
+
existing_installs = _find_existing_installs(context, exists: exists) do |lti|
|
72
|
+
lti[:developer_key_id] == (ekey[:id] % 10_000_000_000_000)
|
73
|
+
end
|
65
74
|
|
66
|
-
|
67
|
-
new_client_id += "/#{scope_tool[:deployment_id]}" if dedicated_deployment
|
75
|
+
scope_tool = existing_installs[0]
|
68
76
|
|
69
|
-
|
70
|
-
|
77
|
+
# Don't need to do an update if it already exists - Settings are stored on the LTI Key instead of the installation
|
78
|
+
unless scope_tool
|
79
|
+
scope_tool = bearcat_client.send(:"create_#{ctype}_external_tool", cid, {
|
80
|
+
client_id: ekey[:id],
|
81
|
+
})
|
71
82
|
|
72
|
-
|
73
|
-
|
74
|
-
|
83
|
+
new_client_id = "#{ekey[:id]}"
|
84
|
+
new_client_id += "/#{scope_tool[:deployment_id]}" if dedicated_deployment
|
85
|
+
|
86
|
+
self.key = new_client_id
|
87
|
+
self.secret = ekey[:api_key]
|
88
|
+
|
89
|
+
save! if changed?
|
90
|
+
end
|
91
|
+
|
92
|
+
@new_lti_installation = scope_tool
|
93
|
+
else
|
94
|
+
raise "Unrecognized LTI Version #{version}"
|
95
|
+
end
|
75
96
|
end
|
97
|
+
|
98
|
+
save!
|
76
99
|
end
|
77
100
|
|
78
|
-
def _ensure_lti_v1p3_key(exists:)
|
101
|
+
def _ensure_lti_v1p3_key(exists:, host:)
|
79
102
|
current_client_id = self.key.split('/')[0]
|
80
103
|
|
81
104
|
existing_keys = []
|
@@ -111,7 +134,10 @@ module PandaPal
|
|
111
134
|
# Update Existing
|
112
135
|
ekey = bearcat_client.put("api/lti/developer_keys/#{ekey[:id]}/tool_configuration", {
|
113
136
|
developer_key: ekey[:developer_key],
|
114
|
-
tool_configuration: lti_json,
|
137
|
+
# tool_configuration: lti_json,
|
138
|
+
tool_configuration: {
|
139
|
+
settings: lti_json,
|
140
|
+
},
|
115
141
|
})
|
116
142
|
end
|
117
143
|
|
@@ -128,26 +154,32 @@ module PandaPal
|
|
128
154
|
ekey
|
129
155
|
end
|
130
156
|
|
131
|
-
def _find_existing_installs(exists
|
157
|
+
def _find_existing_installs(context, exists: nil, &matcher)
|
158
|
+
ctype, cid = _parse_lti_context(context)
|
159
|
+
|
132
160
|
existing_installs = bearcat_client.send(:"#{ctype}_external_tools", cid).all_pages_each.filter do |cet|
|
133
161
|
matcher.call(cet)
|
134
162
|
end
|
135
163
|
|
136
|
-
if existing_installs.present?
|
164
|
+
if exists.present? && existing_installs.present?
|
137
165
|
case exists
|
138
166
|
when :error
|
139
167
|
raise "Tool with key #{self.key} already installed"
|
140
168
|
when :duplicate
|
169
|
+
[]
|
141
170
|
when :replace
|
142
171
|
existing_installs.each do |install|
|
143
172
|
bearcat_client.send(:"delete_#{ctype}_external_tool", cid, install[:id])
|
144
173
|
end
|
174
|
+
[]
|
175
|
+
when :update
|
176
|
+
existing_installs
|
145
177
|
else
|
146
178
|
raise "exists: #{exists} is not supported"
|
147
179
|
end
|
180
|
+
else
|
181
|
+
existing_installs
|
148
182
|
end
|
149
|
-
|
150
|
-
existing_installs
|
151
183
|
end
|
152
184
|
|
153
185
|
def reinstall_lti!(*args, **kwargs)
|
@@ -199,6 +231,10 @@ module PandaPal
|
|
199
231
|
end
|
200
232
|
end
|
201
233
|
|
234
|
+
def lti_installations(context= :root_account)
|
235
|
+
_find_existing_installs(context)
|
236
|
+
end
|
237
|
+
|
202
238
|
def canvas_url
|
203
239
|
PandaPal::Platform.find_org_setting([
|
204
240
|
"canvas.base_url",
|
@@ -72,14 +72,13 @@ module PandaPal
|
|
72
72
|
raise "Unknown platform '#{platform}'"
|
73
73
|
end
|
74
74
|
|
75
|
-
def self.
|
75
|
+
def self.org_subclass
|
76
76
|
return nil unless defined?(self::OrgExtension)
|
77
|
+
oext = self::OrgExtension
|
77
78
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
org
|
79
|
+
@org_subclass ||= Class.new(PandaPal::Organization) do
|
80
|
+
include oext
|
81
|
+
end
|
83
82
|
end
|
84
83
|
|
85
84
|
protected
|
data/lib/panda_pal/version.rb
CHANGED