panda_pal 5.19.0.beta2 → 5.19.0.beta3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b8433b20262277ab9a0e66156b4fb2b865919cbfe73701202c163b1dd4c063c9
4
- data.tar.gz: fba4d18d40156ccf1799c33b4b2a5aed33b71c6e0e772a65df04c586f207503f
3
+ metadata.gz: dc0521710ced7088a0342c4af3b5fc5e0435b3578aafe0ae1223ea98024e78ee
4
+ data.tar.gz: 48fb53a3d5522496fc93e8f74f4ceff4c3e510c5a8c74a2a16b4b5a83a7e1294
5
5
  SHA512:
6
- metadata.gz: 33e70423978afce311e1e0d4a5eecddc17e8814e922bea12e854b1b57135cc336e1c418b6f8d0fcca061c4a25485164dab1468805639d16abd6f1c1951f7b4cb
7
- data.tar.gz: fa08843f3ad5d268203908c22725c546825102127cce6858c907a84b21e0a58561fab5f1e017b569cb95abd5e42c1715045b699b7790f899e7bbabfbf8f9693c
6
+ metadata.gz: eceb5025a2c539f4ca2c9d6a2757d34595cc8071a30d34b988310ee06cf5e8224d4b514b8cc73bb0f871f2c810d31070c09c4fa3b6d58d61d5f65344aef35d4e
7
+ data.tar.gz: 23402bf99ee96e7ecd37bda8750e5463cf12361c703d38112d464bfa8314ca666ff8bc66cfac3d59205cb3874e7d0613e076be0b55cbb4ecd36674ffda2d285c
@@ -148,28 +148,16 @@ module PandaPal
148
148
  scope_tool = existing_installs[0]
149
149
 
150
150
  # Don't need to do an update if it already exists - Settings are stored on the LTI Key instead of the installation
151
- if tool != PandaPal::DEFAULT_TOOL
152
- scope_tool ||= bearcat_client.send(:"create_#{ctype}_external_tool", cid, {
151
+ new_install = !scope_tool
152
+ scope_tool ||= _with_lti_registration_unlocked(ekey) do
153
+ bearcat_client.send(:"create_#{ctype}_external_tool", cid, {
153
154
  client_id: ekey[:id],
154
155
  })
156
+ end
155
157
 
156
- lti_registrations.find_or_create_by!(
157
- tool: tool.to_s,
158
- client_id: ekey[:id].to_s,
159
- deployment_id: (scope_tool[:deployment_id].presence&.to_s if dedicated_deployment),
160
- )
161
- elsif !scope_tool
162
- scope_tool = bearcat_client.send(:"create_#{ctype}_external_tool", cid, {
163
- client_id: ekey[:id],
164
- })
165
-
166
- new_client_id = "#{ekey[:id]}"
167
- new_client_id += "/#{scope_tool[:deployment_id]}" if dedicated_deployment
168
-
169
- self.key = new_client_id
170
- self.secret = ekey[:api_key]
171
-
172
- save! if changed?
158
+ # The default tool's key only moves with a new install; other tools always (re)register
159
+ if new_install || tool != PandaPal::DEFAULT_TOOL
160
+ _register_lti_v1p3_key(tool, ekey, deployment_id: (scope_tool[:deployment_id].presence&.to_s if dedicated_deployment))
173
161
  end
174
162
 
175
163
  @new_lti_installation = scope_tool
@@ -244,7 +232,8 @@ module PandaPal
244
232
 
245
233
  valid_redirect_uris.uniq!
246
234
 
247
- if !ekey
235
+ created = !ekey
236
+ if created
248
237
  # Create New
249
238
  ekey = bearcat_client.post("api/lti/accounts/self/developer_keys/tool_configuration", {
250
239
  developer_key: {
@@ -270,6 +259,10 @@ module PandaPal
270
259
 
271
260
  ekey = ekey[:developer_key] || ekey
272
261
 
262
+ # Record a new key right away, so a failed install is retried against
263
+ # this key instead of creating yet another one.
264
+ _register_lti_v1p3_key(tool, ekey) if created
265
+
273
266
  if ekey[:developer_key_account_binding][:workflow_state] == "off"
274
267
  bearcat_client.post("api/v1/accounts/self/developer_keys/#{ekey[:id]}/developer_key_account_bindings", {
275
268
  developer_key_account_binding: {
@@ -281,6 +274,42 @@ module PandaPal
281
274
  ekey
282
275
  end
283
276
 
277
+ # Points this Organization (default tool) or an LtiRegistration (other
278
+ # tools) at a v1.3 Developer Key.
279
+ def _register_lti_v1p3_key(tool, ekey, deployment_id: nil)
280
+ client_id = ekey[:id].to_s
281
+
282
+ if tool == PandaPal::DEFAULT_TOOL
283
+ self.key = deployment_id ? "#{client_id}/#{deployment_id}" : client_id
284
+ self.secret = ekey[:api_key] if ekey[:api_key].present?
285
+ save! if changed?
286
+ else
287
+ lti_registrations.find_or_create_by!(tool: tool.to_s, client_id: client_id, deployment_id: deployment_id)
288
+ # Drop the deployment-less placeholder recorded when the key was created
289
+ lti_registrations.where(tool: tool.to_s, client_id: client_id, deployment_id: nil).delete_all if deployment_id
290
+ end
291
+ end
292
+
293
+ # Canvas creates LTI Registrations with lock_deploying on, which blocks
294
+ # installing by client_id (when lock_lti_registrations is enabled). Unlock
295
+ # for the duration of the block, then put the lock back as it was.
296
+ def _with_lti_registration_unlocked(ekey)
297
+ registration_id = ekey[:lti_registration_id]
298
+ return yield unless registration_id.present?
299
+
300
+ registration_url = "api/v1/accounts/self/lti_registrations/#{registration_id}"
301
+ registration = bearcat_client.get(registration_url)
302
+ # Inherited registrations can only be changed by their owning account
303
+ return yield unless registration[:lock_deploying] && !registration[:inherited]
304
+
305
+ bearcat_client.put(registration_url, { lock_deploying: false })
306
+ begin
307
+ yield
308
+ ensure
309
+ bearcat_client.put(registration_url, { lock_deploying: true })
310
+ end
311
+ end
312
+
284
313
  def _find_existing_installs(context, exists: nil, &matcher)
285
314
  ctype, cid = _parse_lti_context(context)
286
315
 
@@ -1,3 +1,3 @@
1
1
  module PandaPal
2
- VERSION = '5.19.0.beta2'
2
+ VERSION = '5.19.0.beta3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: panda_pal
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.19.0.beta2
4
+ version: 5.19.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Instructure CustomDev