Skip to content

Commit

Permalink
fix: Add querystring to S3 signed url if it is present in the proxy r…
Browse files Browse the repository at this point in the history
…equest (#61)

* fix: Add querystring to S3 signed url if it is present in the proxy request
  • Loading branch information
ziafazal authored Jan 19, 2024
1 parent 14ad20a commit 4e92c56
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions openedxscorm/scormxblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
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
from django.db.models import Q
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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 = []
Expand Down

0 comments on commit 4e92c56

Please sign in to comment.