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>
2.7 KiB
2.7 KiB
Phase 6: PDF & Polish — Subplan
Goal
Deliver PDF health-compilation generation (WeasyPrint + AI tool), admin user management CRUD, admin app settings with self-registration toggle, and generated_pdfs tracking.
Prerequisites
- Phase 5 completed (notifications, scheduler, all AI tools except generate_pdf)
Tasks
A. Backend Models & Migration (Tasks 1–3)
- A1. Create
backend/app/models/setting.py: Setting model (key PK, value JSONB, updated_by, updated_at). - A2. Create
backend/app/models/generated_pdf.py: GeneratedPdf model (user_id, title, storage_path, source_document_ids, source_chat_id). - A3. Create migration
006. Seed default settings. Updatemodels/__init__.py+ User relationships.
B. Backend Schemas (Tasks 4–5)
- B4. Create
backend/app/schemas/setting.pyandbackend/app/schemas/pdf.py. - B5. Create
backend/app/schemas/admin.py(AdminUserResponse, AdminUserCreateRequest, AdminUserUpdateRequest).
C. Backend Services (Tasks 6–10)
- C6. Add
weasyprint,jinja2to pyproject.toml. Update Dockerfile for WeasyPrint deps. - C7. Create
backend/app/services/pdf_service.py+ HTML template. - C8. Create
backend/app/services/setting_service.py. - C9. Create
backend/app/services/admin_user_service.py. - C10. Wire
self_registration_enabledcheck into auth register endpoint.
D. Backend API (Tasks 11–13)
- D11. Create
backend/app/api/v1/pdf.py: compile, list, download. Register in router. - D12. Extend
backend/app/api/v1/admin.py: users CRUD + settings endpoints. - D13. Add
generate_pdfAI tool to ai_service.py.
E. Frontend (Tasks 14–19)
- E14. Create
frontend/src/api/pdf.ts. Extendadmin.tswith user/settings functions. - E15. Create
frontend/src/pages/admin/users.tsx. - E16. Create
frontend/src/pages/admin/settings.tsx. - E17. Create
frontend/src/pages/pdf.tsx. - E18. Update routes + sidebar (PDF nav, admin users/settings).
- E19. Update en/ru translations.
F. Tests & Verification (Tasks 20–21)
- F20. Create backend tests: test_pdf.py, test_admin_users.py, test_settings.py.
- F21. Verify frontend builds cleanly.
Acceptance Criteria
- PDF compilation generates downloadable PDF from documents + memory
- AI tool
generate_pdfworks in chat - Admin can CRUD users (role, max_chats, is_active)
- Admin can manage app settings (self_registration_enabled, default_max_chats)
- Registration respects self_registration_enabled setting
- Frontend admin pages + PDF page functional
- All UI text in English and Russian
- Backend tests pass, frontend builds clean
Status
COMPLETED