Phase 6: PDF & Polish — PDF generation, admin users/settings, AI tool

Backend:
- Setting + GeneratedPdf models, Alembic migration with default settings seed
- PDF generation service (WeasyPrint + Jinja2 with autoescape)
- Health report HTML template with memory entries + document excerpts
- Admin user management: list, create, update (role/max_chats/is_active)
- Admin settings: self_registration_enabled, default_max_chats
- Self-registration check wired into auth register endpoint
- default_max_chats applied to new user registrations
- AI tool: generate_pdf creates health compilation PDFs
- PDF compile/list/download API endpoints
- WeasyPrint system deps added to Dockerfile

Frontend:
- PDF reports page with generate + download
- Admin users page with create/edit/activate/deactivate
- Admin settings page with self-registration toggle + max chats
- Extended sidebar with PDF reports + admin users/settings links
- English + Russian translations for all new UI

Review fixes applied:
- Jinja2 autoescape enabled (XSS prevention in PDFs)
- db.refresh after flush (created_at populated correctly)
- storage_path removed from API response (no internal path leak)
- Role field uses Literal["user", "admin"] validation
- React hooks called before conditional returns (rules of hooks)
- default_max_chats setting now applied during registration

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-19 14:37:43 +03:00
parent 04e3ae8319
commit fed6a3df1b
33 changed files with 1219 additions and 10 deletions

View File

@@ -0,0 +1,40 @@
import uuid
from datetime import datetime
from typing import Literal
from pydantic import BaseModel, EmailStr, Field
class AdminUserResponse(BaseModel):
id: uuid.UUID
email: str
username: str
full_name: str | None
role: str
is_active: bool
max_chats: int
created_at: datetime
model_config = {"from_attributes": True}
class AdminUserCreateRequest(BaseModel):
email: EmailStr
username: str = Field(min_length=3, max_length=50, pattern=r"^[a-zA-Z0-9_-]+$")
password: str = Field(min_length=8, max_length=128)
full_name: str | None = None
role: Literal["user", "admin"] = "user"
max_chats: int = 10
class AdminUserUpdateRequest(BaseModel):
role: Literal["user", "admin"] | None = None
is_active: bool | None = None
max_chats: int | None = None
full_name: str | None = None
class AdminUserListResponse(BaseModel):
users: list[AdminUserResponse]
total: int

View File

@@ -0,0 +1,25 @@
import uuid
from datetime import datetime
from pydantic import BaseModel, Field
class GeneratePdfRequest(BaseModel):
title: str = Field(min_length=1, max_length=255)
document_ids: list[uuid.UUID] = []
chat_id: uuid.UUID | None = None
class PdfResponse(BaseModel):
id: uuid.UUID
user_id: uuid.UUID
title: str
source_document_ids: list[uuid.UUID] | None
source_chat_id: uuid.UUID | None
created_at: datetime
model_config = {"from_attributes": True}
class PdfListResponse(BaseModel):
pdfs: list[PdfResponse]

View File

@@ -0,0 +1,20 @@
import uuid
from datetime import datetime
from pydantic import BaseModel
class SettingResponse(BaseModel):
key: str
value: dict | bool | int | str
updated_at: datetime
model_config = {"from_attributes": True}
class UpdateSettingRequest(BaseModel):
value: dict | bool | int | str
class SettingsListResponse(BaseModel):
settings: list[SettingResponse]