Skip to content

Commit 2db7399

Browse files
committed
Revert "refactor: remove save_xblock helper"
This reverts commit 8e5b926.
1 parent fac60e2 commit 2db7399

4 files changed

Lines changed: 26 additions & 2 deletions

File tree

lti_consumer/api.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,16 @@ def _ensure_lti_passport(block, lti_config):
7676
)
7777

7878
if key_mismatch:
79+
from lti_consumer.plugin.compat import save_xblock # pylint: disable=import-outside-toplevel
7980
passport = Lti1p3Passport.objects.create(
8081
lti_1p3_tool_public_key=block_public_key,
8182
lti_1p3_tool_keyset_url=block_keyset_url,
8283
name=f"Passport of {block.display_name}",
8384
context_key=block.context_id,
8485
)
86+
# Persist new passport link on block so future loads use split passport.
87+
block.lti_1p3_passport_id = str(passport.passport_id)
88+
save_xblock(block)
8589
log.info("Created new LTI passport for %s", block.scope_ids.usage_id)
8690

8791
return passport

lti_consumer/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,9 @@ def get_or_create_lti_1p3_passport(self):
429429
passport.name = f"Passport of {block.display_name}"
430430
passport.context_key = block.context_id
431431
passport.save()
432+
block.lti_1p3_passport_id = str(passport.passport_id)
433+
block.save()
434+
compat.save_xblock(block)
432435
# We use update to avoid triggering post save signal as this function is itself
433436
# called from the post_save signal handler, this avoids double call to same function.
434437
LtiConfiguration.objects.filter(pk=self.pk).update(lti_1p3_passport=passport)

lti_consumer/plugin/compat.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,23 @@ def load_enough_xblock(location: UsageKey): # pragma: nocover
117117
return xblock_api.load_block(location, None)
118118

119119

120+
def save_xblock(block): # pragma: nocover
121+
"""
122+
Save xblock in modulestore or contentstore.
123+
"""
124+
# pylint: disable=import-error,import-outside-toplevel
125+
from openedx.core.djangoapps.xblock import api as xblock_api
126+
from xmodule.modulestore.django import modulestore
127+
128+
# Save course block using modulestore
129+
if isinstance(block.scope_ids.usage_id.context_key, CourseKey):
130+
return modulestore().update_item(block, None)
131+
# Save library block using the XBlock API
132+
else:
133+
runtime = xblock_api.get_runtime(None)
134+
return runtime.save_block(block)
135+
136+
120137
def load_block_as_user(location): # pragma: nocover
121138
"""
122139
Load a block as the current user, or load as the anonymous user if no user is available.

lti_consumer/plugin/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def public_keyset_endpoint(
138138
lti_passport = Lti1p3Passport.objects.get(passport_id=passport_id)
139139
public_jwk = lti_passport.lti_1p3_public_jwk
140140
# TODO: move version inside passport from config
141-
# We just need any lti_config that is using this passport to check version
141+
# We just need any any lti_config that is using this passport to check version
142142
lti_config = LtiConfiguration.objects.filter(lti_1p3_passport=lti_passport).first()
143143
version = lti_config.version
144144
elif external_app and external_slug:
@@ -457,7 +457,7 @@ def access_token_endpoint(
457457
elif passport_id:
458458
lti_passport = Lti1p3Passport.objects.get(passport_id=passport_id)
459459
# TODO: move version inside passport from config
460-
# We just need any lti_config that is using this passport to check version
460+
# We just need any any lti_config that is using this passport to check version
461461
lti_config = LtiConfiguration.objects.filter(lti_1p3_passport=lti_passport).first()
462462
version = lti_config.version
463463
lti_consumer = LtiConsumer1p3(

0 commit comments

Comments
 (0)