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:
71
plans/phase-6-pdf-polish.md
Normal file
71
plans/phase-6-pdf-polish.md
Normal file
@@ -0,0 +1,71 @@
|
||||
# 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)
|
||||
|
||||
- [x] **A1.** Create `backend/app/models/setting.py`: Setting model (key PK, value JSONB, updated_by, updated_at).
|
||||
- [x] **A2.** Create `backend/app/models/generated_pdf.py`: GeneratedPdf model (user_id, title, storage_path, source_document_ids, source_chat_id).
|
||||
- [x] **A3.** Create migration `006`. Seed default settings. Update `models/__init__.py` + User relationships.
|
||||
|
||||
### B. Backend Schemas (Tasks 4–5)
|
||||
|
||||
- [x] **B4.** Create `backend/app/schemas/setting.py` and `backend/app/schemas/pdf.py`.
|
||||
- [x] **B5.** Create `backend/app/schemas/admin.py` (AdminUserResponse, AdminUserCreateRequest, AdminUserUpdateRequest).
|
||||
|
||||
### C. Backend Services (Tasks 6–10)
|
||||
|
||||
- [x] **C6.** Add `weasyprint`, `jinja2` to pyproject.toml. Update Dockerfile for WeasyPrint deps.
|
||||
- [x] **C7.** Create `backend/app/services/pdf_service.py` + HTML template.
|
||||
- [x] **C8.** Create `backend/app/services/setting_service.py`.
|
||||
- [x] **C9.** Create `backend/app/services/admin_user_service.py`.
|
||||
- [x] **C10.** Wire `self_registration_enabled` check into auth register endpoint.
|
||||
|
||||
### D. Backend API (Tasks 11–13)
|
||||
|
||||
- [x] **D11.** Create `backend/app/api/v1/pdf.py`: compile, list, download. Register in router.
|
||||
- [x] **D12.** Extend `backend/app/api/v1/admin.py`: users CRUD + settings endpoints.
|
||||
- [x] **D13.** Add `generate_pdf` AI tool to ai_service.py.
|
||||
|
||||
### E. Frontend (Tasks 14–19)
|
||||
|
||||
- [x] **E14.** Create `frontend/src/api/pdf.ts`. Extend `admin.ts` with user/settings functions.
|
||||
- [x] **E15.** Create `frontend/src/pages/admin/users.tsx`.
|
||||
- [x] **E16.** Create `frontend/src/pages/admin/settings.tsx`.
|
||||
- [x] **E17.** Create `frontend/src/pages/pdf.tsx`.
|
||||
- [x] **E18.** Update routes + sidebar (PDF nav, admin users/settings).
|
||||
- [x] **E19.** Update en/ru translations.
|
||||
|
||||
### F. Tests & Verification (Tasks 20–21)
|
||||
|
||||
- [x] **F20.** Create backend tests: test_pdf.py, test_admin_users.py, test_settings.py.
|
||||
- [x] **F21.** Verify frontend builds cleanly.
|
||||
|
||||
---
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
1. PDF compilation generates downloadable PDF from documents + memory
|
||||
2. AI tool `generate_pdf` works in chat
|
||||
3. Admin can CRUD users (role, max_chats, is_active)
|
||||
4. Admin can manage app settings (self_registration_enabled, default_max_chats)
|
||||
5. Registration respects self_registration_enabled setting
|
||||
6. Frontend admin pages + PDF page functional
|
||||
7. All UI text in English and Russian
|
||||
8. Backend tests pass, frontend builds clean
|
||||
|
||||
---
|
||||
|
||||
## Status
|
||||
|
||||
**COMPLETED**
|
||||
Reference in New Issue
Block a user