feat(A1): Progression Join-Graph und Multi-Strang-Horizon
Deploy Development / deploy (push) Successful in 52s
Test Suite / pytest-backend (push) Failing after 5m3s
Test Suite / k6 /api/health Baseline (push) Has been skipped
Test Suite / playwright-smoke (push) Has been skipped
Test Suite / lint-backend (push) Successful in 3s
Test Suite / compose-smoke (push) Has been skipped
Deploy Development / deploy (push) Successful in 52s
Test Suite / pytest-backend (push) Failing after 5m3s
Test Suite / k6 /api/health Baseline (push) Has been skipped
Test Suite / playwright-smoke (push) Has been skipped
Test Suite / lint-backend (push) Successful in 3s
Test Suite / compose-smoke (push) Has been skipped
join_gate, strand_project_id, Join-Auto-Schalten, multi-active Gates, Progression-Demo und PO-Lock-Spec. FE: Today strang-gruppiert, Join-Warteliste in Kontrolle. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
192a65a798
commit
3a0ef3a734
29 files changed
+1457
-230
No files matched your search
@@ -312,6 +312,130 @@ def _apply_a2(
|
||||
}
|
||||
|
||||
|
||||
def apply_a1_progression_demo(
|
||||
*,
|
||||
tenant_id: str,
|
||||
initiative_id: str,
|
||||
user_id: Optional[str] = None,
|
||||
) -> dict[str, Any]:
|
||||
"""PO-Kernbild: 2 Stränge → Join → Ausgänge (AP-A1-PM-6). Idempotent wenn Struktur existiert."""
|
||||
from services.maturity_practice import seed_practices_for_stage
|
||||
from services.projects import create_project, list_projects_for_initiative
|
||||
from services.roadmap import add_dependency, create_roadmap_item, list_roadmap_items_for_initiative
|
||||
|
||||
existing = list_roadmap_items_for_initiative(
|
||||
tenant_id=tenant_id, initiative_id=initiative_id
|
||||
)
|
||||
if any(item.get("item_type") == "join_gate" for item in existing):
|
||||
return {"applied": False, "reason": "progression_exists"}
|
||||
|
||||
projects = list_projects_for_initiative(tenant_id=tenant_id, initiative_id=initiative_id)
|
||||
dehnung = _find_by_title(projects, "Dehnung")
|
||||
if not dehnung:
|
||||
dehnung = create_project(
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=initiative_id,
|
||||
title="Dehnung",
|
||||
description="Strang Dehnung",
|
||||
container_kind="stream",
|
||||
sort_order=0,
|
||||
user_id=user_id,
|
||||
)
|
||||
huft = _find_by_title(projects, "Hüftrotation")
|
||||
if not huft:
|
||||
huft = create_project(
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=initiative_id,
|
||||
title="Hüftrotation",
|
||||
description="Strang Hüftrotation",
|
||||
container_kind="stream",
|
||||
sort_order=1,
|
||||
user_id=user_id,
|
||||
)
|
||||
|
||||
d1 = create_roadmap_item(
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=initiative_id,
|
||||
title="Dehnung — Einstieg",
|
||||
item_type="maturity_stage",
|
||||
status="active",
|
||||
sort_order=10,
|
||||
strand_project_id=dehnung["id"],
|
||||
user_id=user_id,
|
||||
)
|
||||
h1 = create_roadmap_item(
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=initiative_id,
|
||||
title="Hüftrotation — Einstieg",
|
||||
item_type="maturity_stage",
|
||||
status="active",
|
||||
sort_order=20,
|
||||
strand_project_id=huft["id"],
|
||||
user_id=user_id,
|
||||
)
|
||||
join = create_roadmap_item(
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=initiative_id,
|
||||
title="Mawashi Geri zur Hüfte",
|
||||
item_type="join_gate",
|
||||
status="planned",
|
||||
sort_order=30,
|
||||
user_id=user_id,
|
||||
)
|
||||
d2 = create_roadmap_item(
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=initiative_id,
|
||||
title="Dehnung — nach Join",
|
||||
item_type="maturity_stage",
|
||||
status="planned",
|
||||
sort_order=40,
|
||||
strand_project_id=dehnung["id"],
|
||||
user_id=user_id,
|
||||
)
|
||||
h2 = create_roadmap_item(
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=initiative_id,
|
||||
title="Hüftrotation — nach Join",
|
||||
item_type="maturity_stage",
|
||||
status="planned",
|
||||
sort_order=50,
|
||||
strand_project_id=huft["id"],
|
||||
user_id=user_id,
|
||||
)
|
||||
|
||||
for from_id, to_id in (
|
||||
(join["id"], d1["id"]),
|
||||
(join["id"], h1["id"]),
|
||||
(d2["id"], join["id"]),
|
||||
(h2["id"], join["id"]),
|
||||
):
|
||||
try:
|
||||
add_dependency(
|
||||
tenant_id=tenant_id,
|
||||
from_item_id=from_id,
|
||||
to_item_id=to_id,
|
||||
dependency_type="requires",
|
||||
user_id=user_id,
|
||||
)
|
||||
except ValueError as exc:
|
||||
if "existiert bereits" not in str(exc):
|
||||
raise
|
||||
|
||||
seed_practices_for_stage(
|
||||
tenant_id=tenant_id, initiative_id=initiative_id, stage=d1, user_id=user_id
|
||||
)
|
||||
seed_practices_for_stage(
|
||||
tenant_id=tenant_id, initiative_id=initiative_id, stage=h1, user_id=user_id
|
||||
)
|
||||
|
||||
return {
|
||||
"applied": True,
|
||||
"projects": ["Dehnung", "Hüftrotation"],
|
||||
"join": join["title"],
|
||||
"active_gates": [d1["title"], h1["title"]],
|
||||
}
|
||||
|
||||
|
||||
def _apply_b2b(
|
||||
*,
|
||||
tenant_id: str,
|
||||
|
||||
@@ -25,12 +25,24 @@ STAGE_PRACTICE_SETS: dict[str, list[tuple[str, str]]] = {
|
||||
"Stufe 3 — Ziel": [
|
||||
("Voller Spagat", "Täglich Zielposition — Messwert dokumentieren"),
|
||||
],
|
||||
"Dehnung — Einstieg": [
|
||||
("Vorbeuge halten", "Täglich 3×30 Sek."),
|
||||
],
|
||||
"Hüftrotation — Einstieg": [
|
||||
("Hüftkreisen im Stand", "Täglich 10 Wiederholungen je Richtung"),
|
||||
],
|
||||
"Dehnung — nach Join": [
|
||||
("Enddehnung Mawashi-Vorbereitung", "Täglich 2×45 Sek."),
|
||||
],
|
||||
"Hüftrotation — nach Join": [
|
||||
("Explosive Hüftrotation", "Täglich 3×8 Wiederholungen"),
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def get_active_maturity_stage(
|
||||
def get_active_maturity_stages(
|
||||
*, tenant_id: str, initiative_id: str
|
||||
) -> Optional[dict[str, Any]]:
|
||||
) -> list[dict[str, Any]]:
|
||||
from services.roadmap import list_roadmap_items_for_initiative
|
||||
|
||||
stages = [
|
||||
@@ -40,34 +52,17 @@ def get_active_maturity_stage(
|
||||
)
|
||||
if item.get("item_type") == "maturity_stage" and item.get("status") == "active"
|
||||
]
|
||||
if not stages:
|
||||
return None
|
||||
stages.sort(key=lambda s: (s.get("sort_order", 0), s.get("title", "")))
|
||||
return stages[0]
|
||||
return stages
|
||||
|
||||
|
||||
def enforce_single_active_maturity_stage(
|
||||
cur,
|
||||
*,
|
||||
tenant_id: str,
|
||||
initiative_id: str,
|
||||
keep_active_id: str,
|
||||
) -> None:
|
||||
"""At most one maturity_stage may be active."""
|
||||
cur.execute(
|
||||
"""
|
||||
UPDATE roadmap_items ri
|
||||
SET status = 'planned', updated_at = NOW()
|
||||
FROM roadmaps r
|
||||
WHERE ri.roadmap_id = r.id
|
||||
AND ri.tenant_id = %s
|
||||
AND r.initiative_id = %s
|
||||
AND ri.item_type = 'maturity_stage'
|
||||
AND ri.status IN ('active', 'at_risk')
|
||||
AND ri.id != %s
|
||||
""",
|
||||
(tenant_id, initiative_id, keep_active_id),
|
||||
def get_active_maturity_stage(
|
||||
*, tenant_id: str, initiative_id: str
|
||||
) -> Optional[dict[str, Any]]:
|
||||
stages = get_active_maturity_stages(
|
||||
tenant_id=tenant_id, initiative_id=initiative_id
|
||||
)
|
||||
return stages[0] if stages else None
|
||||
|
||||
|
||||
def list_practices_for_stage(
|
||||
@@ -107,6 +102,34 @@ def pause_all_practices(
|
||||
return paused
|
||||
|
||||
|
||||
def pause_practices_except_stage(
|
||||
*,
|
||||
tenant_id: str,
|
||||
initiative_id: str,
|
||||
keep_stage_id: str,
|
||||
strand_project_id: Optional[str] = None,
|
||||
user_id: Optional[str] = None,
|
||||
) -> list[str]:
|
||||
paused: list[str] = []
|
||||
for item in list_recurring_for_initiative(
|
||||
tenant_id=tenant_id, initiative_id=initiative_id
|
||||
):
|
||||
if item.get("status") != "active":
|
||||
continue
|
||||
if item.get("roadmap_item_id") == keep_stage_id:
|
||||
continue
|
||||
if strand_project_id is not None and item.get("project_id") != strand_project_id:
|
||||
continue
|
||||
update_recurring_element(
|
||||
tenant_id=tenant_id,
|
||||
recurring_id=item["id"],
|
||||
status="paused",
|
||||
user_id=user_id,
|
||||
)
|
||||
paused.append(item["title"])
|
||||
return paused
|
||||
|
||||
|
||||
def seed_practices_for_stage(
|
||||
*,
|
||||
tenant_id: str,
|
||||
@@ -117,6 +140,7 @@ def seed_practices_for_stage(
|
||||
"""Idempotent: create missing exercises for a stage; activate existing."""
|
||||
stage_id = stage["id"]
|
||||
stage_title = stage.get("title") or ""
|
||||
strand_project_id = stage.get("strand_project_id")
|
||||
defs = STAGE_PRACTICE_SETS.get(stage_title)
|
||||
if not defs:
|
||||
defs = [
|
||||
@@ -161,6 +185,7 @@ def seed_practices_for_stage(
|
||||
interval_days=1,
|
||||
next_due_at=now,
|
||||
roadmap_item_id=stage_id,
|
||||
project_id=strand_project_id,
|
||||
user_id=user_id,
|
||||
)
|
||||
created.append(row)
|
||||
@@ -175,9 +200,19 @@ def activate_stage_practice_set(
|
||||
stage: dict[str, Any],
|
||||
user_id: Optional[str] = None,
|
||||
) -> dict[str, Any]:
|
||||
paused = pause_all_practices(
|
||||
tenant_id=tenant_id, initiative_id=initiative_id, user_id=user_id
|
||||
)
|
||||
strand_project_id = stage.get("strand_project_id")
|
||||
if strand_project_id:
|
||||
paused = pause_practices_except_stage(
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=initiative_id,
|
||||
keep_stage_id=stage["id"],
|
||||
strand_project_id=strand_project_id,
|
||||
user_id=user_id,
|
||||
)
|
||||
else:
|
||||
paused = pause_all_practices(
|
||||
tenant_id=tenant_id, initiative_id=initiative_id, user_id=user_id
|
||||
)
|
||||
exercises = seed_practices_for_stage(
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=initiative_id,
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
"""AP2.0e — Recurring transition when a maturity_stage is reached."""
|
||||
"""AP2.0e — maturity stage transition on verify reached (delegates to progression_graph)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Optional
|
||||
|
||||
from services.maturity_practice import activate_stage_practice_set
|
||||
from services.roadmap import get_roadmap_item, list_roadmap_items_for_initiative
|
||||
|
||||
|
||||
def on_maturity_stage_reached(
|
||||
*,
|
||||
@@ -15,61 +12,14 @@ def on_maturity_stage_reached(
|
||||
reached_item_id: str,
|
||||
user_id: Optional[str] = None,
|
||||
) -> Optional[dict[str, Any]]:
|
||||
"""Pause old routines, activate next stage, seed exercise set for next stage."""
|
||||
item = get_roadmap_item(tenant_id=tenant_id, item_id=reached_item_id)
|
||||
if not item or item.get("item_type") != "maturity_stage":
|
||||
return None
|
||||
from services.progression_graph import on_work_gate_reached
|
||||
|
||||
stages = [
|
||||
s
|
||||
for s in list_roadmap_items_for_initiative(
|
||||
tenant_id=tenant_id, initiative_id=initiative_id
|
||||
)
|
||||
if s.get("item_type") == "maturity_stage"
|
||||
]
|
||||
stages.sort(key=lambda s: (s.get("sort_order", 0), s.get("title", "")))
|
||||
|
||||
reached_index = next(
|
||||
(index for index, stage in enumerate(stages) if stage["id"] == reached_item_id),
|
||||
None,
|
||||
return on_work_gate_reached(
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=initiative_id,
|
||||
reached_item_id=reached_item_id,
|
||||
user_id=user_id,
|
||||
)
|
||||
if reached_index is None:
|
||||
return None
|
||||
|
||||
next_stage = None
|
||||
for stage in stages[reached_index + 1 :]:
|
||||
if stage.get("status") in {"planned", "active", "at_risk"}:
|
||||
next_stage = stage
|
||||
break
|
||||
|
||||
practice_transition = None
|
||||
if next_stage:
|
||||
from services.roadmap import update_roadmap_item
|
||||
|
||||
update_roadmap_item(
|
||||
tenant_id=tenant_id,
|
||||
item_id=next_stage["id"],
|
||||
status="active",
|
||||
user_id=user_id,
|
||||
)
|
||||
next_stage = get_roadmap_item(tenant_id=tenant_id, item_id=next_stage["id"])
|
||||
if next_stage:
|
||||
practice_transition = activate_stage_practice_set(
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=initiative_id,
|
||||
stage=next_stage,
|
||||
user_id=user_id,
|
||||
)
|
||||
|
||||
return {
|
||||
"reached_stage_id": reached_item_id,
|
||||
"next_stage_id": next_stage["id"] if next_stage else None,
|
||||
"paused_recurring": (practice_transition or {}).get("paused_practices", []),
|
||||
"new_recurring_id": (
|
||||
(practice_transition or {}).get("practice_ids") or [None]
|
||||
)[0],
|
||||
"active_practices": (practice_transition or {}).get("active_practices", []),
|
||||
}
|
||||
|
||||
|
||||
def on_maturity_stage_reopened(
|
||||
@@ -79,7 +29,10 @@ def on_maturity_stage_reopened(
|
||||
stage_id: str,
|
||||
user_id: Optional[str] = None,
|
||||
) -> dict[str, Any]:
|
||||
"""Re-enable exercise set for reopened stage; pause others."""
|
||||
"""Re-enable exercise set for reopened stage; pause others on same strand."""
|
||||
from services.maturity_practice import activate_stage_practice_set
|
||||
from services.roadmap import get_roadmap_item
|
||||
|
||||
stage = get_roadmap_item(tenant_id=tenant_id, item_id=stage_id)
|
||||
if not stage:
|
||||
return {"stage_id": stage_id, "active_practices": []}
|
||||
|
||||
@@ -0,0 +1,546 @@
|
||||
"""A1 progression graph — multi-strand work gates, join switch nodes (PO-Lock §10)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Optional
|
||||
|
||||
from psycopg2.extras import RealDictCursor
|
||||
|
||||
from db import get_connection
|
||||
|
||||
WORK_GATE_TYPES = frozenset({"maturity_stage"})
|
||||
JOIN_GATE_TYPE = "join_gate"
|
||||
ACTIVE_WORK_STATUSES = frozenset({"active", "at_risk"})
|
||||
TERMINAL_STATUSES = frozenset({"reached", "moved", "discarded"})
|
||||
|
||||
|
||||
def is_work_gate(item: dict[str, Any]) -> bool:
|
||||
return item.get("item_type") in WORK_GATE_TYPES
|
||||
|
||||
|
||||
def is_join_gate(item: dict[str, Any]) -> bool:
|
||||
return item.get("item_type") == JOIN_GATE_TYPE
|
||||
|
||||
|
||||
def _requires_deps(dependencies: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
||||
return [
|
||||
dep
|
||||
for dep in dependencies
|
||||
if (dep.get("dependency_type") or "requires") == "requires"
|
||||
]
|
||||
|
||||
|
||||
def join_input_gate_ids(
|
||||
join_id: str, dependencies: list[dict[str, Any]]
|
||||
) -> list[str]:
|
||||
"""Join requires input gates (from=join, to=input)."""
|
||||
return [
|
||||
str(dep["to_item_id"])
|
||||
for dep in _requires_deps(dependencies)
|
||||
if str(dep["from_item_id"]) == str(join_id)
|
||||
]
|
||||
|
||||
|
||||
def join_output_gate_ids(
|
||||
join_id: str, dependencies: list[dict[str, Any]]
|
||||
) -> list[str]:
|
||||
"""Output gates require join (from=output, to=join)."""
|
||||
return [
|
||||
str(dep["from_item_id"])
|
||||
for dep in _requires_deps(dependencies)
|
||||
if str(dep["to_item_id"]) == str(join_id)
|
||||
]
|
||||
|
||||
|
||||
def successor_work_gate_ids(
|
||||
gate_id: str, dependencies: list[dict[str, Any]]
|
||||
) -> list[str]:
|
||||
"""Work gates that require this gate (from=successor, to=gate)."""
|
||||
return [
|
||||
str(dep["from_item_id"])
|
||||
for dep in _requires_deps(dependencies)
|
||||
if str(dep["to_item_id"]) == str(gate_id)
|
||||
]
|
||||
|
||||
|
||||
def list_active_work_gates(
|
||||
*, tenant_id: str, initiative_id: str
|
||||
) -> list[dict[str, Any]]:
|
||||
from services.roadmap import list_roadmap_items_for_initiative
|
||||
|
||||
items = list_roadmap_items_for_initiative(
|
||||
tenant_id=tenant_id, initiative_id=initiative_id
|
||||
)
|
||||
active = [
|
||||
item
|
||||
for item in items
|
||||
if is_work_gate(item) and item.get("status") in ACTIVE_WORK_STATUSES
|
||||
]
|
||||
active.sort(key=lambda item: (item.get("sort_order", 0), item.get("title", "")))
|
||||
return active
|
||||
|
||||
|
||||
def compute_join_states(
|
||||
*,
|
||||
tenant_id: str,
|
||||
initiative_id: str,
|
||||
) -> list[dict[str, Any]]:
|
||||
from services.projects import list_projects_for_initiative
|
||||
from services.roadmap import list_dependencies_for_initiative, list_roadmap_items_for_initiative
|
||||
|
||||
items = list_roadmap_items_for_initiative(
|
||||
tenant_id=tenant_id, initiative_id=initiative_id
|
||||
)
|
||||
item_by_id = {str(item["id"]): item for item in items}
|
||||
dependencies = list_dependencies_for_initiative(
|
||||
tenant_id=tenant_id, initiative_id=initiative_id
|
||||
)
|
||||
projects = list_projects_for_initiative(
|
||||
tenant_id=tenant_id, initiative_id=initiative_id
|
||||
)
|
||||
project_title = {str(p["id"]): p.get("title") or "" for p in projects}
|
||||
|
||||
joins = [item for item in items if is_join_gate(item)]
|
||||
states: list[dict[str, Any]] = []
|
||||
|
||||
for join in joins:
|
||||
join_id = str(join["id"])
|
||||
input_ids = join_input_gate_ids(join_id, dependencies)
|
||||
output_ids = join_output_gate_ids(join_id, dependencies)
|
||||
pending: list[dict[str, Any]] = []
|
||||
for input_id in input_ids:
|
||||
gate = item_by_id.get(input_id)
|
||||
if not gate:
|
||||
continue
|
||||
if gate.get("status") != "reached":
|
||||
strand_id = gate.get("strand_project_id")
|
||||
pending.append(
|
||||
{
|
||||
"gate_id": input_id,
|
||||
"title": gate.get("title") or input_id,
|
||||
"strand_project_id": strand_id,
|
||||
"strand_title": project_title.get(str(strand_id or ""), ""),
|
||||
"status": gate.get("status"),
|
||||
}
|
||||
)
|
||||
states.append(
|
||||
{
|
||||
"join_id": join_id,
|
||||
"title": join.get("title") or "",
|
||||
"status": join.get("status"),
|
||||
"ready_to_switch": len(pending) == 0 and join.get("status") not in TERMINAL_STATUSES,
|
||||
"pending_inputs": pending,
|
||||
"output_gate_ids": output_ids,
|
||||
"outputs": [
|
||||
{
|
||||
"gate_id": output_id,
|
||||
"title": (item_by_id.get(output_id) or {}).get("title") or output_id,
|
||||
"strand_project_id": (item_by_id.get(output_id) or {}).get(
|
||||
"strand_project_id"
|
||||
),
|
||||
}
|
||||
for output_id in output_ids
|
||||
if output_id in item_by_id
|
||||
],
|
||||
}
|
||||
)
|
||||
return states
|
||||
|
||||
|
||||
def compute_progression_state(
|
||||
*, tenant_id: str, initiative_id: str
|
||||
) -> dict[str, Any]:
|
||||
active_gates = list_active_work_gates(
|
||||
tenant_id=tenant_id, initiative_id=initiative_id
|
||||
)
|
||||
return {
|
||||
"active_work_gates": [
|
||||
{
|
||||
"id": gate["id"],
|
||||
"title": gate.get("title"),
|
||||
"strand_project_id": gate.get("strand_project_id"),
|
||||
"status": gate.get("status"),
|
||||
}
|
||||
for gate in active_gates
|
||||
],
|
||||
"joins": compute_join_states(
|
||||
tenant_id=tenant_id, initiative_id=initiative_id
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def enforce_single_active_work_gate_per_strand(
|
||||
cur,
|
||||
*,
|
||||
tenant_id: str,
|
||||
initiative_id: str,
|
||||
keep_active_id: str,
|
||||
strand_project_id: Optional[str],
|
||||
) -> None:
|
||||
if strand_project_id:
|
||||
cur.execute(
|
||||
"""
|
||||
UPDATE roadmap_items ri
|
||||
SET status = 'planned', updated_at = NOW()
|
||||
FROM roadmaps r
|
||||
WHERE ri.roadmap_id = r.id
|
||||
AND ri.tenant_id = %s
|
||||
AND r.initiative_id = %s
|
||||
AND ri.item_type = 'maturity_stage'
|
||||
AND ri.status IN ('active', 'at_risk')
|
||||
AND ri.strand_project_id = %s
|
||||
AND ri.id != %s
|
||||
""",
|
||||
(tenant_id, initiative_id, strand_project_id, keep_active_id),
|
||||
)
|
||||
return
|
||||
|
||||
cur.execute(
|
||||
"""
|
||||
UPDATE roadmap_items ri
|
||||
SET status = 'planned', updated_at = NOW()
|
||||
FROM roadmaps r
|
||||
WHERE ri.roadmap_id = r.id
|
||||
AND ri.tenant_id = %s
|
||||
AND r.initiative_id = %s
|
||||
AND ri.item_type = 'maturity_stage'
|
||||
AND ri.status IN ('active', 'at_risk')
|
||||
AND ri.strand_project_id IS NULL
|
||||
AND ri.id != %s
|
||||
""",
|
||||
(tenant_id, initiative_id, keep_active_id),
|
||||
)
|
||||
|
||||
|
||||
def _graph_ready(
|
||||
item_id: str,
|
||||
*,
|
||||
item_by_id: dict[str, dict[str, Any]],
|
||||
dependencies: list[dict[str, Any]],
|
||||
) -> bool:
|
||||
for dep in _requires_deps(dependencies):
|
||||
if str(dep["from_item_id"]) != str(item_id):
|
||||
continue
|
||||
prereq = item_by_id.get(str(dep["to_item_id"]))
|
||||
if not prereq:
|
||||
continue
|
||||
if prereq.get("status") != "reached":
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def activate_work_gate(
|
||||
*,
|
||||
tenant_id: str,
|
||||
initiative_id: str,
|
||||
gate: dict[str, Any],
|
||||
user_id: Optional[str] = None,
|
||||
seed_practices: bool = True,
|
||||
) -> dict[str, Any]:
|
||||
from services.maturity_practice import activate_stage_practice_set
|
||||
from services.roadmap import get_roadmap_item, update_roadmap_item
|
||||
|
||||
gate_id = gate["id"]
|
||||
updated = update_roadmap_item(
|
||||
tenant_id=tenant_id,
|
||||
item_id=gate_id,
|
||||
status="active",
|
||||
user_id=user_id,
|
||||
)
|
||||
if not updated:
|
||||
raise ValueError("Work-Gate konnte nicht aktiviert werden")
|
||||
|
||||
practice_result = None
|
||||
if seed_practices:
|
||||
fresh = get_roadmap_item(tenant_id=tenant_id, item_id=gate_id) or updated
|
||||
practice_result = activate_stage_practice_set(
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=initiative_id,
|
||||
stage=fresh,
|
||||
user_id=user_id,
|
||||
)
|
||||
|
||||
return {
|
||||
"gate_id": gate_id,
|
||||
"gate_title": updated.get("title"),
|
||||
"practice_transition": practice_result,
|
||||
}
|
||||
|
||||
|
||||
def _mark_join_reached(
|
||||
cur,
|
||||
*,
|
||||
tenant_id: str,
|
||||
join_id: str,
|
||||
) -> None:
|
||||
cur.execute(
|
||||
"""
|
||||
UPDATE roadmap_items
|
||||
SET status = 'reached', updated_at = NOW()
|
||||
WHERE id = %s AND tenant_id = %s AND item_type = 'join_gate'
|
||||
""",
|
||||
(join_id, tenant_id),
|
||||
)
|
||||
|
||||
|
||||
def try_switch_join(
|
||||
*,
|
||||
tenant_id: str,
|
||||
initiative_id: str,
|
||||
join_id: str,
|
||||
user_id: Optional[str] = None,
|
||||
) -> Optional[dict[str, Any]]:
|
||||
from services.audit import log_audit
|
||||
from services.roadmap import get_roadmap_item, list_dependencies_for_initiative
|
||||
|
||||
join = get_roadmap_item(tenant_id=tenant_id, item_id=join_id)
|
||||
if not join or not is_join_gate(join):
|
||||
return None
|
||||
if join.get("status") in TERMINAL_STATUSES:
|
||||
return None
|
||||
|
||||
dependencies = list_dependencies_for_initiative(
|
||||
tenant_id=tenant_id, initiative_id=initiative_id
|
||||
)
|
||||
item_by_id = {
|
||||
str(item["id"]): item
|
||||
for item in __import__(
|
||||
"services.roadmap", fromlist=["list_roadmap_items_for_initiative"]
|
||||
).list_roadmap_items_for_initiative(
|
||||
tenant_id=tenant_id, initiative_id=initiative_id
|
||||
)
|
||||
}
|
||||
|
||||
pending = [
|
||||
input_id
|
||||
for input_id in join_input_gate_ids(join_id, dependencies)
|
||||
if item_by_id.get(input_id, {}).get("status") != "reached"
|
||||
]
|
||||
if pending:
|
||||
return None
|
||||
|
||||
output_ids = join_output_gate_ids(join_id, dependencies)
|
||||
activated: list[dict[str, Any]] = []
|
||||
|
||||
conn = get_connection()
|
||||
try:
|
||||
with conn.cursor(cursor_factory=RealDictCursor) as cur:
|
||||
_mark_join_reached(cur, tenant_id=tenant_id, join_id=join_id)
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
for output_id in output_ids:
|
||||
output_gate = item_by_id.get(output_id)
|
||||
if not output_gate or not is_work_gate(output_gate):
|
||||
continue
|
||||
if output_gate.get("status") in TERMINAL_STATUSES:
|
||||
continue
|
||||
if not _graph_ready(output_id, item_by_id=item_by_id, dependencies=dependencies):
|
||||
continue
|
||||
activated.append(
|
||||
activate_work_gate(
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=initiative_id,
|
||||
gate=output_gate,
|
||||
user_id=user_id,
|
||||
)
|
||||
)
|
||||
|
||||
log_audit(
|
||||
"progression.join_switched",
|
||||
user_id=user_id,
|
||||
tenant_id=tenant_id,
|
||||
details={
|
||||
"initiative_id": initiative_id,
|
||||
"join_id": join_id,
|
||||
"join_title": join.get("title"),
|
||||
"activated_gate_ids": [item["gate_id"] for item in activated],
|
||||
},
|
||||
)
|
||||
|
||||
return {
|
||||
"join_id": join_id,
|
||||
"join_title": join.get("title"),
|
||||
"activated": activated,
|
||||
}
|
||||
|
||||
|
||||
def try_switch_joins_for_gate(
|
||||
*,
|
||||
tenant_id: str,
|
||||
initiative_id: str,
|
||||
gate_id: str,
|
||||
user_id: Optional[str] = None,
|
||||
) -> list[dict[str, Any]]:
|
||||
from services.roadmap import list_dependencies_for_initiative, list_roadmap_items_for_initiative
|
||||
|
||||
dependencies = list_dependencies_for_initiative(
|
||||
tenant_id=tenant_id, initiative_id=initiative_id
|
||||
)
|
||||
joins = [
|
||||
item
|
||||
for item in list_roadmap_items_for_initiative(
|
||||
tenant_id=tenant_id, initiative_id=initiative_id
|
||||
)
|
||||
if is_join_gate(item)
|
||||
]
|
||||
switched: list[dict[str, Any]] = []
|
||||
for join in joins:
|
||||
join_id = str(join["id"])
|
||||
inputs = join_input_gate_ids(join_id, dependencies)
|
||||
if gate_id not in inputs:
|
||||
continue
|
||||
result = try_switch_join(
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=initiative_id,
|
||||
join_id=join_id,
|
||||
user_id=user_id,
|
||||
)
|
||||
if result:
|
||||
switched.append(result)
|
||||
return switched
|
||||
|
||||
|
||||
def _legacy_linear_next_stage(
|
||||
*,
|
||||
tenant_id: str,
|
||||
initiative_id: str,
|
||||
reached_item_id: str,
|
||||
user_id: Optional[str] = None,
|
||||
) -> Optional[dict[str, Any]]:
|
||||
from services.roadmap import get_roadmap_item, list_roadmap_items_for_initiative, update_roadmap_item
|
||||
|
||||
stages = [
|
||||
item
|
||||
for item in list_roadmap_items_for_initiative(
|
||||
tenant_id=tenant_id, initiative_id=initiative_id
|
||||
)
|
||||
if is_work_gate(item)
|
||||
]
|
||||
stages.sort(key=lambda item: (item.get("sort_order", 0), item.get("title", "")))
|
||||
reached_index = next(
|
||||
(index for index, stage in enumerate(stages) if stage["id"] == reached_item_id),
|
||||
None,
|
||||
)
|
||||
if reached_index is None:
|
||||
return None
|
||||
|
||||
next_stage = None
|
||||
for stage in stages[reached_index + 1 :]:
|
||||
if stage.get("status") in {"planned", "active", "at_risk"}:
|
||||
next_stage = stage
|
||||
break
|
||||
if not next_stage:
|
||||
return None
|
||||
|
||||
update_roadmap_item(
|
||||
tenant_id=tenant_id,
|
||||
item_id=next_stage["id"],
|
||||
status="active",
|
||||
user_id=user_id,
|
||||
)
|
||||
fresh = get_roadmap_item(tenant_id=tenant_id, item_id=next_stage["id"])
|
||||
if not fresh:
|
||||
return None
|
||||
return activate_work_gate(
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=initiative_id,
|
||||
gate=fresh,
|
||||
user_id=user_id,
|
||||
)
|
||||
|
||||
|
||||
def on_work_gate_reached(
|
||||
*,
|
||||
tenant_id: str,
|
||||
initiative_id: str,
|
||||
reached_item_id: str,
|
||||
user_id: Optional[str] = None,
|
||||
) -> dict[str, Any]:
|
||||
from services.maturity_practice import list_practices_for_stage, update_recurring_element
|
||||
from services.roadmap import get_roadmap_item, list_dependencies_for_initiative, list_roadmap_items_for_initiative
|
||||
|
||||
reached = get_roadmap_item(tenant_id=tenant_id, item_id=reached_item_id)
|
||||
if not reached or not is_work_gate(reached):
|
||||
return {"reached_gate_id": reached_item_id}
|
||||
|
||||
for practice in list_practices_for_stage(
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=initiative_id,
|
||||
stage_id=reached_item_id,
|
||||
):
|
||||
if practice.get("status") == "active":
|
||||
update_recurring_element(
|
||||
tenant_id=tenant_id,
|
||||
recurring_id=practice["id"],
|
||||
status="paused",
|
||||
user_id=user_id,
|
||||
)
|
||||
|
||||
dependencies = list_dependencies_for_initiative(
|
||||
tenant_id=tenant_id, initiative_id=initiative_id
|
||||
)
|
||||
has_progression_deps = any(
|
||||
(dep.get("dependency_type") or "requires") == "requires"
|
||||
for dep in dependencies
|
||||
if str(dep["from_item_id"]) in {
|
||||
str(reached_item_id),
|
||||
*(str(item["id"]) for item in list_roadmap_items_for_initiative(
|
||||
tenant_id=tenant_id, initiative_id=initiative_id
|
||||
) if is_join_gate(item)),
|
||||
}
|
||||
or str(dep["to_item_id"]) == str(reached_item_id)
|
||||
)
|
||||
|
||||
joined = try_switch_joins_for_gate(
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=initiative_id,
|
||||
gate_id=reached_item_id,
|
||||
user_id=user_id,
|
||||
)
|
||||
|
||||
activated_successors: list[dict[str, Any]] = []
|
||||
if not joined:
|
||||
item_by_id = {
|
||||
str(item["id"]): item
|
||||
for item in list_roadmap_items_for_initiative(
|
||||
tenant_id=tenant_id, initiative_id=initiative_id
|
||||
)
|
||||
}
|
||||
for successor_id in successor_work_gate_ids(reached_item_id, dependencies):
|
||||
successor = item_by_id.get(successor_id)
|
||||
if not successor or not is_work_gate(successor):
|
||||
continue
|
||||
if is_join_gate(successor):
|
||||
continue
|
||||
if successor.get("status") in TERMINAL_STATUSES:
|
||||
continue
|
||||
if not _graph_ready(
|
||||
successor_id, item_by_id=item_by_id, dependencies=dependencies
|
||||
):
|
||||
continue
|
||||
activated_successors.append(
|
||||
activate_work_gate(
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=initiative_id,
|
||||
gate=successor,
|
||||
user_id=user_id,
|
||||
)
|
||||
)
|
||||
|
||||
legacy = None
|
||||
if not joined and not activated_successors and not has_progression_deps:
|
||||
legacy = _legacy_linear_next_stage(
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=initiative_id,
|
||||
reached_item_id=reached_item_id,
|
||||
user_id=user_id,
|
||||
)
|
||||
|
||||
return {
|
||||
"reached_gate_id": reached_item_id,
|
||||
"joins_switched": joined,
|
||||
"successors_activated": activated_successors,
|
||||
"legacy_linear": legacy,
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from typing import Any, Literal, Optional
|
||||
|
||||
from psycopg2.extras import RealDictCursor
|
||||
@@ -16,14 +16,14 @@ RecurringStatus = Literal["active", "paused", "ended"]
|
||||
RECURRING_STATUSES = frozenset({"active", "paused", "ended"})
|
||||
|
||||
_RECURRING_COLUMNS = """
|
||||
id, tenant_id, initiative_id, roadmap_item_id, title, description, status,
|
||||
id, tenant_id, initiative_id, roadmap_item_id, project_id, title, description, status,
|
||||
interval_days, next_due_at, 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", "roadmap_item_id"):
|
||||
for key in ("id", "tenant_id", "initiative_id", "roadmap_item_id", "project_id"):
|
||||
if result.get(key):
|
||||
result[key] = str(result[key])
|
||||
for ts_key in ("created_at", "updated_at", "next_due_at"):
|
||||
@@ -47,6 +47,7 @@ def create_recurring_element(
|
||||
interval_days: Optional[int] = None,
|
||||
next_due_at: Optional[datetime] = None,
|
||||
roadmap_item_id: Optional[str] = None,
|
||||
project_id: Optional[str] = None,
|
||||
user_id: Optional[str] = None,
|
||||
) -> dict[str, Any]:
|
||||
title = title.strip()
|
||||
@@ -64,16 +65,17 @@ def create_recurring_element(
|
||||
cur.execute(
|
||||
f"""
|
||||
INSERT INTO recurring_elements (
|
||||
tenant_id, initiative_id, roadmap_item_id, title, description, status,
|
||||
tenant_id, initiative_id, roadmap_item_id, project_id, title, description, status,
|
||||
interval_days, next_due_at
|
||||
)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
RETURNING {_RECURRING_COLUMNS}
|
||||
""",
|
||||
(
|
||||
tenant_id,
|
||||
initiative_id,
|
||||
roadmap_item_id,
|
||||
project_id,
|
||||
title,
|
||||
description,
|
||||
status,
|
||||
@@ -166,6 +168,8 @@ def update_recurring_element(
|
||||
clear_next_due_at: bool = False,
|
||||
roadmap_item_id: Optional[str] = None,
|
||||
clear_roadmap_item_id: bool = False,
|
||||
project_id: Optional[str] = None,
|
||||
clear_project_id: bool = False,
|
||||
) -> Optional[dict[str, Any]]:
|
||||
existing = get_recurring_element(tenant_id=tenant_id, recurring_id=recurring_id)
|
||||
if not existing:
|
||||
@@ -205,6 +209,11 @@ def update_recurring_element(
|
||||
elif roadmap_item_id is not None:
|
||||
updates.append("roadmap_item_id = %s")
|
||||
params.append(roadmap_item_id)
|
||||
if clear_project_id:
|
||||
updates.append("project_id = NULL")
|
||||
elif project_id is not None:
|
||||
updates.append("project_id = %s")
|
||||
params.append(project_id)
|
||||
|
||||
if not updates:
|
||||
return existing
|
||||
|
||||
+44
-17
@@ -13,14 +13,14 @@ from services.audit import log_audit
|
||||
from services.initiatives import get_initiative
|
||||
from services.roadmap_criteria import create_default_criterion, prepare_criteria_for_verify
|
||||
|
||||
RoadmapItemType = Literal["milestone", "review_gate", "maturity_stage", "work_cycle"]
|
||||
RoadmapItemType = Literal["milestone", "review_gate", "maturity_stage", "work_cycle", "join_gate"]
|
||||
RoadmapItemStatus = Literal[
|
||||
"planned", "active", "at_risk", "reached", "moved", "discarded"
|
||||
]
|
||||
SequencingMode = Literal["sequential", "parallel", "optional"]
|
||||
DependencyType = Literal["requires", "blocks", "related", "parallel_group", "optional_branch"]
|
||||
|
||||
ROADMAP_ITEM_TYPES = frozenset({"milestone", "review_gate", "maturity_stage", "work_cycle"})
|
||||
ROADMAP_ITEM_TYPES = frozenset({"milestone", "review_gate", "maturity_stage", "work_cycle", "join_gate"})
|
||||
ROADMAP_ITEM_STATUSES = frozenset(
|
||||
{"planned", "active", "at_risk", "reached", "moved", "discarded"}
|
||||
)
|
||||
@@ -32,7 +32,7 @@ TERMINAL_STATUSES = frozenset({"reached", "moved", "discarded"})
|
||||
|
||||
def _serialize_row(row: dict[str, Any]) -> dict[str, Any]:
|
||||
result = dict(row)
|
||||
for key in ("id", "tenant_id", "roadmap_id", "initiative_id", "from_item_id", "to_item_id"):
|
||||
for key in ("id", "tenant_id", "roadmap_id", "initiative_id", "from_item_id", "to_item_id", "strand_project_id"):
|
||||
if result.get(key):
|
||||
result[key] = str(result[key])
|
||||
if result.get("target_date"):
|
||||
@@ -185,6 +185,7 @@ def list_roadmap_items_for_initiative(
|
||||
ri.id, ri.tenant_id, ri.roadmap_id, r.initiative_id,
|
||||
ri.item_type, ri.title, ri.goal_description, ri.definition_of_done,
|
||||
ri.status, ri.sequencing_mode, ri.target_date, ri.sort_order,
|
||||
ri.strand_project_id,
|
||||
ri.created_at, ri.updated_at
|
||||
FROM roadmap_items ri
|
||||
JOIN roadmaps r ON r.id = ri.roadmap_id AND r.tenant_id = ri.tenant_id
|
||||
@@ -208,6 +209,7 @@ def get_roadmap_item(*, tenant_id: str, item_id: str) -> Optional[dict[str, Any]
|
||||
ri.id, ri.tenant_id, ri.roadmap_id, r.initiative_id,
|
||||
ri.item_type, ri.title, ri.goal_description, ri.definition_of_done,
|
||||
ri.status, ri.sequencing_mode, ri.target_date, ri.sort_order,
|
||||
ri.strand_project_id,
|
||||
ri.created_at, ri.updated_at
|
||||
FROM roadmap_items ri
|
||||
JOIN roadmaps r ON r.id = ri.roadmap_id AND r.tenant_id = ri.tenant_id
|
||||
@@ -233,6 +235,7 @@ def create_roadmap_item(
|
||||
sequencing_mode: SequencingMode = "sequential",
|
||||
target_date: Optional[date] = None,
|
||||
sort_order: int = 0,
|
||||
strand_project_id: Optional[str] = None,
|
||||
initial_criterion_title: Optional[str] = None,
|
||||
user_id: Optional[str] = None,
|
||||
) -> dict[str, Any]:
|
||||
@@ -255,12 +258,13 @@ def create_roadmap_item(
|
||||
"""
|
||||
INSERT INTO roadmap_items (
|
||||
tenant_id, roadmap_id, item_type, title, goal_description,
|
||||
definition_of_done, status, sequencing_mode, target_date, sort_order
|
||||
definition_of_done, status, sequencing_mode, target_date, sort_order,
|
||||
strand_project_id
|
||||
)
|
||||
VALUES (%s, %s, %s, %s, %s, %s::jsonb, %s, %s, %s, %s)
|
||||
VALUES (%s, %s, %s, %s, %s, %s::jsonb, %s, %s, %s, %s, %s)
|
||||
RETURNING id, tenant_id, roadmap_id, item_type, title, goal_description,
|
||||
definition_of_done, status, sequencing_mode, target_date,
|
||||
sort_order, created_at, updated_at
|
||||
sort_order, strand_project_id, created_at, updated_at
|
||||
""",
|
||||
(
|
||||
tenant_id,
|
||||
@@ -273,11 +277,12 @@ def create_roadmap_item(
|
||||
sequencing_mode,
|
||||
target_date,
|
||||
sort_order,
|
||||
strand_project_id,
|
||||
),
|
||||
)
|
||||
row = _serialize_row(dict(cur.fetchone()))
|
||||
row["initiative_id"] = initiative_id
|
||||
if item_type != "work_cycle":
|
||||
if item_type not in ("work_cycle", "join_gate"):
|
||||
create_default_criterion(
|
||||
cur,
|
||||
tenant_id=tenant_id,
|
||||
@@ -324,6 +329,8 @@ def update_roadmap_item(
|
||||
target_date: Optional[date] = None,
|
||||
clear_target_date: bool = False,
|
||||
sort_order: Optional[int] = None,
|
||||
strand_project_id: Optional[str] = None,
|
||||
clear_strand_project: bool = False,
|
||||
) -> Optional[dict[str, Any]]:
|
||||
existing = get_roadmap_item(tenant_id=tenant_id, item_id=item_id)
|
||||
if not existing:
|
||||
@@ -373,6 +380,11 @@ def update_roadmap_item(
|
||||
if sort_order is not None:
|
||||
updates.append("sort_order = %s")
|
||||
params.append(sort_order)
|
||||
if clear_strand_project:
|
||||
updates.append("strand_project_id = NULL")
|
||||
elif strand_project_id is not None:
|
||||
updates.append("strand_project_id = %s")
|
||||
params.append(strand_project_id)
|
||||
|
||||
if not updates:
|
||||
return existing
|
||||
@@ -383,14 +395,22 @@ def update_roadmap_item(
|
||||
conn = get_connection()
|
||||
try:
|
||||
with conn.cursor(cursor_factory=RealDictCursor) as cur:
|
||||
if status == "active" and existing.get("item_type") == "maturity_stage":
|
||||
from services.maturity_practice import enforce_single_active_maturity_stage
|
||||
if (
|
||||
status == "active"
|
||||
and existing.get("item_type") == "maturity_stage"
|
||||
):
|
||||
from services.progression_graph import (
|
||||
enforce_single_active_work_gate_per_strand,
|
||||
)
|
||||
|
||||
enforce_single_active_maturity_stage(
|
||||
enforce_single_active_work_gate_per_strand(
|
||||
cur,
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=str(existing["initiative_id"]),
|
||||
keep_active_id=item_id,
|
||||
strand_project_id=strand_project_id
|
||||
if strand_project_id is not None
|
||||
else existing.get("strand_project_id"),
|
||||
)
|
||||
cur.execute(
|
||||
f"""
|
||||
@@ -399,7 +419,7 @@ def update_roadmap_item(
|
||||
WHERE id = %s AND tenant_id = %s
|
||||
RETURNING id, tenant_id, roadmap_id, item_type, title, goal_description,
|
||||
definition_of_done, status, sequencing_mode, target_date,
|
||||
sort_order, created_at, updated_at
|
||||
sort_order, strand_project_id, created_at, updated_at
|
||||
""",
|
||||
params,
|
||||
)
|
||||
@@ -652,6 +672,10 @@ def verify_reached(
|
||||
raise ValueError("RoadmapItem nicht gefunden")
|
||||
if item["status"] in TERMINAL_STATUSES:
|
||||
raise ValueError(f"RoadmapItem bereits terminal: {item['status']}")
|
||||
if item.get("item_type") == "join_gate":
|
||||
raise ValueError(
|
||||
"Join-Knoten schaltet automatisch, wenn alle Eingänge erreicht sind — kein manuelles Verify"
|
||||
)
|
||||
|
||||
initiative_id = item["initiative_id"]
|
||||
conn = get_connection()
|
||||
@@ -694,7 +718,7 @@ def verify_reached(
|
||||
WHERE id = %s AND tenant_id = %s
|
||||
RETURNING id, tenant_id, roadmap_id, item_type, title, goal_description,
|
||||
definition_of_done, status, sequencing_mode, target_date,
|
||||
sort_order, created_at, updated_at
|
||||
sort_order, strand_project_id, created_at, updated_at
|
||||
""",
|
||||
(item_id, tenant_id),
|
||||
)
|
||||
@@ -718,9 +742,9 @@ def verify_reached(
|
||||
details={"roadmap_item_id": item_id, "verify_reason": verify_reason},
|
||||
)
|
||||
if row.get("item_type") == "maturity_stage":
|
||||
from services.maturity_stage_transition import on_maturity_stage_reached
|
||||
from services.progression_graph import on_work_gate_reached
|
||||
|
||||
transition = on_maturity_stage_reached(
|
||||
transition = on_work_gate_reached(
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=initiative_id,
|
||||
reached_item_id=item_id,
|
||||
@@ -770,13 +794,16 @@ def reopen_roadmap_item(
|
||||
try:
|
||||
with conn.cursor(cursor_factory=RealDictCursor) as cur:
|
||||
if item.get("item_type") == "maturity_stage":
|
||||
from services.maturity_practice import enforce_single_active_maturity_stage
|
||||
from services.progression_graph import (
|
||||
enforce_single_active_work_gate_per_strand,
|
||||
)
|
||||
|
||||
enforce_single_active_maturity_stage(
|
||||
enforce_single_active_work_gate_per_strand(
|
||||
cur,
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=str(item["initiative_id"]),
|
||||
keep_active_id=item_id,
|
||||
strand_project_id=item.get("strand_project_id"),
|
||||
)
|
||||
cur.execute(
|
||||
"""
|
||||
@@ -785,7 +812,7 @@ def reopen_roadmap_item(
|
||||
WHERE id = %s AND tenant_id = %s
|
||||
RETURNING id, tenant_id, roadmap_id, item_type, title, goal_description,
|
||||
definition_of_done, status, sequencing_mode, target_date,
|
||||
sort_order, created_at, updated_at
|
||||
sort_order, strand_project_id, created_at, updated_at
|
||||
""",
|
||||
(item_id, tenant_id),
|
||||
)
|
||||
|
||||
@@ -74,13 +74,14 @@ def _reopen_item_if_reached(
|
||||
if item["status"] != "reached":
|
||||
return
|
||||
if item.get("item_type") == "maturity_stage":
|
||||
from services.maturity_practice import enforce_single_active_maturity_stage
|
||||
from services.progression_graph import enforce_single_active_work_gate_per_strand
|
||||
|
||||
enforce_single_active_maturity_stage(
|
||||
enforce_single_active_work_gate_per_strand(
|
||||
cur,
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=str(item["initiative_id"]),
|
||||
keep_active_id=item["id"],
|
||||
strand_project_id=item.get("strand_project_id"),
|
||||
)
|
||||
cur.execute(
|
||||
"""
|
||||
|
||||
Reference in new issue
Block a user