-
Notifications
You must be signed in to change notification settings - Fork 531
Description
Issue Description
Currently, only dataset owners can visualize knowledge graphs through the /api/v1/datasets/{dataset_id}/graph
endpoint. Users who have been granted read permissions on datasets cannot access graph visualizations due to two issues in the access control implementation:
- Dataset Retrieval Restriction: The
get_dataset()
function only returns datasets for owners - Incorrect Database Context: The
get_formatted_graph_data()
function sets database context with the requesting user's ID instead of the dataset owner's ID
This breaks the intended permission model where users with read access should be able to view graph visualizations.
Current Behavior
When a user with read permissions tries to access a dataset's graph visualization:
- API Call:
GET /api/v1/datasets/{dataset_id}/graph
- Dataset Check:
get_dataset(user.id, dataset_id)
returnsNone
because user is not owner - Result: 404 error - "Dataset not found" even though user has read permissions
Even if the dataset retrieval were fixed, the database context would be set incorrectly, preventing access to the actual graph data.
Expected Behavior
Users with read permissions should be able to:
- Access the graph visualization endpoint
- View the complete knowledge graph for datasets they have read access to
- See the same graph data as the dataset owner (subject to their read permissions)
Technical Solution
Phase 1: Update Dataset Retrieval Logic
Create a new function get_dataset_with_permissions()
that checks read access:
Phase 2: Fix Graph Data Context Setting
Update get_formatted_graph_data()
to use dataset owner's ID for context:
Implementation Steps
Step 1: Create Permission-Aware Dataset Retrieval
Step 2: Update Graph Data Function
Step 3: Update API Endpoint
Files to Modify
New Files
cognee/modules/data/methods/get_dataset_with_permissions.py
Modified Files
cognee/modules/graph/methods/get_formatted_graph_data.py
cognee/api/v1/datasets/routers/get_datasets_router.py
cognee/modules/data/methods/__init__.py # Add new import
Test Files
cognee/tests/test_graph_visualization_permissions.py # New integration tests
cognee/tests/test_dataset_permissions.py # Update existing tests