From 5842845dd5797bcfc31bf26216a6b46e849f51a8 Mon Sep 17 00:00:00 2001
From: Geoff <ge.off.von@gmail.com>
Date: Thu, 31 Mar 2022 13:03:41 -0700
Subject: [PATCH] fix: Fix LTI 1.3 launch templates rendering (#238)

* Use render_django_template for lti 1p3 launch errs
* Test % trans not found in lti 1p3 err templates
* Bump version to 3.4.6; Update ChangeLog
---
 README.rst                                 | 5 +++++
 lti_consumer/__init__.py                   | 2 +-
 lti_consumer/lti_xblock.py                 | 4 ++--
 lti_consumer/tests/unit/test_lti_xblock.py | 4 ++++
 4 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/README.rst b/README.rst
index 893f9e2..ee17c40 100644
--- a/README.rst
+++ b/README.rst
@@ -369,6 +369,11 @@ Changelog
 
 Please See the [releases tab](https://github.com/edx/xblock-lti-consumer/releases) for the complete changelog.
 
+3.4.6 - 2022-03-31
+------------------
+
+* Fix rendering of `lti_1p3_launch_error.html` and `lti_1p3_permission_error.html` templates
+
 3.4.5 - 2022-03-16
 ------------------
 
diff --git a/lti_consumer/__init__.py b/lti_consumer/__init__.py
index 4b73aa0..e78f3ae 100644
--- a/lti_consumer/__init__.py
+++ b/lti_consumer/__init__.py
@@ -4,4 +4,4 @@ Runtime will load the XBlock class from here.
 from .apps import LTIConsumerApp
 from .lti_xblock import LtiConsumerXBlock
 
-__version__ = '3.4.5'
+__version__ = '3.4.6'
diff --git a/lti_consumer/lti_xblock.py b/lti_consumer/lti_xblock.py
index e0ab9a0..336df6e 100644
--- a/lti_consumer/lti_xblock.py
+++ b/lti_consumer/lti_xblock.py
@@ -1166,7 +1166,7 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock):
                 str(self.location),  # pylint: disable=no-member
                 exc,
             )
-            template = loader.render_mako_template('/templates/html/lti_1p3_launch_error.html', context)
+            template = loader.render_django_template('/templates/html/lti_1p3_launch_error.html', context)
             return Response(template, status=400, content_type='text/html')
         except AssertionError as exc:
             log.warning(
@@ -1175,7 +1175,7 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock):
                 self.external_user_id,
                 exc,
             )
-            template = loader.render_mako_template('/templates/html/lti_1p3_permission_error.html', context)
+            template = loader.render_django_template('/templates/html/lti_1p3_permission_error.html', context)
             return Response(template, status=403, content_type='text/html')
 
     @XBlock.handler
diff --git a/lti_consumer/tests/unit/test_lti_xblock.py b/lti_consumer/tests/unit/test_lti_xblock.py
index 390438d..fbada04 100644
--- a/lti_consumer/tests/unit/test_lti_xblock.py
+++ b/lti_consumer/tests/unit/test_lti_xblock.py
@@ -1293,6 +1293,7 @@ class TestLtiConsumer1p3XBlock(TestCase):
 
         response_body = response.body.decode('utf-8')
         self.assertIn("There was an error while launching the LTI 1.3 tool.", response_body)
+        self.assertNotIn("% trans", response_body)
 
     def test_launch_callback_endpoint_when_using_lti_1p1(self):
         """
@@ -1397,6 +1398,9 @@ class TestLtiConsumer1p3XBlock(TestCase):
 
         # Check response
         self.assertEqual(response.status_code, 403)
+        response_body = response.body.decode('utf-8')
+        self.assertIn("Students don't have permissions to perform", response_body)
+        self.assertNotIn("% trans", response_body)
 
     @patch('lti_consumer.api.get_deep_linking_data')
     def test_callback_endpoint_dl_content_launch(self, mock_dl_data):
-- 
GitLab