Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add querystring to S3 signed url if it is present in the proxy request #61

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
Copy link
Contributor

@Danyal-Faheem Danyal-Faheem Jan 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also pass our navigation_title links through urllib.parse.unquote as well as tagged below.

resource_link = self.storage.url(os.path.join(self.extract_folder_path, resource.get("href")))

We should change it to something like:
resource_link = urllib.parse.unquote(self.storage.url(os.path.join(self.extract_folder_path, resource.get("href"))))

"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