fix(i-c): BUG-036 behoben — Workflow-Instances GET lieferte 500 auf jeden Aufruf (Route übergab user_id/is_system_admin die die Service-Signatur nicht akzeptierte → TypeError); Service um optionale User-Filterung erweitert (Nicht-Admins sehen nur eigene Instanzen via initiated_by, Admins alle); Beweistest test_bug036_instances.py 2/2 grün
This commit is contained in:
@@ -401,14 +401,25 @@ async def list_instances(
|
||||
page: int = 1,
|
||||
page_size: int = 20,
|
||||
status_filter: str | None = None,
|
||||
user_id: uuid.UUID | None = None,
|
||||
is_system_admin: bool = False,
|
||||
) -> dict[str, Any]:
|
||||
"""List workflow instances with optional status filter."""
|
||||
"""List workflow instances with optional status filter.
|
||||
|
||||
BUG-036 fix: the route passed ``user_id``/``is_system_admin`` which this
|
||||
signature did not accept -> TypeError -> 500 on every call.
|
||||
|
||||
Non-admin users see only instances they initiated; admins/system admins
|
||||
see all instances of the tenant.
|
||||
"""
|
||||
page = max(1, page)
|
||||
page_size = max(1, min(100, page_size))
|
||||
|
||||
base = select(WorkflowInstance).where(WorkflowInstance.tenant_id == tenant_id)
|
||||
if status_filter:
|
||||
base = base.where(WorkflowInstance.status == status_filter)
|
||||
if not is_system_admin and user_id is not None:
|
||||
base = base.where(WorkflowInstance.initiated_by == user_id)
|
||||
|
||||
count_q = select(func.count()).select_from(base.subquery())
|
||||
total_result = await db.execute(count_q)
|
||||
|
||||
Reference in New Issue
Block a user