Skip to content

Commit

Permalink
fix: use usage_key instead of block_id as location identifier for sco…
Browse files Browse the repository at this point in the history
…rm data (#71)

* fix: use usage_key instead of block_id as location identifier
This is because block_id is maintained across course export/import
Both the courses try to access the same data on storage
Manipulating data in one course will overwrite the data for the other one, breaking it
  • Loading branch information
Danyal-Faheem committed Apr 23, 2024
1 parent 7fd248a commit 6401bba
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
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

0 comments on commit 6401bba

Please sign in to comment.