AP1.8a: Portfolio-Rang im Cockpit mit Reorder und Next-Action-Sortierung.
Deploy Development / deploy (push) Successful in 50s
Test Suite / pytest-backend (push) Successful in 2m21s
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 21s
Deploy Development / deploy (push) Successful in 50s
Test Suite / pytest-backend (push) Successful in 2m21s
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 21s
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
d7aefed0de
commit
a19c6abd26
16 files changed
+426
-34
No files matched your search
@@ -18,7 +18,7 @@ PRIORITIES = frozenset({"low", "normal", "high"})
|
||||
|
||||
_INITIATIVE_COLUMNS = """
|
||||
id, tenant_id, title, goal, vision, target_state_summary, archetype_key,
|
||||
status, priority, owner_actor_id, created_at, updated_at
|
||||
status, priority, portfolio_rank, owner_actor_id, created_at, updated_at
|
||||
"""
|
||||
|
||||
|
||||
@@ -87,13 +87,22 @@ def create_initiative(
|
||||
conn = get_connection()
|
||||
try:
|
||||
with conn.cursor(cursor_factory=RealDictCursor) as cur:
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT COALESCE(MAX(portfolio_rank), -1) + 1 AS next_rank
|
||||
FROM initiatives
|
||||
WHERE tenant_id = %s
|
||||
""",
|
||||
(tenant_id,),
|
||||
)
|
||||
next_rank = int(cur.fetchone()["next_rank"])
|
||||
cur.execute(
|
||||
f"""
|
||||
INSERT INTO initiatives (
|
||||
tenant_id, title, goal, vision, target_state_summary, archetype_key,
|
||||
status, priority, owner_actor_id
|
||||
status, priority, portfolio_rank, owner_actor_id
|
||||
)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
RETURNING {_INITIATIVE_COLUMNS}
|
||||
""",
|
||||
(
|
||||
@@ -105,6 +114,7 @@ def create_initiative(
|
||||
archetype_key,
|
||||
status,
|
||||
priority,
|
||||
next_rank,
|
||||
owner_actor_id,
|
||||
),
|
||||
)
|
||||
@@ -140,7 +150,7 @@ def list_initiatives(*, tenant_id: str) -> list[dict[str, Any]]:
|
||||
SELECT {_INITIATIVE_COLUMNS}
|
||||
FROM initiatives
|
||||
WHERE tenant_id = %s
|
||||
ORDER BY updated_at DESC, title
|
||||
ORDER BY portfolio_rank ASC NULLS LAST, updated_at DESC, title
|
||||
""",
|
||||
(tenant_id,),
|
||||
)
|
||||
@@ -294,3 +304,86 @@ def delete_initiative(
|
||||
details={"initiative_id": initiative_id},
|
||||
)
|
||||
return deleted
|
||||
|
||||
|
||||
def load_portfolio_rank_map(*, tenant_id: str) -> dict[str, Optional[int]]:
|
||||
conn = get_connection()
|
||||
try:
|
||||
with conn.cursor(cursor_factory=RealDictCursor) as cur:
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT id, portfolio_rank
|
||||
FROM initiatives
|
||||
WHERE tenant_id = %s
|
||||
""",
|
||||
(tenant_id,),
|
||||
)
|
||||
return {
|
||||
str(row["id"]): row["portfolio_rank"]
|
||||
for row in cur.fetchall()
|
||||
}
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
def reorder_portfolio(
|
||||
*,
|
||||
tenant_id: str,
|
||||
initiative_ids: list[str],
|
||||
user_id: Optional[str] = None,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""Setzt portfolio_rank für alle übergebenen Initiativen (0 = höchste Prio)."""
|
||||
if not initiative_ids:
|
||||
raise ValueError("initiative_ids darf nicht leer sein")
|
||||
|
||||
unique_ids = list(dict.fromkeys(initiative_ids))
|
||||
conn = get_connection()
|
||||
try:
|
||||
with conn.cursor(cursor_factory=RealDictCursor) as cur:
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT id
|
||||
FROM initiatives
|
||||
WHERE tenant_id = %s
|
||||
ORDER BY portfolio_rank ASC NULLS LAST, updated_at DESC, title
|
||||
""",
|
||||
(tenant_id,),
|
||||
)
|
||||
all_ids = [str(row["id"]) for row in cur.fetchall()]
|
||||
all_set = set(all_ids)
|
||||
if set(unique_ids) - all_set:
|
||||
raise ValueError("Unbekannte Initiative im Tenant")
|
||||
if len(unique_ids) != len(all_ids):
|
||||
raise ValueError("Alle Initiativen des Tenants müssen enthalten sein")
|
||||
|
||||
for rank, initiative_id in enumerate(unique_ids):
|
||||
cur.execute(
|
||||
"""
|
||||
UPDATE initiatives
|
||||
SET portfolio_rank = %s, updated_at = NOW()
|
||||
WHERE id = %s AND tenant_id = %s
|
||||
""",
|
||||
(rank, initiative_id, tenant_id),
|
||||
)
|
||||
|
||||
cur.execute(
|
||||
f"""
|
||||
SELECT {_INITIATIVE_COLUMNS}
|
||||
FROM initiatives
|
||||
WHERE tenant_id = %s
|
||||
ORDER BY portfolio_rank ASC NULLS LAST, updated_at DESC, title
|
||||
""",
|
||||
(tenant_id,),
|
||||
)
|
||||
rows = [_serialize_row(dict(row)) for row in cur.fetchall()]
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
log_audit(
|
||||
"portfolio.reordered",
|
||||
user_id=user_id,
|
||||
tenant_id=tenant_id,
|
||||
details={"initiative_ids": unique_ids},
|
||||
)
|
||||
return rows
|
||||
Reference in new issue
Block a user