-
Notifications
You must be signed in to change notification settings - Fork 31
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
Feature/rationalise file name #1127
Conversation
aa666ee
to
efae1ac
Compare
) | ||
|
||
def update_status_from_core(self, status_label): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused
except ValueError as e: | ||
logger.exception("attempt to access non-existent file %s", self.pk, exc_info=e) | ||
def file_name(self) -> str: | ||
if self.original_file_name: # delete me? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for backwards compatability
original_file = models.FileField(storage=settings.STORAGES["default"]["BACKEND"]) | ||
original_file = models.FileField( | ||
storage=settings.STORAGES["default"]["BACKEND"], | ||
upload_to=build_s3_key, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this upload_to
is the key change
@@ -64,29 +64,42 @@ def test_document_upload_status(client, alice, file_pdf_path: Path, s3_client): | |||
|
|||
@pytest.mark.django_db() | |||
def test_upload_view_duplicate_files(alice, bob, client, file_pdf_path: Path, s3_client): | |||
# delete all alice's files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test has been changed significantly to capture the new intended behaviour
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one query about displaying the file name and whether we want to display the s3 path version in the frontend
@@ -307,10 +307,10 @@ async def handle_citations(self, citations: list[AICitation]): | |||
for s in c.sources: | |||
try: | |||
file = await File.objects.aget(original_file=s.source) | |||
payload = {"url": str(file.url), "original_file_name": file.original_file_name} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we still want to use original_file_name here so we see 'stuff.pdf' in the frontend rather than 'me@cabinetoffice/stuff.pdf'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
file_name
will strip out me@cabinetoffice/
and just return stuff.pdf
TBH i was hoping that we could just delete original_file_name
altogether in 30 days (this PR means that its no longer getting populated)
Context
The file-name is especially significant and problematic as it has to be both human readable, and globally unique.
Currently we handle this via:
original_file_name
field to store the name of the file as the user uploaded itunique_name
,name
I propose that we dont actually need a file name to be globally unique, we want it to be unique per user, so that:
to achieve this we should change the file name to user.email/file_name, this will have to convenient side effect of presenting the files in directories named after the user within s3.
Changes proposed in this pull request
orginal_file_name
-> now unused but kept for backwards compatibilityname
->file_name
, the original file name - for the benefit of the userGuidance to review
do we actually want this behaviour?
Relevant links
Things to check