Repository navigation
[feature] Rename attachments - #11920
Conversation
✅ Deploy Preview for inventree-web-pui-preview canceled.
|
There was a problem hiding this comment.
Pull request overview
This PR adds support for renaming uploaded attachment files after upload, exposing a new backend API endpoint and wiring it into the frontend attachment table UI. It also bumps the API version and records the change in the changelog.
Changes:
- Add backend
attachment/<pk>/rename/endpoint and supporting serializer/model method to rename stored attachment files. - Add a “Rename File” row action in the frontend attachment table which opens a modal to submit the new filename.
- Bump API version and document the change in
api_version.pyandCHANGELOG.md.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/frontend/src/tables/general/AttachmentTable.tsx | Adds a “Rename File” row action and modal to call the new rename API endpoint. |
| src/frontend/lib/enums/ApiEndpoints.tsx | Registers a new attachment_rename endpoint constant for frontend usage. |
| src/backend/InvenTree/InvenTree/api_version.py | Bumps API version to v487 and adds a brief release note entry. |
| src/backend/InvenTree/common/serializers.py | Adds AttachmentRenameSerializer to validate rename requests. |
| src/backend/InvenTree/common/models.py | Implements Attachment.validate_rename() and Attachment.rename() to move the stored file and update DB path. |
| src/backend/InvenTree/common/api.py | Adds AttachmentRename API view and routes it under the attachment detail path. |
| CHANGELOG.md | Notes the new attachment rename feature in the changelog. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #11920 +/- ##
==========================================
+ Coverage 91.39% 91.41% +0.01%
==========================================
Files 974 974
Lines 50635 50731 +96
==========================================
+ Hits 46279 46374 +95
- Misses 4356 4357 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
- Use the existing API endpoint
|
@matmair I have simplified this to make use of the existing API endpoint - LMK what you think |
| if default_storage.exists(new_path): | ||
| raise ValidationError(_('A file with this name already exists')) | ||
|
|
||
| # Create a new file with the new name, and delete the old file |
There was a problem hiding this comment.
Can we ensure this is an atomic action?
matmair
left a comment
There was a problem hiding this comment.
Lgtm; a further improvement could be to use build-in validations of filenames instead of hard coding a regex
* Implementation * Update API and CHANGELOG * Annotate response type * Simplify attachment renaming - Use the existing API endpoint * Capture the actual saved path * Tweak attachment table fields * Use built-in validation * Update docs * Unit testing * Ignore some lines from coverage * Check if file exists before deleting
Tasks