From 19262993dff888471ab66428332183e9d476464f Mon Sep 17 00:00:00 2001 From: pkulkark <pooja@opencraft.com> Date: Fri, 6 Aug 2021 18:39:44 +0530 Subject: [PATCH] Fix: Add missing parameter processors code This Adds back the parameter processors code logic that was missed in a recent refactor. --- lti_consumer/lti_1p1/consumer.py | 15 +++++++++++++++ lti_consumer/lti_xblock.py | 10 ++++++++++ setup.py | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lti_consumer/lti_1p1/consumer.py b/lti_consumer/lti_1p1/consumer.py index 7341c61..5b2d16d 100644 --- a/lti_consumer/lti_1p1/consumer.py +++ b/lti_consumer/lti_1p1/consumer.py @@ -146,6 +146,9 @@ class LtiConsumer1p1: self.lti_launch_presentation_locale = None self.lti_custom_parameters = None + # Extra claims - used for custom parameter processors + self.extra_claims = {} + def set_user_data( self, user_id, @@ -241,6 +244,14 @@ class LtiConsumer1p1: self.lti_custom_parameters = custom_parameters + def set_extra_claims(self, claim): + """ + Updates launch extra claims using python's dict .update method + """ + if not isinstance(claim, dict): + raise ValueError('Invalid extra claim: {!r} is not a dict.'.format(claim)) + self.extra_claims.update(claim) + def generate_launch_request(self, resource_link_id): """ Signs LTI launch request and returns signature and OAuth parameters. @@ -288,6 +299,10 @@ class LtiConsumer1p1: if self.lti_custom_parameters: lti_parameters.update(self.lti_custom_parameters) + # Extra claims - from custom parameter processors + if self.extra_claims: + lti_parameters.update(self.extra_claims) + headers = { # This is needed for body encoding: 'Content-Type': 'application/x-www-form-urlencoded', diff --git a/lti_consumer/lti_xblock.py b/lti_consumer/lti_xblock.py index 42e1d5a..6d6cd54 100644 --- a/lti_consumer/lti_xblock.py +++ b/lti_consumer/lti_xblock.py @@ -1009,6 +1009,16 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock): lti_consumer.set_custom_parameters(self.prefixed_custom_parameters) + for processor in self.get_parameter_processors(): + try: + default_params = getattr(processor, 'lti_xblock_default_params', {}) + lti_consumer.set_extra_claims(default_params) + lti_consumer.set_extra_claims(processor(self) or {}) + except Exception: # pylint: disable=broad-except + # Log the error without causing a 500-error. + # Useful for catching casual runtime errors in the processors. + log.exception('Error in XBlock LTI parameter processor "%s"', processor) + lti_parameters = lti_consumer.generate_launch_request(self.resource_link_id) loader = ResourceLoader(__name__) context = self._get_context_for_template() diff --git a/setup.py b/setup.py index 9a0e759..6114e2d 100644 --- a/setup.py +++ b/setup.py @@ -49,7 +49,7 @@ with open('README.rst') as _f: setup( name='lti-consumer-xblock', - version='3.0.2', + version='3.0.3', author='Open edX project', author_email='oscm@edx.org', description='This XBlock implements the consumer side of the LTI specification.', -- GitLab