feat(B-HOOK): Lifecycle Hooks + Outbox Events — 55 neue Hooks, 10 Domain Events
Check Cross-Plugin Imports / check (push) Has been cancelled
Check Cross-Plugin Imports / check (push) Has been cancelled
B-HOOK-CORE: Company Hooks (6: before/after create/update/delete) B-HOOK-MAIL: Mail Hooks (5: after_receive, before/after_delete, before/after_move) B-HOOK-DMS: DMS Hooks (10: after_upload, before/after_update/delete/restore, folder CRUD) B-HOOK-CAL: Calendar Hooks (4: before/after update/delete) B-HOOK-TASK: Task Hooks (6: before/after create/update/delete) B-HOOK-COMM: Communication Hooks (8: conversation create, message/edit/delete) B-HOOK-AI: Agent Hooks (2: before/after_run) B-HOOK-WF: Workflow Hooks (4: before/after_start, after_complete/cancel) B-HOOK-TAG: Tag Hooks (8: create/assign/unassign/delete) B-HOOK-SEARCH: Search Filters (2: before/after_search) B-EVT-OUTBOX: 10 Domain Events (task.completed, file.created/deleted/restored, mail.received, workflow.started/completed/cancelled, agent.run_started/completed) B-HOOK-TEST: 79 Tests in test_lifecycle_hooks.py — alle grün B-HOOK-DOC: Plugin-Dev-Guide Kapitel 8 aktualisiert (Hook-Liste + Outbox Event-Liste)
This commit is contained in:
@@ -101,6 +101,8 @@ async def create_task(
|
||||
data: dict[str, Any],
|
||||
) -> dict[str, Any]:
|
||||
"""Create a new task."""
|
||||
from app.core.hooks import do_action
|
||||
await do_action("task.before_create", data, db=db, tenant_id=tenant_id, user_id=user_id)
|
||||
task = Task(
|
||||
tenant_id=tenant_id,
|
||||
title=data["title"],
|
||||
@@ -116,6 +118,9 @@ async def create_task(
|
||||
db.add(task)
|
||||
await db.flush()
|
||||
|
||||
from app.core.hooks import do_action
|
||||
await do_action("task.after_create", _task_to_dict(task), db=db, tenant_id=tenant_id, user_id=user_id)
|
||||
|
||||
# Publish task.created event
|
||||
from app.core.event_bus import get_event_bus
|
||||
event_bus = get_event_bus()
|
||||
@@ -144,6 +149,8 @@ async def update_task(
|
||||
if task is None:
|
||||
return None
|
||||
|
||||
from app.core.hooks import do_action
|
||||
await do_action("task.before_update", data, db=db, tenant_id=tenant_id, task_id=str(task_id))
|
||||
if "title" in data and data["title"] is not None:
|
||||
task.title = data["title"]
|
||||
if "description" in data:
|
||||
@@ -161,6 +168,8 @@ async def update_task(
|
||||
|
||||
await db.flush()
|
||||
await db.refresh(task)
|
||||
from app.core.hooks import do_action
|
||||
await do_action("task.after_update", _task_to_dict(task), db=db, tenant_id=tenant_id, task_id=str(task_id))
|
||||
return _task_to_dict(task)
|
||||
|
||||
|
||||
@@ -172,8 +181,12 @@ async def delete_task(db: AsyncSession, tenant_id: uuid.UUID, task_id: uuid.UUID
|
||||
task = result.scalar_one_or_none()
|
||||
if task is None:
|
||||
return False
|
||||
from app.core.hooks import do_action
|
||||
await do_action("task.before_delete", db=db, tenant_id=tenant_id, task_id=str(task_id))
|
||||
task.deleted_at = datetime.now(timezone.utc)
|
||||
await db.flush()
|
||||
from app.core.hooks import do_action
|
||||
await do_action("task.after_delete", db=db, tenant_id=tenant_id, task_id=str(task_id))
|
||||
return True
|
||||
|
||||
|
||||
@@ -210,6 +223,9 @@ async def update_task_status(
|
||||
return None
|
||||
task.status = new_status
|
||||
await db.flush()
|
||||
if new_status == "done":
|
||||
from app.core.outbox import enqueue_outbox_event
|
||||
await enqueue_outbox_event(db, tenant_id, "task.completed", {"task_id": str(task.id), "tenant_id": str(tenant_id), "title": task.title, "assigned_to": str(task.assigned_to) if task.assigned_to else None}, aggregate_type="task", aggregate_id=task.id)
|
||||
return _task_to_dict(task)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user