AP2.2e: Unplan, Bug/Issue-Referenz und Sprint-Lebenszyklus.
Deploy Development / deploy (push) Successful in 44s
Test Suite / pytest-backend (push) Successful in 2m52s
Test Suite / lint-backend (push) Successful in 2s
Test Suite / compose-smoke (push) Has been skipped
Test Suite / k6 /api/health Baseline (push) Successful in 18s
Test Suite / playwright-smoke (push) Successful in 13s
Deploy Development / deploy (push) Successful in 44s
Test Suite / pytest-backend (push) Successful in 2m52s
Test Suite / lint-backend (push) Successful in 2s
Test Suite / compose-smoke (push) Has been skipped
Test Suite / k6 /api/health Baseline (push) Successful in 18s
Test Suite / playwright-smoke (push) Successful in 13s
Ermöglicht APs zurück in den Eingang zu schieben, Bugs/Issues mit Feature-Bezug zu planen und den Scrum-Sprint-Ablauf in der UI. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
e221b5b09f
commit
e65838118c
21 files changed
+794
-14
No files matched your search
+204
-5
@@ -26,15 +26,25 @@ OPEN_ACTION_STATUSES = frozenset(
|
||||
|
||||
_ACTION_COLUMNS = """
|
||||
id, tenant_id, initiative_id, project_id, roadmap_item_id, work_cycle_id, title, description,
|
||||
status, priority, due_at, sort_order, action_kind, created_at, updated_at
|
||||
status, priority, due_at, sort_order, action_kind, parent_action_id, created_at, updated_at
|
||||
"""
|
||||
|
||||
ACTION_KINDS = frozenset({"delivery", "planning", "review"})
|
||||
ACTION_KINDS = frozenset({"delivery", "planning", "review", "bug", "issue"})
|
||||
UNPLAN_ALLOWED_STATUSES = frozenset({"open", "ready"})
|
||||
|
||||
|
||||
def _serialize_row(row: dict[str, Any]) -> dict[str, Any]:
|
||||
result = dict(row)
|
||||
for key in ("id", "tenant_id", "initiative_id", "project_id", "roadmap_item_id", "work_cycle_id", "owner_actor_id"):
|
||||
for key in (
|
||||
"id",
|
||||
"tenant_id",
|
||||
"initiative_id",
|
||||
"project_id",
|
||||
"roadmap_item_id",
|
||||
"work_cycle_id",
|
||||
"parent_action_id",
|
||||
"owner_actor_id",
|
||||
):
|
||||
if result.get(key):
|
||||
result[key] = str(result[key])
|
||||
if result.get("created_at"):
|
||||
@@ -46,6 +56,42 @@ def _serialize_row(row: dict[str, Any]) -> dict[str, Any]:
|
||||
return result
|
||||
|
||||
|
||||
def _validate_parent_action_in_initiative(
|
||||
*,
|
||||
cur,
|
||||
tenant_id: str,
|
||||
initiative_id: str,
|
||||
parent_action_id: Optional[str],
|
||||
action_id: Optional[str] = None,
|
||||
) -> None:
|
||||
if not parent_action_id:
|
||||
return
|
||||
if action_id and parent_action_id == action_id:
|
||||
raise ValueError("Arbeitspaket kann nicht auf sich selbst verweisen")
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT action_kind
|
||||
FROM actions
|
||||
WHERE id = %s AND tenant_id = %s AND initiative_id = %s
|
||||
""",
|
||||
(parent_action_id, tenant_id, initiative_id),
|
||||
)
|
||||
row = cur.fetchone()
|
||||
if not row:
|
||||
raise ValueError("Referenz-Arbeitspaket (Feature) nicht gefunden")
|
||||
action_kind = row["action_kind"] if isinstance(row, dict) else row[0]
|
||||
if action_kind in ("bug", "issue"):
|
||||
raise ValueError("Referenz muss ein Feature-Arbeitspaket sein, kein Bug/Issue")
|
||||
|
||||
|
||||
def _action_kind_to_item_kind(action_kind: str) -> str:
|
||||
if action_kind == "bug":
|
||||
return "bug"
|
||||
if action_kind == "issue":
|
||||
return "issue"
|
||||
return "story"
|
||||
|
||||
|
||||
def _validate_action_kind(action_kind: str) -> None:
|
||||
if action_kind not in ACTION_KINDS:
|
||||
raise ValueError(f"Ungültiger action_kind: {action_kind}")
|
||||
@@ -149,6 +195,7 @@ def create_action(
|
||||
assigned_actor_ids: Optional[list[str]] = None,
|
||||
sort_order: int = 0,
|
||||
action_kind: str = "delivery",
|
||||
parent_action_id: Optional[str] = None,
|
||||
user_id: Optional[str] = None,
|
||||
) -> dict[str, Any]:
|
||||
title = title.strip()
|
||||
@@ -183,13 +230,20 @@ def create_action(
|
||||
work_cycle_id=work_cycle_id,
|
||||
cur=cur,
|
||||
)
|
||||
_validate_parent_action_in_initiative(
|
||||
cur=cur,
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=initiative_id,
|
||||
parent_action_id=parent_action_id,
|
||||
)
|
||||
cur.execute(
|
||||
f"""
|
||||
INSERT INTO actions (
|
||||
tenant_id, initiative_id, project_id, roadmap_item_id, work_cycle_id,
|
||||
title, description, status, priority, due_at, sort_order, action_kind
|
||||
title, description, status, priority, due_at, sort_order, action_kind,
|
||||
parent_action_id
|
||||
)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
RETURNING {_ACTION_COLUMNS}
|
||||
""",
|
||||
(
|
||||
@@ -205,6 +259,7 @@ def create_action(
|
||||
due_at,
|
||||
sort_order,
|
||||
action_kind,
|
||||
parent_action_id,
|
||||
),
|
||||
)
|
||||
row = _serialize_row(dict(cur.fetchone()))
|
||||
@@ -299,6 +354,8 @@ def update_action(
|
||||
clear_work_cycle: bool = False,
|
||||
sort_order: Optional[int] = None,
|
||||
action_kind: Optional[str] = None,
|
||||
parent_action_id: Optional[str] = None,
|
||||
clear_parent_action: bool = False,
|
||||
) -> Optional[dict[str, Any]]:
|
||||
existing = get_action(tenant_id=tenant_id, action_id=action_id)
|
||||
if not existing:
|
||||
@@ -373,6 +430,11 @@ def update_action(
|
||||
_validate_action_kind(action_kind)
|
||||
updates.append("action_kind = %s")
|
||||
params.append(action_kind)
|
||||
if clear_parent_action:
|
||||
updates.append("parent_action_id = NULL")
|
||||
elif parent_action_id is not None:
|
||||
updates.append("parent_action_id = %s")
|
||||
params.append(parent_action_id)
|
||||
|
||||
if not updates:
|
||||
return existing
|
||||
@@ -383,6 +445,14 @@ def update_action(
|
||||
conn = get_connection()
|
||||
try:
|
||||
with conn.cursor(cursor_factory=RealDictCursor) as cur:
|
||||
if parent_action_id is not None and not clear_parent_action:
|
||||
_validate_parent_action_in_initiative(
|
||||
cur=cur,
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=existing["initiative_id"],
|
||||
parent_action_id=parent_action_id,
|
||||
action_id=action_id,
|
||||
)
|
||||
cur.execute(
|
||||
f"""
|
||||
UPDATE actions
|
||||
@@ -533,3 +603,132 @@ def list_open_actions_for_actor(
|
||||
finally:
|
||||
conn.close()
|
||||
return _attach_assignments(actions, tenant_id=tenant_id)
|
||||
|
||||
|
||||
def unplan_action_to_backlog(
|
||||
*,
|
||||
tenant_id: str,
|
||||
action_id: str,
|
||||
user_id: Optional[str] = None,
|
||||
) -> dict[str, Any]:
|
||||
"""Entfernt ein Arbeitspaket aus dem Sprint und stellt es im Eingang wieder her."""
|
||||
existing = get_action(tenant_id=tenant_id, action_id=action_id)
|
||||
if not existing:
|
||||
raise ValueError("Arbeitspaket nicht gefunden")
|
||||
if existing["status"] not in UNPLAN_ALLOWED_STATUSES:
|
||||
raise ValueError(
|
||||
"Nur offene oder bereite Arbeitspakete können zurück in den Eingang"
|
||||
)
|
||||
|
||||
initiative_id = existing["initiative_id"]
|
||||
item_kind = _action_kind_to_item_kind(existing.get("action_kind") or "delivery")
|
||||
|
||||
conn = get_connection()
|
||||
try:
|
||||
with conn.cursor(cursor_factory=RealDictCursor) as cur:
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT id
|
||||
FROM backlog_items
|
||||
WHERE tenant_id = %s AND converted_action_id = %s
|
||||
""",
|
||||
(tenant_id, action_id),
|
||||
)
|
||||
linked = cur.fetchone()
|
||||
|
||||
if linked:
|
||||
backlog_id = str(linked["id"])
|
||||
cur.execute(
|
||||
"""
|
||||
UPDATE backlog_items
|
||||
SET status = 'accepted',
|
||||
converted_action_id = NULL,
|
||||
title = %s,
|
||||
description = %s,
|
||||
priority = %s,
|
||||
roadmap_item_id = %s,
|
||||
item_kind = %s,
|
||||
parent_action_id = %s,
|
||||
updated_at = NOW()
|
||||
WHERE id = %s AND tenant_id = %s
|
||||
RETURNING id, tenant_id, initiative_id, title, description, status,
|
||||
priority, roadmap_item_id, converted_action_id, sort_order,
|
||||
item_kind, parent_action_id, created_at, updated_at
|
||||
""",
|
||||
(
|
||||
existing["title"],
|
||||
existing.get("description") or "",
|
||||
existing["priority"],
|
||||
existing.get("roadmap_item_id"),
|
||||
item_kind,
|
||||
existing.get("parent_action_id"),
|
||||
backlog_id,
|
||||
tenant_id,
|
||||
),
|
||||
)
|
||||
backlog_row = _serialize_row(dict(cur.fetchone()))
|
||||
else:
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT COALESCE(MAX(sort_order), -10) + 10 AS next_order
|
||||
FROM backlog_items
|
||||
WHERE tenant_id = %s AND initiative_id = %s
|
||||
""",
|
||||
(tenant_id, initiative_id),
|
||||
)
|
||||
next_order = int(cur.fetchone()["next_order"])
|
||||
cur.execute(
|
||||
"""
|
||||
INSERT INTO backlog_items (
|
||||
tenant_id, initiative_id, title, description, status, priority,
|
||||
roadmap_item_id, sort_order, item_kind, parent_action_id
|
||||
)
|
||||
VALUES (%s, %s, %s, %s, 'accepted', %s, %s, %s, %s, %s)
|
||||
RETURNING id, tenant_id, initiative_id, title, description, status,
|
||||
priority, roadmap_item_id, converted_action_id, sort_order,
|
||||
item_kind, parent_action_id, created_at, updated_at
|
||||
""",
|
||||
(
|
||||
tenant_id,
|
||||
initiative_id,
|
||||
existing["title"],
|
||||
existing.get("description") or "",
|
||||
existing["priority"],
|
||||
existing.get("roadmap_item_id"),
|
||||
next_order,
|
||||
item_kind,
|
||||
existing.get("parent_action_id"),
|
||||
),
|
||||
)
|
||||
backlog_row = _serialize_row(dict(cur.fetchone()))
|
||||
|
||||
cur.execute(
|
||||
"""
|
||||
UPDATE actions
|
||||
SET status = 'discarded',
|
||||
work_cycle_id = NULL,
|
||||
updated_at = NOW()
|
||||
WHERE id = %s AND tenant_id = %s
|
||||
RETURNING id, tenant_id, initiative_id, project_id, roadmap_item_id,
|
||||
work_cycle_id, title, description, status, priority, due_at,
|
||||
sort_order, action_kind, parent_action_id, created_at, updated_at
|
||||
""",
|
||||
(action_id, tenant_id),
|
||||
)
|
||||
action_row = _serialize_row(dict(cur.fetchone()))
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
action_result = get_action(tenant_id=tenant_id, action_id=action_id)
|
||||
log_audit(
|
||||
"action.unplanned_to_backlog",
|
||||
user_id=user_id,
|
||||
tenant_id=tenant_id,
|
||||
details={
|
||||
"action_id": action_id,
|
||||
"backlog_item_id": backlog_row["id"],
|
||||
"initiative_id": initiative_id,
|
||||
},
|
||||
)
|
||||
return {"backlog_item": backlog_row, "action": action_result or action_row}
|
||||
@@ -13,18 +13,28 @@ from services.initiatives import PRIORITIES, get_initiative
|
||||
from services.plan_ist import validate_roadmap_item_in_initiative
|
||||
|
||||
BacklogStatus = Literal["new", "triaged", "accepted", "rejected", "converted"]
|
||||
BacklogItemKind = Literal["story", "bug", "issue"]
|
||||
|
||||
BACKLOG_STATUSES = frozenset({"new", "triaged", "accepted", "rejected", "converted"})
|
||||
BACKLOG_ITEM_KINDS = frozenset({"story", "bug", "issue"})
|
||||
|
||||
_BACKLOG_COLUMNS = """
|
||||
id, tenant_id, initiative_id, title, description, status,
|
||||
priority, roadmap_item_id, converted_action_id, sort_order, created_at, updated_at
|
||||
priority, roadmap_item_id, converted_action_id, sort_order, item_kind,
|
||||
parent_action_id, created_at, updated_at
|
||||
"""
|
||||
|
||||
|
||||
def _serialize_row(row: dict[str, Any]) -> dict[str, Any]:
|
||||
result = dict(row)
|
||||
for key in ("id", "tenant_id", "initiative_id", "converted_action_id", "roadmap_item_id"):
|
||||
for key in (
|
||||
"id",
|
||||
"tenant_id",
|
||||
"initiative_id",
|
||||
"converted_action_id",
|
||||
"roadmap_item_id",
|
||||
"parent_action_id",
|
||||
):
|
||||
if result.get(key):
|
||||
result[key] = str(result[key])
|
||||
if result.get("created_at"):
|
||||
@@ -44,6 +54,44 @@ def _validate_priority(priority: str) -> None:
|
||||
raise ValueError(f"Ungültige Priorität: {priority}")
|
||||
|
||||
|
||||
def _validate_item_kind(item_kind: str) -> None:
|
||||
if item_kind not in BACKLOG_ITEM_KINDS:
|
||||
raise ValueError(f"Ungültiger Backlog-Typ: {item_kind}")
|
||||
|
||||
|
||||
def _item_kind_to_action_kind(item_kind: str) -> str:
|
||||
if item_kind == "bug":
|
||||
return "bug"
|
||||
if item_kind == "issue":
|
||||
return "issue"
|
||||
return "delivery"
|
||||
|
||||
|
||||
def _validate_parent_action_in_initiative(
|
||||
*,
|
||||
cur,
|
||||
tenant_id: str,
|
||||
initiative_id: str,
|
||||
parent_action_id: Optional[str],
|
||||
) -> None:
|
||||
if not parent_action_id:
|
||||
return
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT action_kind, parent_action_id
|
||||
FROM actions
|
||||
WHERE id = %s AND tenant_id = %s AND initiative_id = %s
|
||||
""",
|
||||
(parent_action_id, tenant_id, initiative_id),
|
||||
)
|
||||
row = cur.fetchone()
|
||||
if not row:
|
||||
raise ValueError("Referenz-Arbeitspaket (Feature) nicht gefunden")
|
||||
action_kind = row["action_kind"] if isinstance(row, dict) else row[0]
|
||||
if action_kind in ("bug", "issue"):
|
||||
raise ValueError("Referenz muss ein Feature-Arbeitspaket sein, kein Bug/Issue")
|
||||
|
||||
|
||||
def create_backlog_item(
|
||||
*,
|
||||
tenant_id: str,
|
||||
@@ -54,6 +102,8 @@ def create_backlog_item(
|
||||
priority: str = "normal",
|
||||
roadmap_item_id: Optional[str] = None,
|
||||
sort_order: Optional[int] = None,
|
||||
item_kind: BacklogItemKind = "story",
|
||||
parent_action_id: Optional[str] = None,
|
||||
user_id: Optional[str] = None,
|
||||
) -> dict[str, Any]:
|
||||
title = title.strip()
|
||||
@@ -61,6 +111,7 @@ def create_backlog_item(
|
||||
raise ValueError("Titel ist erforderlich")
|
||||
_validate_status(status)
|
||||
_validate_priority(priority)
|
||||
_validate_item_kind(item_kind)
|
||||
if not get_initiative(tenant_id=tenant_id, initiative_id=initiative_id):
|
||||
raise ValueError("Initiative nicht gefunden")
|
||||
|
||||
@@ -73,6 +124,12 @@ def create_backlog_item(
|
||||
initiative_id=initiative_id,
|
||||
roadmap_item_id=roadmap_item_id,
|
||||
)
|
||||
_validate_parent_action_in_initiative(
|
||||
cur=cur,
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=initiative_id,
|
||||
parent_action_id=parent_action_id,
|
||||
)
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT COALESCE(MAX(sort_order), -10) + 10 AS next_order
|
||||
@@ -86,9 +143,9 @@ def create_backlog_item(
|
||||
f"""
|
||||
INSERT INTO backlog_items (
|
||||
tenant_id, initiative_id, title, description, status, priority,
|
||||
roadmap_item_id, sort_order
|
||||
roadmap_item_id, sort_order, item_kind, parent_action_id
|
||||
)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
RETURNING {_BACKLOG_COLUMNS}
|
||||
""",
|
||||
(
|
||||
@@ -100,6 +157,8 @@ def create_backlog_item(
|
||||
priority,
|
||||
roadmap_item_id,
|
||||
sort_order if sort_order is not None else next_order,
|
||||
item_kind,
|
||||
parent_action_id,
|
||||
),
|
||||
)
|
||||
row = _serialize_row(dict(cur.fetchone()))
|
||||
@@ -167,6 +226,9 @@ def update_backlog_item(
|
||||
roadmap_item_id: Optional[str] = None,
|
||||
clear_roadmap_item: bool = False,
|
||||
sort_order: Optional[int] = None,
|
||||
item_kind: Optional[BacklogItemKind] = None,
|
||||
parent_action_id: Optional[str] = None,
|
||||
clear_parent_action: bool = False,
|
||||
) -> Optional[dict[str, Any]]:
|
||||
existing = get_backlog_item(tenant_id=tenant_id, backlog_item_id=backlog_item_id)
|
||||
if not existing:
|
||||
@@ -214,6 +276,15 @@ def update_backlog_item(
|
||||
if sort_order is not None:
|
||||
updates.append("sort_order = %s")
|
||||
params.append(sort_order)
|
||||
if item_kind is not None:
|
||||
_validate_item_kind(item_kind)
|
||||
updates.append("item_kind = %s")
|
||||
params.append(item_kind)
|
||||
if clear_parent_action:
|
||||
updates.append("parent_action_id = NULL")
|
||||
elif parent_action_id is not None:
|
||||
updates.append("parent_action_id = %s")
|
||||
params.append(parent_action_id)
|
||||
|
||||
if not updates:
|
||||
return existing
|
||||
@@ -224,6 +295,13 @@ def update_backlog_item(
|
||||
conn = get_connection()
|
||||
try:
|
||||
with conn.cursor(cursor_factory=RealDictCursor) as cur:
|
||||
if parent_action_id is not None and not clear_parent_action:
|
||||
_validate_parent_action_in_initiative(
|
||||
cur=cur,
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=existing["initiative_id"],
|
||||
parent_action_id=parent_action_id,
|
||||
)
|
||||
cur.execute(
|
||||
f"""
|
||||
UPDATE backlog_items
|
||||
@@ -316,6 +394,7 @@ def convert_backlog_to_action(
|
||||
if active:
|
||||
resolved_cycle_id = active["id"]
|
||||
|
||||
item_kind = existing.get("item_kind") or "story"
|
||||
action = create_action(
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=existing["initiative_id"],
|
||||
@@ -325,6 +404,8 @@ def convert_backlog_to_action(
|
||||
roadmap_item_id=existing.get("roadmap_item_id"),
|
||||
work_cycle_id=resolved_cycle_id,
|
||||
assigned_actor_ids=assigned_actor_ids or [],
|
||||
action_kind=_item_kind_to_action_kind(item_kind),
|
||||
parent_action_id=existing.get("parent_action_id"),
|
||||
user_id=user_id,
|
||||
)
|
||||
|
||||
|
||||
@@ -213,6 +213,12 @@ def complete_work_cycle(
|
||||
conn.close()
|
||||
|
||||
result = _serialize_cycle({**dict(row), "initiative_id": initiative_id})
|
||||
open_count = count_actions_in_work_cycle(
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=initiative_id,
|
||||
work_cycle_id=work_cycle_id,
|
||||
)
|
||||
result["open_action_count_at_completion"] = open_count
|
||||
log_audit(
|
||||
"work_cycle.completed",
|
||||
user_id=user_id,
|
||||
|
||||
Reference in new issue
Block a user