3ab4925783
- 10 models: tenants, users, user_tenants, roles, sessions, audit_log, deletion_log, notifications, password_reset_tokens, api_tokens - Session-based auth (Redis + PostgreSQL audit trail) - Multi-tenant with ORM-level filtering + PostgreSQL RLS (set_config) - RBAC with roles/permissions + field-level permissions - CSRF protection via Origin header validation - Auth rate limiting (Redis counters with TTL) - CORS with explicit origins (no wildcard) - Health endpoint (no auth required) - Notification service + audit log middleware - 29 tests, 26 ACs, all passing - Coverage: 62% (infrastructure modules pending coverage in later tasks)
41 lines
1.7 KiB
Python
41 lines
1.7 KiB
Python
"""Company model — minimal for cross-tenant test (AC #17)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import uuid
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import String, Integer, Numeric, Text, DateTime, ForeignKey, func, Index
|
|
from sqlalchemy.dialects.postgresql import UUID as PGUUID
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.core.db import Base, TenantMixin
|
|
|
|
|
|
class Company(Base, TenantMixin):
|
|
"""Company entity (minimal fields for T01 cross-tenant test)."""
|
|
|
|
__tablename__ = "companies"
|
|
__table_args__ = (
|
|
Index("ix_companies_tenant_deleted", "tenant_id", "deleted_at"),
|
|
Index("ix_companies_tenant_name", "tenant_id", "name"),
|
|
)
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(
|
|
PGUUID(as_uuid=True), primary_key=True, default=uuid.uuid4
|
|
)
|
|
name: Mapped[str] = mapped_column(String(100), nullable=False)
|
|
account_number: Mapped[str | None] = mapped_column(String(40), nullable=True)
|
|
industry: Mapped[str | None] = mapped_column(String(50), nullable=True)
|
|
phone: Mapped[str | None] = mapped_column(String(30), nullable=True)
|
|
email: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
|
website: Mapped[str | None] = mapped_column(String(500), nullable=True)
|
|
description: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
deleted_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
|
created_by: Mapped[uuid.UUID | None] = mapped_column(
|
|
PGUUID(as_uuid=True), ForeignKey("users.id", ondelete="SET NULL"), nullable=True
|
|
)
|
|
updated_by: Mapped[uuid.UUID | None] = mapped_column(
|
|
PGUUID(as_uuid=True), ForeignKey("users.id", ondelete="SET NULL"), nullable=True
|
|
)
|