Skip to main content

What to fix (prioritised)

Ordered by severity. Each links to the note with the detail.

P0 — integrity & isolation (do first; they invalidate the product's promise)

  1. Move the workflow engine server-side. All transition guards, deadlines, gates, and checklist logic become one transactional server command; RLS forbids direct cases.status writes. → client-side integrity, non-atomic transitions.
  2. Fix storage tenant isolation on case-attachments. → storage isolation.
  3. Close the RLS holes: public companies read, self-provision role escalation, unscoped evidence/gate queries. → RLS & tenancy gaps, self-provision.
  4. Make the audit trail court-grade: server-authored, awaited, unconditional, paginated, append-only, tamper-evident, single stream. → audit not court-grade.
  5. Kill the hardcoded credentials: invite-user temp password, seed-test-data open endpoint, committed .env. Rotate keys. → hardcoded credentials.
  6. Sanitise dossier/document generation (HTML injection). → dossier XSS.
  1. One holiday-aware, timezone-correct working-day calculator; capture legal dates as explicit facts, not click-time. → naive deadline math, legal time vs click time.
  2. Statute-verify and test every legal rule (deadlines, caducidade, consultation, witness caps). → zero tests, domain.
  3. Reconcile the status enum: one canonical set + a legacy→canonical migration. → status generations.
  4. Reconstruct case_phase_deliverables and audit the migration set for other console-created objects. → phantom table.
  5. Separate "document produced" from "obligation verified" (stop auto-approving checklists). → checklist auto-approve.

P2 — model & UX correctness

  1. Per-tenant, normalised RBAC; explicit active-tenant (URL); server-owned provisioning. → role global, company context, signup provisions nothing.
  2. Promote load-bearing JSONB fields to typed columns; unify the two deliverable subsystems. → JSONB state, deliverable subsystems.
  3. Single source for string vocabularies (events, statuses, entity types). → string vocabularies.
  4. Centralise routes; delete dead/stub surfaces (CompanyDashboard, /consulta/:slug, Templates). → broken links.
  5. Reimplement email off Lovable; wire the portal-notification email. → email queue.