Skip to content

[feature] Rename attachments - #11920

Merged
SchrodingersGat merged 14 commits into
inventree:masterfrom
SchrodingersGat:rename-uploads
May 18, 2026
Merged

SchrodingersGat merged 14 commits into
inventree:masterfrom
SchrodingersGat:rename-uploads

Conversation

@SchrodingersGat

@SchrodingersGat SchrodingersGat commented May 11, 2026 •

Copy link
Copy Markdown
Member

Tasks

  • Prevent change of file extension (security risks?)
  • Docs update
  • Unit tests

@SchrodingersGat SchrodingersGat added this to the 1.4.0 milestone May 11, 2026
@SchrodingersGat SchrodingersGat added api Relates to the API feature User Interface Related to the frontend / User Interface labels May 11, 2026
@netlify

netlify Bot commented May 11, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for inventree-web-pui-preview canceled.

Name Link
🔨 Latest commit d2743d5
🔍 Latest deploy log https://app.netlify.com/projects/inventree-web-pui-preview/deploys/6a0ad9d4a977d00008fa16a7

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.py and CHANGELOG.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.

Comment thread src/backend/InvenTree/common/api.py Resolved
Comment thread src/backend/InvenTree/common/models.py Resolved
Comment thread src/backend/InvenTree/common/models.py Resolved
Comment thread src/backend/InvenTree/common/api.py Resolved
@codecov

codecov Bot commented May 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.97980% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.41%. Comparing base (73c7820) to head (d2743d5).
⚠️ Report is 394 commits behind head on master.

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     
Flag Coverage Δ
backend 89.24% <97.97%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Backend Apps 91.74% <ø> (+<0.01%) ⬆️
Backend General 93.49% <97.91%> (+0.07%) ⬆️
Frontend ∅ <ø> (∅)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/backend/InvenTree/common/api.py Resolved
@SchrodingersGat

Copy link
Copy Markdown
Member Author

@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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we ensure this is an atomic action?

@matmair matmair left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Lgtm; a further improvement could be to use build-in validations of filenames instead of hard coding a regex

@SchrodingersGat
SchrodingersGat merged commit acc2786 into inventree:master May 18, 2026
37 checks passed
@SchrodingersGat
SchrodingersGat deleted the rename-uploads branch May 18, 2026 10:02
martonmiklos pushed a commit to martonmiklos/InvenTree that referenced this pull request Jun 30, 2026
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Relates to the API feature User Interface Related to the frontend / User Interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FR] Allow renaming of uploaded files

3 participants