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: use usage_key instead of block_id as location identifier for scorm data #71

Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- [Bugfix] Prevent overwriting of exported course scorm data by imported course. (by @Danyal-Faheem)
- Use usage_key instead of block_id as the location identifier for scorm data as it is unique across course imports.
- This change will not take effect for previously created scorm modules.
17 changes: 17 additions & 0 deletions openedxscorm/scormxblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,23 @@ def extract_folder_path(self):
def extract_folder_base_path(self):
"""
Path to the folder where packages will be extracted.
Compute hash of the unique block usage_id and use that as our directory name.
"""
# For backwards compatibility, we return the old path if the directory exists
if self.storage.exists(self.extract_old_folder_base_path):
return self.extract_old_folder_base_path
sha1 = hashlib.sha1()
sha1.update(str(self.scope_ids.usage_id).encode())
hashed_usage_id = sha1.hexdigest()
return os.path.join(self.scorm_location(), hashed_usage_id)

@property
def extract_old_folder_base_path(self):
"""
Deprecated Path to the folder where packages will be extracted.
Deprecated as the block_id was shared by courses when exporting and importing
them, thus causing storage conflicts.
Only keeping this here for backwards compatibility.
"""
return os.path.join(self.scorm_location(), self.location.block_id)

Expand Down