From 4e92c567f73614f5da7d72c8b694004e176e881e Mon Sep 17 00:00:00 2001 From: Zia Fazal Date: Fri, 19 Jan 2024 16:31:26 +0500 Subject: [PATCH] fix: Add querystring to S3 signed url if it is present in the proxy request (#61) * fix: Add querystring to S3 signed url if it is present in the proxy request --- openedxscorm/scormxblock.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/openedxscorm/scormxblock.py b/openedxscorm/scormxblock.py index 958386e..57c8324 100644 --- a/openedxscorm/scormxblock.py +++ b/openedxscorm/scormxblock.py @@ -6,6 +6,7 @@ import xml.etree.ElementTree as ET import zipfile import mimetypes +import urllib from django.core.files.base import ContentFile from django.core.files.storage import default_storage @@ -13,7 +14,6 @@ from django.template import Context, Template from django.utils import timezone from django.utils.module_loading import import_string -import urllib.request from webob import Response import pkg_resources from six import string_types @@ -195,7 +195,7 @@ def author_view(self, context=None): def student_view(self, context=None): student_context = { - "index_page_url": self.index_page_url, + "index_page_url": urllib.parse.unquote(self.index_page_url), "completion_status": self.lesson_status, "grade": self.get_grade(), "can_view_student_reports": self.can_view_student_reports, @@ -240,6 +240,8 @@ def assets_proxy(self, request, suffix): """ file_name = os.path.basename(suffix) signed_url = self.storage.url(suffix) + if request.query_string: + signed_url = '&'.join([signed_url, request.query_string]) file_type, _ = mimetypes.guess_type(file_name) with urllib.request.urlopen(signed_url) as response: file_content = response.read() @@ -544,7 +546,7 @@ def update_package_fields(self): schemaversion = root.find( "{prefix}metadata/{prefix}schemaversion".format(prefix=prefix) ) - + self.extract_navigation_titles(root, prefix) if resource is not None: @@ -600,7 +602,9 @@ def find_titles_recursively(self, item, prefix, root): else: resource = root.find("{prefix}resources/{prefix}resource[@identifier='{identifier}']".format(prefix=prefix, identifier=item_identifier)) # Attach the storage path with the file path - resource_link = self.storage.url(os.path.join(self.extract_folder_path, resource.get("href"))) + resource_link = urllib.parse.unquote( + self.storage.url(os.path.join(self.extract_folder_path, resource.get("href"))) + ) if not children: return [(sanitized_title, resource_link)] child_titles = []