Adds a DELETE USER button to the edit user modal with a confirmation
dialog. Includes a self-deletion guard on both the frontend and backend.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Password complexity: enforce 12+ chars, uppercase, lowercase, number, and
special character on /setup-password and admin password-reset flow; show
requirements hint on login page
- Data retention: cleanup_old_logs(days=90) purges activity_log and
interactions rows older than 90 days; runs at every startup in lifespan
- PII hashing: add _hash_quote() SHA-256 helper (16-char prefix) for
correlation without storing raw customer text in audit records; activity_log
already stores no raw quotes — helper available for future log calls
- import hashlib added to main.py
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Structured JSON logging (core/logging_config.py):
- Replace ad-hoc print() statements with logger.info/warning/error
- Each log line is one JSON object: timestamp (ISO8601 UTC), level, logger,
message, module, exception traceback, plus user-supplied 'extra' fields
- Quiets uvicorn.access and huggingface_hub noise to WARNING
- Configurable via LOG_LEVEL env var
/health endpoint (public, no auth):
- 200 + {"status":"healthy"} → DB ok, predictor loaded
- 200 + {"status":"degraded", ...} → DB ok, predictor still warming
- 503 + {"status":"unhealthy","reason"} → DB unreachable, restart needed
- Compatible with HF Spaces / Railway / uptime monitors
Fail-fast model loading:
- After download attempt, verify distilbert_stage1 exists on disk
- If missing, raise RuntimeError to prevent app from starting in a broken
state where every /api/predict returns 500 at runtime
- Operators can override with ALLOW_DEGRADED_STARTUP=1 (offline dev, etc.)
- Critical-level log includ…
Rework role hierarchy: admin/manager/staff with granular permissions
Role structure:
- Admin (3): Full access to all pages and operations
- Manager (2): Access all pages + admin panel, but can only add users (not delete)
- Staff (1): Access consultants/analytics/browse (read-only), can save corrections
Changes:
- Rename employee→manager, viewer→staff in role definitions
- Update PAGE_ACCESS to reflect new permissions
- Add admin-only authorization checks on all delete endpoints
- /admin/corrections/delete
- /browse/delete, /browse/edit
- /analytics/delete
- Update admin.html with new role select options (staff/manager/admin)
- Hide delete buttons from non-admin users in corrections table
- Allow managers to access admin navigation link in base.html and home.html
- Add .role-manager CSS styling (blue/purple)
- Update database default role from employee to staff
- Remove obsolete .role-employee CSS selector
Backward compatibility: Existing 'employee' and 'viewer' users need migration:
UPDATE users SET role = 'manager' WHERE role = 'employee';
…
Apply security hardening across FastAPI and Webapp
- Remove hardcoded admin email fallback; require ADMIN_EMAIL env var
- Reduce session lifetime from 3650 days to 30 days
- Set secure=True on session cookies (opt-out via ENVIRONMENT=local)
- Add HTTP security headers middleware (X-Frame-Options, X-Content-Type-Options, HSTS, etc.)
- Require authentication on /api/services and /api/type-cluster-map
- Sanitize 500 error messages to avoid leaking exception details
- Validate role enum on user add/update (whitelist: admin/employee/viewer)
- Add 5000-char limit on prediction quotes; raise password minimum to 8 chars
- Call cleanup_expired_sessions() on startup to prune stale tokens
- Guard admin seed row against empty ADMIN_EMAIL in both databases
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>