Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

api/rest.py: Add URLs to access attachments #1108

Merged
merged 1 commit into from
Nov 6, 2023

Conversation

katieworton
Copy link
Member

@katieworton katieworton commented Oct 30, 2023

WIP draft of support for accessing attachments. Adds an AttachmentViewSet so a hyperlink can be created.

Work in progress as I have not yet figured out how to combine the url and the filename to create a clickable link directly to the file.

@katieworton
Copy link
Member Author

Noticed there were some issues with the previously pushed version of this code, so have changed approach. As a temporary solution, I have added an extra field which builds the url for accessing attachments. This successfully fulfils the requirement of adding a downloadable link, but doesn't look like the cleanest solution when compared to how other file downloads are handled in the code. I will explore more to see if there is a cleaner approach.

@katieworton katieworton changed the title api/rest.py,core/models.py: support for attachement access api/rest.py: support for attachement access Nov 2, 2023
squad/api/rest.py Outdated Show resolved Hide resolved
@katieworton
Copy link
Member Author

katieworton commented Nov 3, 2023

@chaws I've added a test case to check the download url works & updated the previous attachments test case to include the download url - let me know if this looks ok or if any other changes would be required.
edit: originally also added the migrations files that were generated but realised that these are no longer needed as I removed the model change that required the migration.

class Meta:
model = Attachment
fields = ('filename', 'mimetype', 'length')
fields = ('download_url', 'filename', 'mimetype', 'length')
Copy link
Contributor

Choose a reason for hiding this comment

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

do we really need the 'filename' field here, that is in the download_url now or?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well, it wouldn't hurt I think it's fine IMHO

@katieworton katieworton changed the title api/rest.py: support for attachement access api/rest.py: Add URLs to access attachments Nov 6, 2023
Attachments can be accessed via testruns, by adding
"attachments?filename=<filename>" to the end of the testrun URL.
However, this is quite unintuitive and prone to user error.

Add a "download_url" field to attachments, which creates a download URL
in each file's entry in the attachments list.

Signed-off-by: Katie Worton <[email protected]>
filename = 'foo.txt'
attachment = self.test_run.attachments.create(filename=filename, length=len(data), mimetype="text/plain")
attachment.save_file(filename, data)
# NOTE: /api/testruns/%s/attachments?filename=foo.txt redirects to /api/testruns/%s/attachments/?filename=foo.txt
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good catch!

@chaws
Copy link
Collaborator

chaws commented Nov 6, 2023

LGTM! I'll merge it and make 1.76.1 release so you can use it in your squad-client patch

Copy link
Collaborator

@chaws chaws left a comment

Choose a reason for hiding this comment

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

LGTM

@chaws chaws merged commit 0e4633a into Linaro:master Nov 6, 2023
7 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants