Skip to content

Fix Graph Visualization Access for Users with Read Permissions #1182

@Vasilije1990

Description

@Vasilije1990

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:

  1. Dataset Retrieval Restriction: The get_dataset() function only returns datasets for owners
  2. 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:

  1. API Call: GET /api/v1/datasets/{dataset_id}/graph
  2. Dataset Check: get_dataset(user.id, dataset_id) returns None because user is not owner
  3. 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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions