-
Notifications
You must be signed in to change notification settings - Fork 6
Add file download endpoint for beacons #582
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
base: main
Are you sure you want to change the base?
Conversation
| end | ||
|
|
||
| def accessible_blobs | ||
| ActiveStorage::Blob |
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.
Do we want to use sql in this query? I know it is faster but it is less accessible to everyone. (Not saying don't use sql, asking the question)
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.
Also, I know this is in draft and not finished so ignore this ;)
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.
Good shout - just changed it to ActiveRecord 👍
5621b6e to
8a9bcf5
Compare
Beacons need to scope file access to only documents attached to their associated topics. The accessible_blobs method provides this authorisation layer by joining through the attachments and beacon_topics associations to ensure beacons cannot access files from topics belonging to other beacons.
Beacons receive a manifest listing files they need, then download each file individually via this endpoint. The controller validates that the requesting beacon has access through its assigned topics and supports resumable downloads via Range headers for reliability on unstable connections.
8a9bcf5 to
5aa9416
Compare
What Issue Does This PR Cover, If Any?
Resolves: #568
What Changed? And Why Did It Change?
Beacons need to download documents that are attached to their associated topics. Previously there was no endpoint to serve these files with proper authentication and authorization. This PR adds a files endpoint that allows beacons to download documents only from topics they have access to. The endpoint uses ActiveStorage streaming to support both full file downloads and partial content requests via Range headers, which is important for efficient delivery of large files.
The accessible_blobs method was added to the Beacon model to provide the authorization layer, ensuring beacons can only access documents from their own topics. The namespace was also standardised from beacons to beacon for consistency across the API.
How Has This Been Tested?
Comprehensive request specs cover authentication, authorization, full downloads, Range header support with single and multiple byte ranges, not found scenarios, and cross-beacon authorization checks. Model specs verify the accessible_blobs method correctly scopes files to the beacon's topics.