-
Notifications
You must be signed in to change notification settings - Fork 95
feat: LTI 1.3 Passport Refactor + Database Cleanup Support #627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
navinkarkera
wants to merge
17
commits into
openedx:master
Choose a base branch
from
open-craft:navin/fal-4318/split-config
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0692de5
feat(models): split LTI 1.3 configuration into separate Passport model
navinkarkera a0955d3
feat(lti): add signal handlers for LTI configuration deletion
navinkarkera f9cb60e
fix(lti): correct spelling and improve logging in signal handlers
navinkarkera 45ce7ac
fix: lint issues
navinkarkera 2280f94
feat: install openedx-events
navinkarkera 4f1be85
fix: model label
navinkarkera d1560d3
fix: handle no location
navinkarkera bbed967
test: fix tests
navinkarkera 7becfcb
fix: lint issues
navinkarkera f28c502
fixup! fix: lint issues
navinkarkera b7c06db
test: add signal tests
navinkarkera 9cc408d
fix: coverage
navinkarkera b5203b0
refactor(models): rename create_lti_1p3_passport to get_or_create_lti…
navinkarkera 1128e48
fix: copy-paste bug when both public key and keyset url is specified
navinkarkera d790df8
fix: lint issues
navinkarkera 0456b57
test: improve coverage
navinkarkera fde2f3d
refactor(views): remove unnecessary db call
navinkarkera File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,5 @@ | |
| [run] | ||
| data_file = .coverage | ||
| source = lti_consumer | ||
| omit = */urls.py | ||
| omit = | ||
| */urls.py | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
lti_consumer/migrations/0020_lti1p3passport_lticonfiguration_lti_1p3_passport.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # Generated by Django 5.2.12 on 2026-03-17 14:56 | ||
|
|
||
| import uuid | ||
|
|
||
| import django.db.models.deletion | ||
| from django.db import migrations, models | ||
|
|
||
| import lti_consumer.models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ('lti_consumer', '0019_mariadb_uuid_conversion'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name='Lti1p3Passport', | ||
| fields=[ | ||
| ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
| ('passport_id', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)), | ||
| ( | ||
| 'lti_1p3_internal_private_key', | ||
| models.TextField(blank=True, help_text="Platform's generated Private key. Keep this value secret."), | ||
| ), | ||
| ( | ||
| 'lti_1p3_internal_private_key_id', | ||
| models.CharField(blank=True, help_text="Platform's generated Private key ID", max_length=255), | ||
| ), | ||
| ( | ||
| 'lti_1p3_internal_public_jwk', | ||
| models.TextField(blank=True, help_text="Platform's generated JWK keyset."), | ||
| ), | ||
| ( | ||
| 'lti_1p3_client_id', | ||
| models.CharField( | ||
| default=lti_consumer.models.generate_client_id, | ||
| help_text='Client ID used by LTI tool', | ||
| max_length=255, | ||
| ), | ||
| ), | ||
| ( | ||
| 'lti_1p3_tool_public_key', | ||
| models.TextField( | ||
| blank=True, | ||
| help_text="This is the LTI Tool's public key. This should be provided by the LTI Tool. One of either lti_1p3_tool_public_key or lti_1p3_tool_keyset_url must not be blank.", | ||
| verbose_name='LTI 1.3 Tool Public Key', | ||
| ), | ||
| ), | ||
| ( | ||
| 'lti_1p3_tool_keyset_url', | ||
| models.CharField( | ||
| blank=True, | ||
| help_text="This is the LTI Tool's JWK (JSON Web Key) Keyset (JWKS) URL. This should be provided by the LTI Tool. One of either lti_1p3_tool_public_key or lti_1p3_tool_keyset_url must not be blank.", | ||
| max_length=255, | ||
| verbose_name='LTI 1.3 Tool Keyset URL', | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| migrations.AddField( | ||
| model_name='lticonfiguration', | ||
| name='lti_1p3_passport', | ||
| field=models.ForeignKey( | ||
| blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='lti_consumer.lti1p3passport' | ||
| ), | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # Generated migration for copying config_id into modulestore from database (Django 6.2) | ||
| """ | ||
| This migration will copy config_id from LtiConsumer database to LtiConsumerXBlock. | ||
|
|
||
| This will help us link xblocks with LtiConsumer database rows without relying on the location or usage_key of xblocks. | ||
| """ | ||
| from django.db import migrations | ||
|
|
||
|
|
||
| def create_lti_1p3_passport(apps, _): # pragma: nocover | ||
| """Copy config_id from LtiConsumer to LtiConsumerXBlock.""" | ||
| from lti_consumer.plugin.compat import load_enough_xblock, save_xblock # pylint: disable=import-outside-toplevel | ||
| from lti_consumer.utils import model_to_dict # pylint: disable=import-outside-toplevel | ||
|
|
||
| LtiConfiguration = apps.get_model("lti_consumer", "LtiConfiguration") | ||
| Lti1p3Passport = apps.get_model("lti_consumer", "Lti1p3Passport") | ||
|
|
||
| for configuration in LtiConfiguration.objects.all(): | ||
| try: | ||
| block = load_enough_xblock(configuration.location) | ||
| block.lti_1p3_passport_id = str(configuration.config_id) | ||
| block.save() | ||
| save_xblock(block) | ||
| except Exception as e: # pylint: disable=broad-exception-caught | ||
| print(f"Failed to copy passport_id for configuration {configuration}: {e}") | ||
| values = model_to_dict( | ||
| configuration, | ||
| include=[ | ||
| 'lti_1p3_internal_private_key', | ||
| 'lti_1p3_internal_private_key_id', | ||
| 'lti_1p3_internal_public_jwk', | ||
| 'lti_1p3_client_id', | ||
| 'lti_1p3_tool_public_key', | ||
| 'lti_1p3_tool_keyset_url', | ||
| ], | ||
| ) | ||
| if block.config_type == "new": | ||
| # Data is stored xblock | ||
| values.update({ | ||
| 'lti_1p3_tool_public_key': block.lti_1p3_tool_public_key, | ||
| 'lti_1p3_tool_keyset_url': block.lti_1p3_tool_keyset_url, | ||
| }) | ||
| passport, _ = Lti1p3Passport.objects.update_or_create( | ||
| # Use config_id as passport_id to preserve existing urls that use it. | ||
| passport_id=configuration.config_id, | ||
| defaults=values, | ||
| ) | ||
| configuration.lti_1p3_passport = passport | ||
| configuration.save() | ||
|
|
||
|
|
||
| def backwards(*_): | ||
| """Reverse the migration only for MariaDB databases.""" | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('lti_consumer', '0020_lti1p3passport_lticonfiguration_lti_1p3_passport'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RunPython( | ||
| code=create_lti_1p3_passport, | ||
| reverse_code=backwards, | ||
| ), | ||
| ] | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be the
lti_1p3_passport.id? Should we also need to add a field for theLtiConfigurationto the block?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use
config_idaspassport_idin migration as we want the existing blocks to work without requiring any change in the LTI tool configuration. After this PR,passport_idis included in the access_token and keyset urls instead of config_id.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, gotcha, makes sense.