diff --git a/lms/services/assignment.py b/lms/services/assignment.py index 856752e359..47a83f0351 100644 --- a/lms/services/assignment.py +++ b/lms/services/assignment.py @@ -163,6 +163,11 @@ def get_assignment_for_launch(self, request, course: Course) -> Assignment | Non ) ) + # Set the value for the v13 id for this assignment. + assignment.lti_v13_resource_link_id = request.lti_params.v13.get( + "https://purl.imsglobal.org/spec/lti/claim/resource_link", {} + ).get("id") + # Always update the assignment configuration # It often will be the same one while launching the assignment again but # it might for example be an updated deep linked URL or similar. diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index f1411ddc08..c3b82f14d7 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -145,6 +145,14 @@ def pyramid_request(db_session, application_instance, lti_v11_params): return pyramid_request +@pytest.fixture +def lti_v13_pyramid_request(pyramid_request, lti_v13_params, lti_v11_params): + pyramid_request.lti_jwt = "JWT" + pyramid_request.lti_params = LTIParams(v11=lti_v11_params, v13=lti_v13_params) + + return pyramid_request + + @pytest.fixture def product(pyramid_request): return pyramid_request.product diff --git a/tests/unit/lms/services/assignment_test.py b/tests/unit/lms/services/assignment_test.py index 2c673df0c1..cdc9e139cf 100644 --- a/tests/unit/lms/services/assignment_test.py +++ b/tests/unit/lms/services/assignment_test.py @@ -128,6 +128,17 @@ def test_get_assignment_for_launch_existing( ) assert assignment.is_gradable == misc_plugin.is_assignment_gradable.return_value assert assignment.course_id == course.id + assert ( + assignment.lti_v13_resource_link_id + == pyramid_request.lti_params.v13.get("") + ) + + def test_get_assignment_for_launch_set_v13_context_id( + self, lti_v13_pyramid_request, svc, course + ): + assignment = svc.get_assignment_for_launch(lti_v13_pyramid_request, course) + + assert assignment.lti_v13_resource_link_id == "RESOURCE_LINK_ID" def test_get_assignment_returns_None_with_when_no_document( self, pyramid_request, svc, misc_plugin, course