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
57 lines
1.2 KiB
Python
57 lines
1.2 KiB
Python
"""
|
|
Utility per paginazione standardizzata nelle API.
|
|
"""
|
|
|
|
from typing import Generic, TypeVar
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
T = TypeVar("T")
|
|
|
|
DEFAULT_PAGE_SIZE = 25
|
|
MAX_PAGE_SIZE = 100
|
|
|
|
|
|
class PaginationParams(BaseModel):
|
|
page: int = Field(default=1, ge=1, description="Numero di pagina (1-based)")
|
|
page_size: int = Field(
|
|
default=DEFAULT_PAGE_SIZE,
|
|
ge=1,
|
|
le=MAX_PAGE_SIZE,
|
|
description=f"Elementi per pagina (max {MAX_PAGE_SIZE})",
|
|
)
|
|
|
|
@property
|
|
def offset(self) -> int:
|
|
return (self.page - 1) * self.page_size
|
|
|
|
@property
|
|
def limit(self) -> int:
|
|
return self.page_size
|
|
|
|
|
|
class PaginatedResponse(BaseModel, Generic[T]):
|
|
"""Risposta paginata generica."""
|
|
items: list[T]
|
|
total: int
|
|
page: int
|
|
page_size: int
|
|
pages: int
|
|
|
|
@classmethod
|
|
def create(
|
|
cls,
|
|
items: list[T],
|
|
total: int,
|
|
params: PaginationParams,
|
|
) -> "PaginatedResponse[T]":
|
|
import math
|
|
pages = math.ceil(total / params.page_size) if params.page_size > 0 else 0
|
|
return cls(
|
|
items=items,
|
|
total=total,
|
|
page=params.page,
|
|
page_size=params.page_size,
|
|
pages=pages,
|
|
)
|