c889a57b6b
Test Suites / Build CI Environment (push) Has been cancelled
Test Suites / Basic Tests (push) Has been cancelled
Test Suites / End-to-End Tests (push) Has been cancelled
Test Suites / CLI Tests (push) Has been cancelled
Test Suites / Slow End-to-End Tests (push) Has been cancelled
Test Suites / Graph Database Tests (push) Has been cancelled
Test Suites / Vector DB Tests (push) Has been cancelled
Test Suites / Temporal Graph Test (push) Has been cancelled
Test Suites / Search Test on Different DBs (push) Has been cancelled
Test Suites / Example Tests (push) Has been cancelled
Test Suites / Notebook Tests (push) Has been cancelled
Test Suites / OS and Python Tests Ubuntu (push) Has been cancelled
Test Suites / OS and Python Tests Extended (push) Has been cancelled
Test Suites / LLM Test Suite (push) Has been cancelled
Test Suites / S3 File Storage Test (push) Has been cancelled
Test Suites / Run Integration Tests (push) Has been cancelled
Test Suites / MCP Tests (push) Has been cancelled
Test Suites / Docker Compose Test (push) Has been cancelled
Test Suites / Docker CI test (push) Has been cancelled
Test Suites / Relational DB Migration Tests (push) Has been cancelled
Test Suites / Distributed Cognee Test (push) Has been cancelled
Test Suites / DB Examples Tests (push) Has been cancelled
Test Suites / Test Completion Status (push) Has been cancelled
Test Suites / Claude Code Review (push) Has been cancelled
Test Suites / basic checks (push) Has been cancelled
build | Build and Push Cognee MCP Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
build | Build and Push Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.11) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.12) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (kuzu, kuzu) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (neo4j, neo4j) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Examples (push) Has been cancelled
Weighted Edges Tests / Code Quality for Weighted Edges (push) Has been cancelled
62 lines
1.8 KiB
Python
62 lines
1.8 KiB
Python
from typing import Optional
|
|
from uuid import UUID as uuid_UUID
|
|
from fastapi_users import schemas
|
|
from fastapi_users.db import SQLAlchemyBaseUserTableUUID
|
|
from sqlalchemy import ForeignKey, Column, UUID
|
|
from sqlalchemy.orm import relationship, Mapped
|
|
|
|
from .Principal import Principal
|
|
from .UserTenant import UserTenant
|
|
from .UserRole import UserRole
|
|
from .Role import Role
|
|
from .Tenant import Tenant
|
|
|
|
|
|
class User(SQLAlchemyBaseUserTableUUID, Principal):
|
|
__tablename__ = "users"
|
|
|
|
id = Column(UUID, ForeignKey("principals.id", ondelete="CASCADE"), primary_key=True)
|
|
|
|
# Foreign key to current Tenant (Many-to-One relationship)
|
|
tenant_id = Column(UUID, ForeignKey("tenants.id"))
|
|
|
|
# Parent user — when an agent/service user creates datasets, the parent
|
|
# inherits full permissions automatically. Null for regular human users.
|
|
parent_user_id = Column(UUID, ForeignKey("users.id", ondelete="SET NULL"), nullable=True)
|
|
|
|
# Many-to-Many Relationship with Roles
|
|
roles: Mapped[list["Role"]] = relationship(
|
|
"Role",
|
|
secondary=UserRole.__tablename__,
|
|
back_populates="users",
|
|
)
|
|
|
|
# Many-to-Many Relationship with Tenants user is a part of
|
|
tenants: Mapped[list["Tenant"]] = relationship(
|
|
"Tenant",
|
|
secondary=UserTenant.__tablename__,
|
|
back_populates="users",
|
|
)
|
|
|
|
# ACL Relationship (One-to-Many)
|
|
acls = relationship("ACL", back_populates="principal", cascade="all, delete")
|
|
|
|
__mapper_args__ = {
|
|
"polymorphic_identity": "user",
|
|
}
|
|
|
|
|
|
# Keep these schemas in sync with User model
|
|
class UserRead(schemas.BaseUser[uuid_UUID]):
|
|
tenant_id: Optional[uuid_UUID] = None
|
|
parent_user_id: Optional[uuid_UUID] = None
|
|
|
|
|
|
class UserCreate(schemas.BaseUserCreate):
|
|
is_verified: bool = True
|
|
parent_user_id: Optional[uuid_UUID] = None
|
|
|
|
|
|
class UserUpdate(schemas.BaseUserUpdate):
|
|
pass
|