Skip to content

Commit 2e3e410

Browse files
committed
🐛(back) fix document filename handling for documents stored on AWS
The document serializer was not properly updated in the previous PR. When serving legacy Marsha documents that were stored on AWS (now migrated to Scaleway), the filename was still computed from playlist and document titles. It should instead use the newly added filename field. Fixing that behavior.
1 parent c32d32e commit 2e3e410

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Versioning](https://semver.org/spec/v2.0.0.html).
88

99
## [Unreleased]
1010

11+
### Fixed
12+
13+
- Fix filename handling for legacy documents
14+
1115
## [5.11.0] - 2025-07-17
1216

1317
### Changed

src/backend/marsha/core/serializers/file.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,7 @@ def get_filename(self, obj):
8787
The document's filename
8888
8989
"""
90-
if obj.storage_location == SCW_S3:
91-
return obj.filename
92-
93-
return self._get_filename(obj.title, obj.extension, obj.playlist.title)
90+
return obj.filename
9491

9592
def get_url(self, obj):
9693
"""Url of the Document.

src/backend/marsha/core/tests/test_api_document.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def test_api_document_fetch_instructor_on_aws(self):
6363
pk="4c51f469-f91e-4998-b438-e31ee3bd3ea6",
6464
uploaded_on=datetime(2018, 8, 8, tzinfo=baseTimezone.utc),
6565
upload_state="ready",
66+
filename="bar_baz.pdf",
6667
extension="pdf",
6768
playlist__title="foo",
6869
playlist__lti_id="course-v1:ufr+mathematics+00001",
@@ -83,13 +84,13 @@ def test_api_document_fetch_instructor_on_aws(self):
8384
{
8485
"active_stamp": "1533686400",
8586
"extension": "pdf",
86-
"filename": "foo_bar-baz.pdf",
87+
"filename": "bar_baz.pdf",
8788
"id": str(document.id),
8889
"is_ready_to_show": True,
8990
"title": document.title,
9091
"upload_state": "ready",
9192
"url": "https://abc.svc.edge.scw.cloud/aws/4c51f469-f91e-4998-b438-e31ee3bd3ea6/"
92-
"document/foo_bar-baz.pdf",
93+
"document/bar_baz.pdf",
9394
"show_download": True,
9495
"playlist": {
9596
"id": str(document.playlist.id),

src/backend/marsha/core/tests/views/test_public_document.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def test_document_publicly_accessible_on_aws(self):
3737
playlist__consumer_site__domain="trusted_domain.com",
3838
is_public=True,
3939
title="document-001",
40+
filename="document-001.pdf",
4041
upload_state=random.choice([s[0] for s in STATE_CHOICES]),
4142
uploaded_on="2019-09-24 07:24:40+00",
4243
storage_location=AWS_S3,
@@ -79,15 +80,15 @@ def test_document_publicly_accessible_on_aws(self):
7980
"upload_state": document.upload_state,
8081
"title": document.title,
8182
"extension": None,
82-
"filename": "playlist-003_document-001",
83+
"filename": "document-001.pdf",
8384
"playlist": {
8485
"id": str(document.playlist.id),
8586
"title": "playlist-003",
8687
"lti_id": "course-v1:ufr+mathematics+00001",
8788
},
8889
"url": (
8990
"https://abc.svc.edge.scw.cloud/aws/301b5f4f-b9f1-4a5f-897d-f8f1bf22c396"
90-
"/document/playlist-003_document-001"
91+
"/document/document-001.pdf"
9192
),
9293
},
9394
)
@@ -206,6 +207,7 @@ def test_public_document_without_consumer_site(self):
206207
playlist=playlist,
207208
is_public=True,
208209
title="document-001",
210+
filename="document-001.pdf",
209211
upload_state=random.choice([s[0] for s in STATE_CHOICES]),
210212
uploaded_on="2019-09-24 07:24:40+00",
211213
storage_location=AWS_S3,
@@ -243,15 +245,15 @@ def test_public_document_without_consumer_site(self):
243245
"upload_state": document.upload_state,
244246
"title": document.title,
245247
"extension": None,
246-
"filename": "playlist-003_document-001",
248+
"filename": "document-001.pdf",
247249
"playlist": {
248250
"id": str(document.playlist.pk),
249251
"title": "playlist-003",
250252
"lti_id": None,
251253
},
252254
"url": (
253255
f"https://abc.svc.edge.scw.cloud/aws/{document.pk}"
254-
"/document/playlist-003_document-001"
256+
"/document/document-001.pdf"
255257
),
256258
},
257259
)

src/backend/marsha/development/api.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from marsha.bbb.models import ClassroomDocument
1313
from marsha.core.defaults import TMP_STORAGE_BASE_DIRECTORY
1414
from marsha.core.models import Document, Video
15-
from marsha.core.serializers.file import DocumentSerializer
1615
from marsha.core.storage.storage_class import file_storage
1716
from marsha.core.utils import time_utils
1817
from marsha.deposit.models import DepositedFile
@@ -83,8 +82,7 @@ def local_document_upload(request: HttpRequest, uuid=None):
8382
except Document.DoesNotExist:
8483
return Response({"success": False}, status=404)
8584

86-
filename = DocumentSerializer().get_filename(document)
87-
destination = document.get_storage_key(filename=filename)
85+
destination = document.get_storage_key(filename=document.filename)
8886

8987
file_storage.save(destination, uploaded_document)
9088
return Response(status=204)

0 commit comments

Comments
 (0)