A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.
feat(api): update edge label
dextmorgnc4408c2f3e26
diff --git a/flowsint-api/app/api/routes/sketches.py b/flowsint-api/app/api/routes/sketches.pyindex c225c7e2..c9d1a42b 100644--- a/flowsint-api/app/api/routes/sketches.py+++ b/flowsint-api/app/api/routes/sketches.py@@ -1,31 +1,32 @@-from app.security.permissions import check_investigation_permission+from typing import Any, Dict, List, Literal+from uuid import UUID+from fastapi import (APIRouter,- HTTPException,+ BackgroundTasks,Depends,- status,- UploadFile,File,Form,- BackgroundTasks,+ HTTPException,+ UploadFile,+ status,)-from flowsint_types import TYPE_REGISTRY-from pydantic import BaseModel, Field-from typing import Literal, List, Dict, Any-from flowsint_core.utils import flatten-from sqlalchemy.orm import Session-from app.api.schemas.sketch import SketchCreate, SketchRead, SketchUpdate-from flowsint_core.core.models import Sketch, Profile-from uuid import UUIDfrom flowsint_core.core.graph_db import neo4j_connectionfrom flowsint_core.core.graph_repository import GraphRepository+from flowsint_core.core.models import Profile, Sketchfrom flowsint_core.core.postgre_db import get_db-from app.api.deps import get_current_user-from flowsint_core.imports import FileParseResult, parse_import_file-from app.api.sketch_utils import update_sketch_timestampfrom flowsint_core.core.types import Role+from flowsint_core.imports import FileParseResult, parse_import_file+from flowsint_core.utils import flatten+from flowsint_types import TYPE_REGISTRY+from pydantic import BaseModel, Fieldfrom sqlalchemy import or_+from sqlalchemy.orm import Session+from app.api.deps import get_current_user+from app.api.schemas.sketch import SketchCreate, SketchRead, SketchUpdate+from app.api.sketch_utils import update_sketch_timestamp+from app.security.permissions import check_investigation_permissionrouter = APIRouter()@@ -63,6 +64,13 @@ class NodeEditInput(BaseModel):)+class RelationshipEditInput(BaseModel):+ relationshipId: str+ data: Dict[str, Any] = Field(+ default_factory=dict, description="Updated data for the relationship"+ )++class NodeMergeInput(BaseModel):id: strdata: NodeData = Field(@@ -105,7 +113,9 @@ def list_sketches(query = query.filter(InvestigationUserRole.user_id == current_user.id)# Filter by allowed roles- conditions = [InvestigationUserRole.roles.any(role) for role in allowed_roles_for_read]+ conditions = [+ InvestigationUserRole.roles.any(role) for role in allowed_roles_for_read+ ]query = query.filter(or_(*conditions))return query.distinct().all()@@ -435,6 +445,50 @@ def edit_node(}[email protected]("/{sketch_id}/relationships/edit")+@update_sketch_timestamp+def edit_relationship(+ sketch_id: str,+ relationship_edit: RelationshipEditInput,+ background_tasks: BackgroundTasks,+ db: Session = Depends(get_db),+ current_user: Profile = Depends(get_current_user),+):+ # First verify the sketch exists and belongs to the user+ sketch = db.query(Sketch).filter(Sketch.id == sketch_id).first()+ if not sketch:+ raise HTTPException(status_code=404, detail="Sketch not found")+ check_investigation_permission(+ current_user.id, sketch.investigation_id, actions=["update"], db=db+ )++ # Update edge using GraphRepository+ try:+ graph_repo = GraphRepository(neo4j_connection)+ result = graph_repo.update_relationship(+ element_id=relationship_edit.relationshipId,+ properties=relationship_edit.data,+ sketch_id=sketch_id,+ )+ except Exception as e:+ print(f"Relationship update error: {e}")+ raise HTTPException(status_code=500, detail="Failed to update relationship")++ if not result:+ raise HTTPException(+ status_code=404, detail="Relationship not found or not accessible"+ )++ return {+ "status": "relationship updated",+ "relationship": {+ "id": result["id"],+ "label": result["type"],+ "data": result["data"],+ },+ }++class NodePosition(BaseModel):nodeId: strx: float@@ -741,7 +795,9 @@ async def execute_import(# Get the Pydantic type from registryDetectedType = TYPE_REGISTRY.get_lowercase(entity_type)if not DetectedType:- conversion_errors.append(f"Entity {idx + 1} ({label}): Unknown type {entity_type}")+ conversion_errors.append(+ f"Entity {idx + 1} ({label}): Unknown type {entity_type}"+ )continue# Clean empty values and add label@@ -758,7 +814,9 @@ async def execute_import(# Batch create all nodesgraph_repo = GraphRepository(neo4j_connection)try:- result = graph_repo.batch_create_nodes(nodes=pydantic_nodes, sketch_id=sketch_id)+ result = graph_repo.batch_create_nodes(+ nodes=pydantic_nodes, sketch_id=sketch_id+ )nodes_created = result["nodes_created"]batch_errors = result.get("errors", [])all_errors = conversion_errors + batch_errors