Skip to content

API Reference parrot_formdesigner.services.org_graph

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_formdesigner.services.org_graph

View source

OrgGraphService — árbol multi-jerarquía read-only sobre auth.* + geografía.

Lee tablas de solo-lectura:

  • auth.organizations, auth.organization_clients, auth.clients, auth.programs, auth.program_clients
  • Geografía per-client: networkninja.markets, networkninja.districts, networkninja.regions
  • Proyectos propios: fieldsync.projects

Principios de diseño (§8 spec):

  • Hard tenant isolation: todo query filtra org_id / client_id explícitamente; sin leakage cross-tenant.
  • SQL 100% parametrizado: valores siempre vía $1/$2 etc.; nombres de schema/tabla fijados como constantes (no interpolados desde input de usuario).
  • Múltiples jerarquías: un "company" super-node agrupa todas las sub-jerarquías del tenant (por si un cliente tiene >1 organización).
  • Read-only: no hay ningún INSERT/UPDATE/DELETE en este servicio.
  • Pool inyectado: acepta pool o fake-pool para testabilidad completa.

Uso::

svc = OrgGraphService(pool)
graph = await svc.get_graph(org_id=7, tenant="myco")
node  = await svc.get_node("client", "42", tenant="myco")

Attribute NodeType

Class OrgGraph

Full organizational graph for a tenant.

Fields:

Field Type Default Description
org_id int Numeric identifier of the organization.
tenant str Tenant slug (program slug from navigator-auth).
root OrgNode Root OrgNode (type "company"); children are the tree.

Class OrgGraphService

Build in-memory org-graph trees from navigator-auth + networkninja.

Designed for read-only access. Enforces hard tenant isolation by always filtering on org_id / client_id passed as parameters.

Example::

svc = OrgGraphService(pool)
graph = await svc.get_graph(7, tenant="acme")
Parameter Type Default Description
pool Any | None None asyncpg pool (or compatible fake). When None, falls back to creating a pool from FIELDSYNC_AUTH_RO_DSN env var. In unit tests pass a fake pool explicitly.

Method OrgGraphService.get_graph

Build the full org graph for org_id / tenant.

get_graph(org_id: int, *, tenant: str, depth: int = 3) -> OrgGraph

Parameter Type Default Description
org_id int Numeric organization identifier.
tenant str Tenant slug (used for metadata and isolation).
depth int 3 How many levels deep to traverse (default 3). Level 0 = company root only; 1 = + orgs; 2 = + clients/programs; 3 = + projects/geography.

Returns: OrgGraph — OrgGraph with a "company" root node containing all discovered sub-hierarchies.

Raises:

  • KeyError — If the organization is not found.
  • RuntimeError — If no pool is available.

Method OrgGraphService.get_node

Retrieve a single node by type and ID, enforcing tenant isolation.

Currently supports "organization", "client", and "program" node types. Other types return a stub node with metadata from a best-effort query.

get_node(node_type: NodeType, node_id: str, *, tenant: str, org_id: int) -> OrgNode

Parameter Type Default Description
node_type NodeType Type of node to retrieve.
node_id str String identifier for the node.
tenant str Tenant slug for isolation (stored in metadata).
org_id int

Returns: OrgNode — OrgNode with metadata populated from the DB.

Raises:

  • KeyError — If the node is not found.
  • RuntimeError — If no pool is available.

Class OrgNode

A single node in the organizational hierarchy.

Fields:

Field Type Default Description
node_type NodeType Type of the node (organization, client, program, etc.).
node_id str String identifier unique within the node_type namespace.
parent_id str | None None String identifier of the parent node, or None for root.
metadata dict[str, Any] Arbitrary key-value metadata (name, client_id, etc.).
children list['OrgNode'] Nested child nodes (populated up to requested depth).

Attribute logger

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally