# 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**