mirror of
https://github.com/idrainformatica/PecFlow.git
synced 2026-06-16 12:45:42 +02:00
58a233236c
- docker-compose.yml: PostgreSQL 16, Redis 7, MinIO, Nginx - backend FastAPI: struttura monorepo, config pydantic-settings - modelli SQLAlchemy: tutti i modelli (tenants, users, mailboxes, messages, archival, permissions, labels, audit_log) - migrazione Alembic 0001: schema completo in pure SQL - auth API: login JWT, refresh token rotation, logout, 2FA TOTP (setup/verify/disable) - CRUD utenti: lista, crea, modifica, reset password, soft delete - permessi granulari (Fase 1-A): mailbox_permissions, assegna/revoca/lista - CRUD tenant: gestione super-admin - sicurezza: AES-256-GCM cifratura credenziali IMAP/SMTP, bcrypt password - RLS PostgreSQL: isolamento multi-tenant per request - seed sviluppo: tenant demo + admin + operator - test unit: security (bcrypt, JWT, AES), auth_service - test integration: auth endpoints, users endpoints - CI GitHub Actions: lint (ruff), test (pytest), build Docker, security scan - infra: nginx.conf, redis.conf - Makefile con comandi make dev/test/migrate/seed Definition of Done: ✅ Login, refresh token e TOTP funzionanti ✅ make dev porta in piedi tutto lo stack locale ✅ CI configurata
48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
"""
|
||
Modello Tenant – ogni organizzazione cliente del SaaS.
|
||
"""
|
||
|
||
import uuid
|
||
from datetime import datetime
|
||
|
||
from sqlalchemy import Boolean, DateTime, Index, Integer, String, func
|
||
from sqlalchemy.dialects.postgresql import UUID
|
||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||
|
||
from app.database import Base
|
||
|
||
|
||
class Tenant(Base):
|
||
__tablename__ = "tenants"
|
||
|
||
id: Mapped[uuid.UUID] = mapped_column(
|
||
UUID(as_uuid=True), primary_key=True, default=uuid.uuid4
|
||
)
|
||
slug: Mapped[str] = mapped_column(String(63), nullable=False, unique=True)
|
||
name: Mapped[str] = mapped_column(String(255), nullable=False)
|
||
plan: Mapped[str] = mapped_column(String(50), nullable=False, default="starter")
|
||
is_active: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)
|
||
max_mailboxes: Mapped[int] = mapped_column(Integer, nullable=False, default=5)
|
||
max_users: Mapped[int] = mapped_column(Integer, nullable=False, default=10)
|
||
created_at: Mapped[datetime] = mapped_column(
|
||
DateTime(timezone=True), nullable=False, server_default=func.now()
|
||
)
|
||
updated_at: Mapped[datetime] = mapped_column(
|
||
DateTime(timezone=True), nullable=False, server_default=func.now(), onupdate=func.now()
|
||
)
|
||
|
||
# Relazioni
|
||
users: Mapped[list["User"]] = relationship( # noqa: F821
|
||
"User", back_populates="tenant", cascade="all, delete-orphan"
|
||
)
|
||
mailboxes: Mapped[list["Mailbox"]] = relationship( # noqa: F821
|
||
"Mailbox", back_populates="tenant", cascade="all, delete-orphan"
|
||
)
|
||
|
||
__table_args__ = (
|
||
Index("idx_tenants_slug", "slug"),
|
||
)
|
||
|
||
def __repr__(self) -> str:
|
||
return f"<Tenant {self.slug!r} ({self.plan})>"
|