mirror of https://github.com/buster-so/buster.git
3.3 KiB
3.3 KiB
title | author | date | status |
---|---|---|---|
Add Dashboards to Collection REST Endpoint | Cascade | 2025-03-19 | Implemented |
Add Dashboards to Collection REST Endpoint
Problem Statement
Users need the ability to programmatically add dashboards to collections via a REST API. Currently, this functionality is not available, limiting the ability to manage collections through the API.
Goals
- ✅ Create a REST endpoint to add dashboards to a collection
- ✅ Implement proper permission validation
- ✅ Ensure data integrity with proper error handling
- ✅ Follow established patterns for REST endpoints and handlers
Non-Goals
- Modifying the existing collections functionality
- Creating UI components for this endpoint
Technical Design
REST Endpoint
Endpoint: POST /collections/:id/dashboards
Request Body:
{
"dashboard_ids": ["uuid1", "uuid2", "uuid3"]
}
Response:
200 OK
- Success{ "message": "Dashboards added to collection successfully" }
400 Bad Request
- Invalid input403 Forbidden
- Insufficient permissions404 Not Found
- Collection not found500 Internal Server Error
- Server error
Handler Implementation
The handler will:
- ✅ Validate that the collection exists
- ✅ Check if the user has appropriate permissions (Owner, FullAccess, or CanEdit)
- ✅ Validate that the dashboards exist and the user has access to them
- ✅ Add the dashboards to the collection by creating records in the
collections_to_assets
table - ✅ Handle the case where a dashboard was previously in the collection but was deleted (upsert)
File Changes
New Files
- ✅
libs/handlers/src/collections/add_dashboards_to_collection_handler.rs
- ✅
src/routes/rest/routes/collections/add_dashboards_to_collection.rs
- ✅ Update
libs/handlers/src/collections/mod.rs
to include the new handler - ✅ Update
src/routes/rest/routes/collections/mod.rs
to include the new endpoint
Database Operations
The implementation uses the collections_to_assets
table with the following operations:
- ✅ SELECT to check if records exist
- ✅ INSERT for new records
- ✅ UPDATE for records that were previously deleted
Testing Strategy
Unit Tests
-
✅ Test the handler with mocked database connections
- ✅ Test adding dashboards to a collection
- ✅ Test error cases (collection not found, dashboard not found, insufficient permissions)
- ✅ Test adding dashboards that were previously in the collection but deleted
-
✅ Test the REST endpoint
- ✅ Test successful request
- ✅ Test error responses for various scenarios
Integration Tests
- ✅ Test skeleton created for the endpoint with a test database
Security Considerations
- ✅ The endpoint requires authentication
- ✅ Permission checks ensure users can only modify collections they have access to
- ✅ Input validation prevents malicious data
Monitoring and Logging
- ✅ All operations are logged with appropriate context
- ✅ Errors are logged with detailed information
Dependencies
libs/sharing
- For permission checkinglibs/database
- For database operations
Rollout Plan
- ✅ Implement the handler and endpoint
- ✅ Write tests
- ✅ Code review
- Deploy to staging
- Test in staging
- Deploy to production
- Monitor for issues