fix: Event-bus workflow trigger, RBAC on all routes, search provider, events, cron jobs
Critical fixes:
- Event Bus → Workflow auto-trigger: wildcard subscription starts workflows on matching events
- Kommunikation routes: require_permission on all 30+ endpoints (comm:read/write/delete/manage)
- Permissions routes: require_permission('permissions:admin') on all management endpoints
- CompanySearchProvider registered in auto_register_providers()
Medium fixes:
- system_notif events: 10 event_bus.publish() calls added (lead.created, contact.created/updated,
task.created/overdue, mail.received, user.created, workflow.completed, notification.created, backup.*)
- Cron jobs: backup_check (daily), search_index_check (daily), workflow_timeout (5min) registered
- AI tool permission: call_crm_api now requires 'ai:write' permission
- New file: automation/jobs.py with backup_check and search_index_check functions
This commit is contained in:
+15
-3
@@ -61,6 +61,16 @@ class WorkflowEngine:
|
||||
instance.status = "completed"
|
||||
instance.completed_at = datetime.now(UTC)
|
||||
await self.db.flush()
|
||||
|
||||
# Publish workflow.completed event
|
||||
event_bus = get_event_bus()
|
||||
await event_bus.publish('workflow.completed', {
|
||||
'workflow_id': str(instance.workflow_id),
|
||||
'instance_id': str(instance.id),
|
||||
'tenant_id': str(self.tenant_id),
|
||||
'initiated_by': str(instance.initiated_by) if instance.initiated_by else None,
|
||||
})
|
||||
|
||||
return _instance_to_dict(instance)
|
||||
|
||||
step = steps[instance.current_step_index]
|
||||
@@ -284,6 +294,8 @@ def register_workflow_event_handlers() -> None:
|
||||
"""Register event bus handlers for workflow triggers.
|
||||
|
||||
Subscribes to the event bus to auto-start workflows when events fire.
|
||||
Uses a wildcard '*' subscription to catch ALL events and dynamically
|
||||
check which workflows have a matching trigger_event.
|
||||
Should be called during application startup.
|
||||
"""
|
||||
event_bus = get_event_bus()
|
||||
@@ -301,6 +313,6 @@ def register_workflow_event_handlers() -> None:
|
||||
async with create_db_session(tenant_id) as db:
|
||||
await handle_event(db, tenant_id, event_name, payload)
|
||||
|
||||
# Subscribe to common events
|
||||
for event_name in ("user.created", "contact.created"):
|
||||
event_bus.subscribe(event_name, _workflow_event_handler)
|
||||
# Subscribe to ALL events via wildcard '*' — the handler dynamically
|
||||
# queries for workflows whose trigger_event matches the published event.
|
||||
event_bus.subscribe('*', _workflow_event_handler)
|
||||
|
||||
Reference in New Issue
Block a user