PR #3347 - Default User File Upload #3638
Draft
+363
β38
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request Type
Relevant Issues
#3347
resolves #3347
What is in this change?
This Pull Request implements a feature that allows administrators to grant document upload permissions to regular users in multi-user mode, with the ability to set upload quotas. Previously, only admin
and manager roles could upload documents to workspaces.
Feature Overview:
- Regular users can now be granted document upload permissions by administrators
- A quota system limits how many documents a regular user can upload
- Added canUploadDocuments (boolean) field to User model
- Added documentUploadLimit (integer) field to User model
- Added document ownership tracking (uploadedBy field in workspace_documents)
- New canUploadDocuments middleware to enforce permissions
- Permission check considers both permission flag and upload quota
- All document upload endpoints now use this middleware
- Added UI in Admin panel for enabling/disabling document upload permissions
- Added UI for setting document upload quotas
- Conditional rendering for upload buttons based on permissions
- Regular users can only upload to workspaces they have access to
- Quotas prevent excessive uploads
- All uploads go through the same content validation process
Technical Implementation:
- Modified Prisma schema to add new user fields
- Created relation between users and documents
- Implemented canUploadDocuments middleware that checks both permission flag and remaining quota
- Updated all document upload endpoints to use the new middleware:
- Added comprehensive documentation for the feature in USER_PERMISSIONS.md
- Updated README to mention the new granular permissions system
This PR addresses issue #3347 by expanding AnythingLLM's permission system to give administrators more control over who can upload documents while maintaining security and preventing resource abuse
through the quota system.
Additional Information
This PR introduces a significant enhancement to AnythingLLM's multi-user permission system by allowing finer-grained control over document uploads. Some additional context worth noting:
- Organizations can now delegate document upload capabilities to trusted regular users without needing to grant them full manager privileges
- This creates a more flexible workflow where subject matter experts can contribute documents while maintaining appropriate access control
- We chose to extend the existing permission system rather than creating a new role type
- This approach preserves backward compatibility and minimizes changes to the existing role system
- The implementation builds on the established middleware pattern already used throughout the application
- The document count per user is tracked efficiently to maintain performance
- Permission checks only cause minimal overhead during document upload operations
- This permission framework could serve as a model for other granular permissions in the future
- The quota system pattern could be adapted for other resource limitations (e.g., API usage, workspace creation)
- Tested extensively in Docker environment with multi-user mode enabled
- Verified that all document upload endpoints correctly respect the new permission system
- Confirmed UI elements appear/disappear appropriately based on permissions
- We deliberately chose to make document upload permissions administrator-controlled only
- The decision to track document ownership allows for potential future features (such as user-specific document management)
- Regular users are shown upload UI elements only when they have permission, providing a cleaner experience
This enhancement balances security with flexibility, giving administrators more control over how users interact with the system while maintaining AnythingLLM's robust permission model.
Developer Validations
yarn lint
from the root of the repo & committed changes