feat: Allow adding custom LTI parameters via LTI_CUSTOM_PARAMS django setting
Adds a new Django setting called `LTI_CUSTOM_PARAMS` that allows extending the list of optional LTI parameters processed by the platform. These parameters can be used by plugins for deeper platform integration.
This commit is contained in:
committed by
Farhaan Bukhsh
parent
c5f0f09d79
commit
ba6026f999
@@ -1,13 +1,12 @@
|
||||
"""
|
||||
Tests for the LTI provider views
|
||||
"""
|
||||
|
||||
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.test import TestCase
|
||||
from django.test.client import RequestFactory
|
||||
from django.test.utils import override_settings
|
||||
from django.urls import reverse
|
||||
from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator
|
||||
from openedx_events.learning.data import UserData, UserPersonalData, LtiProviderLaunchData, LtiProviderLaunchParamsData
|
||||
@@ -143,6 +142,23 @@ class LtiLaunchTest(LtiTestMixin, TestCase):
|
||||
self.consumer
|
||||
)
|
||||
|
||||
@patch('lms.djangoapps.lti_provider.views.render_courseware')
|
||||
@patch('lms.djangoapps.lti_provider.views.store_outcome_parameters')
|
||||
@patch('lms.djangoapps.lti_provider.views.authenticate_lti_user')
|
||||
@override_settings(LTI_CUSTOM_PARAMS=["extra_param1", "extra_param2"])
|
||||
def test_valid_launch_with_extra_params(self, _authenticate, store_params, _render):
|
||||
"""
|
||||
Verifies that the LTI launch succeeds when passed a valid request.
|
||||
"""
|
||||
extra_params = {'extra_param1': 'extra_value1', 'extra_param2': "extra_value2"}
|
||||
request = build_launch_request(extra_post_data=LTI_OPTIONAL_PARAMS | extra_params)
|
||||
views.lti_launch(request, str(COURSE_KEY), str(USAGE_KEY))
|
||||
store_params.assert_called_with(
|
||||
dict(list(ALL_PARAMS.items()) + list(LTI_OPTIONAL_PARAMS.items()) + list(extra_params.items())),
|
||||
request.user,
|
||||
self.consumer
|
||||
)
|
||||
|
||||
@patch('lms.djangoapps.courseware.views.views.render_xblock')
|
||||
@patch('lms.djangoapps.lti_provider.views.authenticate_lti_user')
|
||||
def test_render_xblock_params(self, _authenticate, render):
|
||||
|
||||
@@ -20,6 +20,7 @@ from lms.djangoapps.lti_provider.models import LtiConsumer
|
||||
from lms.djangoapps.lti_provider.outcomes import store_outcome_parameters
|
||||
from lms.djangoapps.lti_provider.signature_validator import SignatureValidator
|
||||
from lms.djangoapps.lti_provider.users import authenticate_lti_user
|
||||
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
|
||||
from openedx.core.lib.url_utils import unquote_slashes
|
||||
|
||||
log = logging.getLogger("edx.lti_provider")
|
||||
@@ -61,6 +62,7 @@ def lti_launch(request, course_id, usage_id):
|
||||
if not params:
|
||||
return HttpResponseBadRequest()
|
||||
params.update(get_optional_parameters(request.POST))
|
||||
params.update(get_custom_parameters(request.POST))
|
||||
|
||||
# Get the consumer information from either the instance GUID or the consumer
|
||||
# key
|
||||
@@ -175,6 +177,22 @@ def get_optional_parameters(dictionary):
|
||||
return {key: dictionary[key] for key in OPTIONAL_PARAMETERS if key in dictionary}
|
||||
|
||||
|
||||
def get_custom_parameters(params: dict[str]) -> dict[str]:
|
||||
"""
|
||||
Extract all optional LTI parameters from a dictionary. This method does not
|
||||
fail if any parameters are missing.
|
||||
|
||||
:param params: A dictionary containing zero or more parameters.
|
||||
:return: A new dictionary containing all optional parameters from the
|
||||
original dictionary, or an empty dictionary if no optional parameters
|
||||
were present.
|
||||
"""
|
||||
custom_params = configuration_helpers.get_value("LTI_CUSTOM_PARAMS", settings.LTI_CUSTOM_PARAMS)
|
||||
if not custom_params:
|
||||
return {}
|
||||
return {key: params[key] for key in custom_params if key in params}
|
||||
|
||||
|
||||
def render_courseware(request, usage_key):
|
||||
"""
|
||||
Render the content requested for the LTI launch.
|
||||
|
||||
@@ -3984,6 +3984,16 @@ LTI_USER_EMAIL_DOMAIN = 'lti.example.com'
|
||||
# The time value is in seconds.
|
||||
LTI_AGGREGATE_SCORE_PASSBACK_DELAY = 15 * 60
|
||||
|
||||
|
||||
# .. setting_name: LTI_CUSTOM_PARAMS
|
||||
# .. setting_default: []
|
||||
# .. setting_description: This expands the list of optional LTI parameters that the
|
||||
# platform accepts. These parameters are not used by the platform, but can then
|
||||
# be used by other plugins.
|
||||
# .. setting_creation_date: 2025-08-22
|
||||
# .. setting_tickets:
|
||||
LTI_CUSTOM_PARAMS = []
|
||||
|
||||
# Credit notifications settings
|
||||
NOTIFICATION_EMAIL_CSS = "templates/credit_notifications/credit_notification.css"
|
||||
NOTIFICATION_EMAIL_EDX_LOGO = "templates/credit_notifications/edx-logo-header.png"
|
||||
|
||||
Reference in New Issue
Block a user