Commit Graph

852 Commits

Author SHA1 Message Date
Agent Zero 310a9f0542 Phase 6: Workspaces — Widget CRUD, Manager-Check, Cross-Tenant, Zustand Store, Settings Route
Backend:
- Widget CRUD: get_widgets, create_widget, update_widget, delete_widget
- Manager role check: is_workspace_manager
- Cross-tenant validation: verify_user_same_tenant (UserTenant)
- Default workspace seeding: seed_default_workspace with 12 standard modules
- Set user default workspace: set_user_default_workspace
- Fix create_workspace default uniqueness (unset others before insert)
- Widget CRUD routes: GET/POST/PUT/DELETE /{workspace_id}/widgets
- Set-default route: POST /{workspace_id}/set-default
- Cross-tenant validation in assign_user route

Frontend:
- workspaceStore (Zustand): central state with sessionStorage persistence
- API client interceptor: X-Workspace-ID header on all requests
- useWorkspace hook refactored to use workspaceStore
- Widget API hooks: useWorkspaceWidgets, useCreateWorkspaceWidget, etc.
- useSetDefaultWorkspace hook
- Settings route: /settings/workspaces with WorkspaceManagerPage
- Settings nav item for Workspaces

Tests:
- 25 backend tests (CRUD, modules, widgets, users, manager, seeding, context, isolation)
- 12 frontend tests (workspaceStore state, visibility, persistence, reset)
- 48/48 backend tests passing
- 12/12 frontend tests passing
2026-08-03 03:39:27 +02:00
Agent Zero 236f0d2a5d deploy.py: create_api_application ueber /applications/private-deploy-key (Git-basiert) 2026-08-03 02:18:23 +02:00
Agent Zero 95972d2cdd deploy.py: --initial mit API-UUID fuer Worker-Image und Deploy 2026-08-03 02:16:31 +02:00
Agent Zero 0c789f7660 deploy.py: create_api_application ueber /applications/dockerfile (base64) 2026-08-03 02:10:38 +02:00
Agent Zero cd48d99c65 deploy.py: --initial Modus fuer vollautomatische Erstinstallation ueber Coolify API 2026-08-03 02:05:19 +02:00
Agent Zero f775405a01 deploy.py: 409 Conflict Handling (POST -> PATCH bei existierenden ENVs) 2026-08-03 01:32:41 +02:00
Agent Zero 7e5e0dd8bd deploy.py: ENV-Variablen ueber Coolify API setzen, keine manuelle .env-Datei mehr 2026-08-03 01:30:03 +02:00
Agent Zero 8ac90e4dd6 deploy.py: .env nach update_service schreiben + _wait_service_healthy Bug fix 2026-08-03 01:22:44 +02:00
Agent Zero 5eec2fdde8 deploy.py: ENV-Variablen statt hardcoded Passwoerter + .env auf Server schreiben 2026-08-03 01:17:25 +02:00
Agent Zero c63ab9b45a Fix deploy.py: Use /deploy endpoint for Worker Service + connect_to_docker_network 2026-08-03 01:00:02 +02:00
Agent Zero 2b50f528f3 Fix deploy.py: head -1 statt tail -1 fuer Image-Tag (neuestes Image zuerst) 2026-08-03 00:47:30 +02:00
Agent Zero bb6ea4001a Update SANIERUNGS_FORTSCHRITT.md: Phase 5 produktionsverifiziert 2026-08-03 00:13:49 +02:00
Agent Zero ceb06600c5 Fix deploy.py: Worker-Deploy repariert
- Tag :latest auf neuestes Commit-Image (Coolify taggt mit Hash, nicht latest)
- Verbinde Worker mit coolify Netzwerk nach Restart (für Redis/Postgres DNS)
- Kein update_service mehr (überschreibt Coolify-Konfiguration)
- Worker-Compose auf Server korrigiert (coolify Netzwerk in Service-Definition)
2026-08-03 00:12:00 +02:00
Agent Zero e2b3cf081b Fix deploy.py: Worker-Deploy war kaputt
- Bug 1: WORKER_COMPOSE_YAML hatte PW Platzhalter statt echter Passwörter
- Bug 2: deploy_worker rief deploy_application auf Service-UUID auf (falsche API)
- Bug 3: verify_worker_service akzeptierte nicht running:healthy Status
- Fix: Echte Passwörter, update_service+restart statt deploy_application, Status-Check korrigiert
2026-08-02 23:57:16 +02:00
Agent Zero 74936b3972 Phase 5 (v2): Processing-Recovery, Retention-Cleanup, Replay-Delivery-Reset
- recover_stuck_events: Reset processing events stuck >120s back to pending
- cleanup_published_events: Delete published events older than 30 days
- Replay now resets outbox_deliveries for clean retry
- Worker: hourly retention cleanup cron job
- API: /recover-stuck and /cleanup-published endpoints
- process_outbox_batch: auto-recovery at start of each tenant iteration
- 23/23 tests passing (5 new tests)
2026-08-02 23:47:29 +02:00
Agent Zero 4b0d32f8f0 Update SANIERUNGS_FORTSCHRITT.md: Phase 5 abgeschlossen 2026-08-02 23:29:21 +02:00
Agent Zero 07a99975ec Phase 5: Outbox DLQ, Monitoring, Consumer-Registry
- Migration 0092: DLQ columns (error_message, failed_at) + consumer_inbox RLS fix
- outbox.py: DLQ logic, replay functions, stats, consumer registry
- app/routes/outbox.py: 5 API endpoints (stats, failed, replay, replay-all, consumer-registry)
- outbox_deliveries tracking per consumer handler
- 18/18 tests passing
2026-08-02 23:25:54 +02:00
Agent Zero 24cb10a7a2 docs: SANIERUNGS_FORTSCHRITT.md — kompakter Fortschritts-Tracker
- Phasen-Status: Phase 0-3 abgeschlossen, 4-10 offen
- Gates: Alle 5 bestanden
- Produktions-Setup: Coolify Ressourcen, DB-Rollen, Volumes
- Deployment: deploy.py Befehle dokumentiert
- Wichtige Dateien und Regeln für nächsten Agenten
- Was erledigt ist und was als nächstes zu tun ist
2026-08-02 23:05:33 +02:00
Agent Zero dfd9e778c5 test: Phase 3 — Plugin lifecycle tests (14/14 passed)
Tests:
- Registry initialization and engine requirement
- Plugin registration and discovery
- Load order with and without dependencies
- Core plugin deactivation blocked
- Deactivation blocked by active dependents
- Event handler registration on activate
- Event handler unregistration on deactivate
- Activate → deactivate → reactivate cycle
- Idempotent activate when already active
- Idempotent deactivate when already inactive

Phase 3 (Plugin-Lifecycle) verified:
- install: idempotent, dependency checks, migrations via crm_migration
- activate: idempotent, per-tenant with RLS context, event handlers
- deactivate: idempotent, core protection, dependency check, handler cleanup
- uninstall: deactivate first, then optional drop tables
- main.py: per-tenant activation with set_tenant_context
- Worker: event handlers only for active plugins (Gate 5)
- Router: only in API, not in worker
2026-08-01 23:29:20 +02:00
Agent Zero 745bc4f2d8 feat: Phase 2 — Migration 0091: FK-Constraints für 74 Tenant-Tabellen
- 74 Tabellen erhalten FOREIGN KEY (tenant_id) REFERENCES tenants(id) ON DELETE CASCADE
- 10 globale Tabellen ausgeschlossen (sequences, system_settings, currencies, etc.)
- Orphan-Cleanup: SET tenant_id = NULL für verwaiste Einträge
- Idempotent: IF NOT EXISTS für alle Constraints
- Downgrade: Drop aller FK-Constraints
2026-08-01 23:04:15 +02:00
Agent Zero a922408e49 fix: add Origin header to login test in deploy.py 2026-08-01 21:23:52 +02:00
Agent Zero b3f40bacd2 fix: deploy.py rewrite — everything via Coolify API, no manual docker 2026-08-01 21:22:55 +02:00
Agent Zero a7b3424eee docs: Vollständige Installationsanleitung (INSTALL.md)
- Komplette Schritt-für-Schritt-Installation von Grund auf
- Alle DB-Rollen und Bootstrap-Reihenfolge dokumentiert
- Alle ENV-Variablen für API, Worker, DB dokumentiert
- Vollständige docker-compose.yml Referenz
- Coolify-Setup-Anleitung
- prestart.sh Startup-Ablauf
- seed_admin.py Admin-Erstellung
- Verifikationsschritte (Health, Login, Alembic, RLS, DDL)
- SMTP-Konfiguration
- Backup und Restore mit Grant-Hinweis
- Häufige Probleme und Lösungen
- Architektur-Übersicht und Datei-Struktur
2026-08-01 20:37:53 +02:00
Agent Zero be20a8545e docs: Abschlussbericht Phase 0+1 und vollständiger Sanierungsplan
- Kompletter Statusbericht mit allen 5 Gates
- Datenbankrollen-Architektur dokumentiert
- RLS-Architektur dokumentiert
- Verifizierte Sicherheitsnachweise
- Durchgeführte Code-Änderungen und Migrationen
- Offene Risiken
- Vollständiger Sanierungsplan Phase 2-10
- Gesamtschätzung: 120-210h verbleibend
- Empfohlene Reihenfolge
2026-08-01 07:28:11 +02:00
Agent Zero 733fa1c807 docs: Gate 3 acceptance — restore test verified
Gate 3 (Restore-Test) bestanden:
- Backup aus Forgejo-Release heruntergeladen, MD5 verifiziert
- pg_restore in separate Test-DB (crm_restore_test)
- alembic upgrade head: 0086 → 0090
- Datenintegrität: 9 Contacts, 2 Tenants, 1 User, 479 Sessions
- RLS: 0 rows ohne Kontext, 8 rows Tenant B, 2 rows Tenant A
- Cross-Tenant INSERT blockiert, DDL blockiert
- 108 RLS-Tabellen, 112 Policies, 0 Legacy Policies
2026-08-01 00:27:12 +02:00
Agent Zero 9b4ee3b8ca docs: Gate 5 acceptance — worker event handlers verified
Gate 5 (Worker und Eventhandler) bestanden:
- Worker healthy, verarbeitet Outbox-Jobs und enqueued Jobs
- 18 Worker-Funktionen registriert
- Plugin-Eventhandler nur für aktive Plugins
- Per-Tenant Outbox-Processing mit RLS-Kontext
- Worker verwendet crm_worker (get_worker_session_factory)
- Keine Plugin-Router im Worker
2026-07-31 23:15:32 +02:00
Agent Zero 94847ea515 fix: PluginModel.is_active → PluginModel.active (worker crash fix) 2026-07-31 23:12:05 +02:00
Agent Zero cea21ff576 fix: Gate 5 — worker event handlers and per-tenant outbox processing
Worker fixes:
- registry.initialize uses get_migration_engine() for DDL (not worker_engine)
- Worker session uses get_worker_session_factory() (crm_worker, not crm_api)
- Event handlers only registered for active plugins (is_active check)
- Outbox processing per-tenant with set_config(app.current_tenant_id)
- process_outbox_job uses get_worker_session_factory() and loads tenant_ids
- Removed unused get_engine import

Outbox fixes:
- process_outbox_batch iterates over tenants, sets RLS context per tenant
- _process_single_outbox_event extracted for clarity
- Events claimed per-tenant (RLS-compatible, no BYPASSRLS needed)
- Commit after each tenant to release locks

Gate 5 requirements met:
- Plugin event handlers registered for active plugins only
- No plugin routers registered in worker
- Outbox events without handlers marked as no_handlers
- Failed consumers trigger retry with exponential backoff
- Processing is idempotent (consumer_inbox check)
- Every worker DB access sets app.current_tenant_id
- Worker cannot read/write other tenant data (RLS enforced)
2026-07-31 23:09:25 +02:00
Agent Zero 89fe7a4750 docs: Gate 2 acceptance — fresh DB install verified
Gate 2 (Neuinstallation auf leerer Datenbank) bestanden:
- Alembic-Head 0090, 124 Tabellen, 47 RLS-Tabellen
- 0 legacy app.tenant_id policies
- Alle 4 DB-Rollen korrekt (NOSUPERUSER, crm_migration BYPASSRLS)
- RLS fail-closed: 0 rows ohne Kontext
- Cross-Tenant INSERT blockiert
- crm_api DDL blockiert
- seed_admin.py funktioniert
- Login erfolgreich (200 OK)
- Keine manuellen Schemaänderungen
2026-07-31 22:33:07 +02:00
Agent Zero 89b775b9ef fix: legacy app.tenant_id policies on _old tables + seed_admin.py rewrite
- Migration 0090: Drop legacy tenant_isolation policies on companies_old,
  company_contacts_old, contacts_old that used app.tenant_id variable.
  Create new policies using app.current_tenant_id for crm_api/crm_worker.
- seed_admin.py: Rewrite to use migration engine (crm_migration) for
  bootstrap, set tenant context, create Tenant + Role + User + UserTenant.
  No longer passes tenant_id as User parameter.

Fixes: 3 legacy app.tenant_id policies found in Gate 2 verification.
Fixes: seed_admin.py incompatible with current User model.
2026-07-31 22:23:38 +02:00
Agent Zero b5191f0d11 gate2: migration 0089 — add updated_at to sessions table (model uses TimestampMixin but table was missing column) 2026-07-31 22:15:29 +02:00
Agent Zero 569476b993 gate2: fix prestart.sh shell quote conflict — use temp Python file instead of python3 -c 2026-07-31 21:57:04 +02:00
Agent Zero 68db50544c gate2: fix shell quote conflict in prestart.sh — use string concat instead of f-string for ALTER ROLE 2026-07-31 21:49:45 +02:00
Agent Zero 2a7412e49f gate2: fix prestart.sh — inline password for ALTER ROLE (prepared statements dont work with ALTER ROLE) 2026-07-31 21:42:55 +02:00
Agent Zero 9124b17a8e gate2: prestart.sh sets passwords for all DB roles (crm_api, crm_auth, crm_worker, crm_migration) after migration
Migration 0070 creates roles without passwords. On fresh DB, API cannot authenticate.
prestart.sh now extracts password from MIGRATION_DATABASE_URL and sets it for all roles.
2026-07-31 21:31:18 +02:00
Agent Zero 10296137e9 gate2: fix migration 0085 — revoke default privileges before dropping crm_runtime, handle dependent_objects_still_exist 2026-07-31 21:20:59 +02:00
Agent Zero 48ddd78e9e gate2: fix mail plugin migration 0009 — guard UPDATE for missing deleted_at column on fresh DB
Check Cross-Plugin Imports / check (push) Has been cancelled
2026-07-31 20:56:06 +02:00
Agent Zero 4a5c905934 P0-fix: plugin migrations use migration engine (crm_migration) instead of API engine (crm_api)
Check Cross-Plugin Imports / check (push) Has been cancelled
- main.py: registry.initialize(get_migration_engine()) instead of get_engine()
- main.py: plugin migrations run via get_migration_session_factory() not async_session()
- registry.py: upgrade_plugin, install_plugin, uninstall_plugin all use migration session for DDL
- db/__init__.py: get_migration_engine() raises RuntimeError if MIGRATION_DATABASE_URL missing (no fallback)
- Fixes fresh-install failure: crm_api has no DDL rights, plugin migrations need crm_migration
2026-07-31 20:45:16 +02:00
Agent Zero 010ef448e7 gate2: fix all migrations for fresh DB installation 2026-07-31 19:16:11 +02:00
Agent Zero d37388423d gate2: fix ix_contacts_tenant_id conflict — drop old index before recreate in 0021 2026-07-31 18:51:15 +02:00
Agent Zero e43a906cde gate2: fix ix_contacts_tenant_id duplicate (index=True in 0021 vs create_index in 0002) 2026-07-31 18:34:35 +02:00
Agent Zero dd7ad461d8 gate2: fix duplicate column/index in migrations for fresh DB installation 2026-07-31 18:20:09 +02:00
Agent Zero 224a5ea9af gate2: fix migration 0019 duplicate deleted_at on roles (IF NOT EXISTS) 2026-07-31 17:50:07 +02:00
Agent Zero 3f3ef28264 gate: final acceptance report — Gate 1 + Gate 4 passed, Gate 2/3/5 open 2026-07-31 12:07:04 +02:00
Agent Zero 3032ad2cbf gate4: migration 0088 — auth RLS policies for password_reset_tokens and audit_log 2026-07-31 12:04:27 +02:00
Agent Zero a303a4e455 gate4: use separate API session for audit log in confirm_password_reset 2026-07-31 12:01:11 +02:00
Agent Zero a721db5214 gate4: set tenant context before audit log in confirm_password_reset 2026-07-31 11:58:11 +02:00
Agent Zero ce0e9ab12a gate4: fix SMTP TLS mode for port 465 (implicit TLS instead of STARTTLS) 2026-07-31 11:37:11 +02:00
Agent Zero 31408670e6 gate4: register app.core.jobs in worker for send_password_reset_email 2026-07-31 11:32:47 +02:00
Agent Zero ebc63beeb4 gate1: fix npm peer dependency conflict with --legacy-peer-deps 2026-07-31 11:19:53 +02:00