https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44272 --- Comment #2 from Nick Clemens (kidclamp) <nick@bywatersolutions.com> --- Created attachment 212575 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212575&action=edit Bug 44272: Add optional slugs for readable links to uploaded files This adds an optional, unique 'slug' (link name) to uploaded files. A public upload with a slug is linked as OPACBaseURL/cgi-bin/koha/opac-retrieve-file.pl/<slug> instead of OPACBaseURL/cgi-bin/koha/opac-retrieve-file.pl/<hashvalue>/<filename> The file is still served by opac-retrieve-file.pl, so the public flag and the Content-Type/Content-Disposition headers still apply. A slug on a non-public upload does not make it reachable in the OPAC. Slug rules (Koha::UploadedFile->is_valid_slug): - 1 to 100 characters from a-z, 0-9, '_' and '-' - starts and ends with a letter or digit - no dots, so a slug cannot claim a file extension (e.g. 'invoice.pdf' pointing to an executable) - cannot look like a hashvalue (Koha::UploadedFile->looks_like_hashvalue), so it cannot be confused with a hashvalue link - unique; input is trimmed and lowercased, empty removes the slug - the OPAC matches slugs exactly: /Annual-Report is a 404 when the slug is annual-report Retired slugs: when an upload's slug is changed or removed, or the upload is deleted, the slug is recorded in the new table uploaded_files_retired_slugs. Another upload can only take a retired slug if the user has tools/upload_manage, so a link that was published (e.g. in 856$u) cannot silently be pointed to other content. The upload that released a slug can take it back. This is enforced in Koha::UploadedFile->store; Koha::UploadedFile->set_slug is the way to allow the reuse. Only the upload's owner or a user with upload_manage can set or change a slug (Koha::UploadedFile->can_be_managed_by, from bug YYYYY). Search in Tools > Upload now also matches slugs. Test plan: 1. Apply patches, updatedatabase, restart_all 2. prove t/db_dependent/Upload.t 3. Tools > Upload: upload a public file, then click 'Link name' on it and enter 'annual-report' 4. The row shows 'Link name: annual-report' and the Public link is .../opac-retrieve-file.pl/annual-report 5. Open that link: the file is served under its real filename 6. Try .../opac-retrieve-file.pl/Annual-Report and .../opac-retrieve-file.pl/annual-report/x: 404 7. Upload a second file and try to give it the link name 'annual-report': 'This link name is already used by another upload.' 8. Try 'bad name!', 'invoice.pdf' or a 32-character hex string: 'Link name is not valid...' 9. Give a non-public upload a link name and open it in the OPAC: 404 10. Search uploads for 'annual-rep': the file is found by its slug 11. Clear the link name (empty value): the link falls back to .../opac-retrieve-file.pl/<hash>/<filename> 12. Set it back to 'annual-report' on the same file: allowed 13. Create a staff user with only catalogue + tools > upload_general_files. As that user: a. try to set a link name on someone else's upload: the button is not shown, and a forged POST is refused b. upload a file of your own 14. As the superlibrarian, delete the 'annual-report' upload 15. As the limited user, give your file the link name 'annual-report': 'This link name was used by another upload before...' 16. As the superlibrarian, give another upload the link name 'annual-report': allowed 17. With the upload.pl plugin on 856$u, Choose a file with a slug: the slug link is used 18. Enable HTML5MediaEnable, put a slug link to a public mp3/mp4 in 856$u and confirm the player appears on the OPAC detail page Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> -- You are receiving this mail because: You are watching all bug changes.