mirror of https://github.com/buster-so/buster.git
3.3 KiB
3.3 KiB
title | author | date | status |
---|---|---|---|
Add Dashboard to Collections REST Endpoint | Cascade | 2025-03-19 | Complete |
Add Dashboard to Collections REST Endpoint
Problem Statement
Users need the ability to programmatically add a dashboard to multiple 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 a dashboard to multiple collections
- ✅ 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 /dashboards/:id/collections
Request Body:
{
"collection_ids": ["uuid1", "uuid2", "uuid3"]
}
Response:
200 OK
- Success{ "message": "Dashboard added to collections successfully" }
400 Bad Request
- Invalid input403 Forbidden
- Insufficient permissions404 Not Found
- Dashboard not found500 Internal Server Error
- Server error
Handler Implementation
The handler will:
- ✅ Validate that the dashboard exists
- ✅ Check if the user has appropriate permissions (Owner, FullAccess, or CanEdit)
- ✅ Validate that the collections exist and the user has access to them
- ✅ Add the dashboard to the collections by creating records in the
collections_to_assets
table - ✅ Handle the case where a dashboard was previously in a collection but was deleted (upsert)
File Changes
New Files
- ✅
libs/handlers/src/dashboards/add_dashboard_to_collections_handler.rs
- ✅
src/routes/rest/routes/dashboards/add_dashboard_to_collections.rs
- ✅ Update
libs/handlers/src/dashboards/mod.rs
to include the new handler - ✅ Update
src/routes/rest/routes/dashboards/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 a dashboard to collections
- ✅ Test error cases (dashboard not found, collection not found, insufficient permissions)
- ✅ Test adding a dashboard that was previously in a 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