diff --git a/lms/views/lti/deep_linking.py b/lms/views/lti/deep_linking.py index dcf1e1588f..fe377af37b 100644 --- a/lms/views/lti/deep_linking.py +++ b/lms/views/lti/deep_linking.py @@ -42,6 +42,7 @@ import uuid from datetime import datetime, timedelta +from marshmallow import Schema, validate from pyramid.view import view_config, view_defaults from webargs import fields @@ -85,12 +86,32 @@ def deep_linking_launch(context, request): return {} +class _AutoGradingConfig(Schema): + grading_type = fields.Str( + required=True, validate=validate.OneOf(["all_or_nothing", "scaled"]) + ) + activity_calculation = fields.Str( + required=True, validate=validate.OneOf(["cumulative", "separately"]) + ) + + required_annotations = fields.Int( + required=False, allow_none=True, validate=validate.Range(min=0) + ) + required_replies = fields.Int( + required=False, allow_none=True, validate=validate.Range(min=0) + ) + + class DeepLinkingFieldsRequestSchema(JSONPyramidRequestSchema): content_item_return_url = fields.Str(required=True) content = fields.Dict(required=True) group_set = fields.Str(required=False, allow_none=True) title = fields.Str(required=False, allow_none=True) + auto_grading_config = fields.Nested( + _AutoGradingConfig, required=False, allow_none=True + ) + class LTI11DeepLinkingFieldsRequestSchema(DeepLinkingFieldsRequestSchema): opaque_data_lti11 = fields.Str(required=False, allow_none=True) @@ -254,6 +275,10 @@ def _get_assignment_configuration(request) -> dict: if title := request.parsed_params.get("title"): params["title"] = title + if auto_grading_config := request.parsed_params.get("auto_grading_config"): + # Custom params must be str, encode these settings as JSON + params["auto_grading_config"] = json.dumps(auto_grading_config) + if content["type"] == "url": params["url"] = content["url"] else: diff --git a/tests/unit/lms/views/lti/deep_linking_test.py b/tests/unit/lms/views/lti/deep_linking_test.py index eb1e1bc380..42e6b651f1 100644 --- a/tests/unit/lms/views/lti/deep_linking_test.py +++ b/tests/unit/lms/views/lti/deep_linking_test.py @@ -211,6 +211,10 @@ def test_it_for_v11( {"group_set": "1", "title": "title"}, {"group_set": "1", "title": "title"}, ), + ( + {"auto_grading_config": {"key": "value"}}, + {"auto_grading_config": '{"key": "value"}'}, + ), ], ) def test_get_assignment_configuration(