diff --git a/CHANGELOG.md b/CHANGELOG.md index 8131c5a..f96aaba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Versioning](https://semver.org/spec/v2.0.0.html). ### Added - Accept Content-Item selection request used in a deep linking context +- Add an LTIMessageType enum ### Fixed diff --git a/src/lti_toolbox/launch_params.py b/src/lti_toolbox/launch_params.py index e325dac..b2334bb 100644 --- a/src/lti_toolbox/launch_params.py +++ b/src/lti_toolbox/launch_params.py @@ -4,13 +4,22 @@ This is based on lti library (https://github.com/pylti/lti). """ from collections.abc import MutableMapping +from enum import Enum from typing import List, Set, Union from urllib.parse import urlencode from .exceptions import InvalidParamException, MissingParamException DEFAULT_LTI_VERSION = "LTI-1.0" -SELECTION_PARAMS_MESSAGE_TYPE = "ContentItemSelectionRequest" + + +class LTIMessageType(Enum): + """Enum describing all type of message received through LTI requests.""" + + LAUNCH_REQUEST = "basic-lti-launch-request" + SELECTION_REQUEST = "ContentItemSelectionRequest" + SELECTION_RESPONSE = "ContentItemSelection" + LAUNCH_PARAMS_REQUIRED = {"lti_message_type", "lti_version", "resource_link_id"} diff --git a/src/lti_toolbox/lti.py b/src/lti_toolbox/lti.py index 944f6a2..8e9799c 100644 --- a/src/lti_toolbox/lti.py +++ b/src/lti_toolbox/lti.py @@ -6,12 +6,7 @@ from oauthlib.oauth1 import SignatureOnlyEndpoint from .exceptions import LTIException, LTIRequestNotVerifiedException, ParamException -from .launch_params import ( - SELECTION_PARAMS_MESSAGE_TYPE, - LaunchParams, - ParamsMixins, - SelectionParams, -) +from .launch_params import LaunchParams, LTIMessageType, ParamsMixins, SelectionParams from .models import LTIConsumer, LTIPassport from .validator import LTIRequestValidator @@ -37,8 +32,8 @@ def __init__(self, request): def _process_params(self) -> ParamsMixins: """Process LTI parameters based on request type.""" is_selection_request = ( - self.request.POST.get("lti_message_type") - == SELECTION_PARAMS_MESSAGE_TYPE + self.request.POST.get("lti_message_type") + == LTIMessageType.SELECTION_REQUEST.value ) try: params = ( diff --git a/tests/lti_toolbox/test_launch_params.py b/tests/lti_toolbox/test_launch_params.py index 8b60b0c..301dada 100644 --- a/tests/lti_toolbox/test_launch_params.py +++ b/tests/lti_toolbox/test_launch_params.py @@ -128,7 +128,6 @@ def test_invalid_parameter(self): ) - class SelectionParamTestCase(TestCase): """Test the SelectionParam class""" @@ -144,7 +143,7 @@ def _selection_params(lti_parameters): url = "http://testserver/lti/launch" signed_parameters = sign_parameters(passport, lti_parameters, url) return SelectionParams(signed_parameters) - + def test_only_required_parameters(self): """Test validation of a minimalistic LTI Content-Item Selection request with only required parameters.