Modify the maximum file count and storage capacity allowed for a specific user. Both limits are optional in the request body.
Endpoint
PUT /api/admin/users/:userID/limits
Authentication
Requires authentication via JWT token in Authorization header. Currently uses standard AuthRequired() middleware. Admin-specific authorization is planned for future implementation.
Authorization: Bearer <jwt_token>
Source: routes/routes.go:58
Parameters
The unique identifier of the user whose limits should be updated
Request Body
Maximum number of files the user can upload. Must be >= 0. Omit to leave unchanged.
Maximum storage capacity in bytes. Must be >= 0. Omit to leave unchanged.
Both fields are optional. You can update only max_files, only max_storage, or both in a single request.
Example Request
{
"max_files": 2000,
"max_storage": 21474836480
}
Update only storage:
{
"max_storage": 10737418240
}
Response
Success Response (200)
Updated user informationUpdated maximum file count
Updated maximum storage in bytes
Example Response
{
"message": "User limits updated successfully",
"user": {
"id": 42,
"username": "alice",
"max_files": 2000,
"max_storage": 21474836480
}
}
Error Responses
400 Bad Request - Missing or invalid user ID
{
"error": "User ID is required"
}
400 Bad Request - Invalid request body
{
"error": "<validation error details>"
}
400 Bad Request - Negative value validation
{
"error": "Max files cannot be negative"
}
Or:
{
"error": "Max storage cannot be negative"
}
Source: controllers/user.go:165-177
404 Not Found - User does not exist
{
"error": "User not found"
}
Source: controllers/user.go:159
500 Internal Server Error - Database save failed
{
"error": "Failed to update user limits"
}
Source: controllers/user.go:181
Implementation Details
Validation Logic
The endpoint enforces these validations:
- User ID required: Path parameter
userID must be non-empty
- User exists: Queries database for user with matching ID
- Non-negative values: Both
max_files and max_storage must be >= 0 if provided
Source: controllers/user.go:141-178
Partial Updates
The endpoint uses pointer types (*int and *int64) to distinguish between:
- Field not provided (nil pointer) - no update
- Field provided with value (non-nil pointer) - update to new value
This allows selective updates without requiring all fields.
Source: controllers/user.go:147-150
Update Behavior
- Only fields provided in the request body are modified
- Database record is saved with
DB.Save(&user) which updates all fields
- No cascading effects on existing files or access records
Updating limits does not automatically delete or restrict access to existing files that may now exceed the new limits. Users with files exceeding their new limits may need to delete files before uploading new ones.
Storage Units Reference
| Unit | Bytes | Example Value |
|---|
| 1 KB | 1,024 | 1024 |
| 1 MB | 1,048,576 | 1048576 |
| 1 GB | 1,073,741,824 | 1073741824 |
| 10 GB | 10,737,418,240 | 10737418240 |
| 20 GB | 21,474,836,480 | 21474836480 |
Example Usage
curl -X PUT https://api.defdrive.com/api/admin/users/42/limits \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{
"max_files": 2000,
"max_storage": 21474836480
}'