Files
personal-ai-assistant/plans/phase-6-pdf-polish.md
dolgolyov.alexei fed6a3df1b 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>
2026-03-19 14:37:43 +03:00

2.7 KiB
Raw Blame History

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 13)

  • 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. Update models/__init__.py + User relationships.

B. Backend Schemas (Tasks 45)

  • B4. Create backend/app/schemas/setting.py and backend/app/schemas/pdf.py.
  • B5. Create backend/app/schemas/admin.py (AdminUserResponse, AdminUserCreateRequest, AdminUserUpdateRequest).

C. Backend Services (Tasks 610)

  • C6. Add weasyprint, jinja2 to 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_enabled check into auth register endpoint.

D. Backend API (Tasks 1113)

  • 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_pdf AI tool to ai_service.py.

E. Frontend (Tasks 1419)

  • E14. Create frontend/src/api/pdf.ts. Extend admin.ts with 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 2021)

  • F20. Create backend tests: test_pdf.py, test_admin_users.py, test_settings.py.
  • 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