Enhance Exercise Progression Graph Functionality and Visibility Logic
Deploy Development / deploy (push) Successful in 50s
Test Suite / pytest-backend (push) Successful in 44s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 14s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m16s
Deploy Development / deploy (push) Successful in 50s
Test Suite / pytest-backend (push) Successful in 44s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 14s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m16s
- Introduced new functions for handling exercise visibility in progression graphs, including `library_content_visibility_for_progression_graph_sql` to manage visibility based on graph context. - Added `_supplemental_exercise_ids_from_body` to extract exercise IDs from request bodies, improving data handling in path suggestions. - Implemented visibility promotion candidate retrieval in the API, allowing for the identification of private exercises that need visibility adjustments when promoting graph visibility. - Enhanced existing SQL queries and retrieval functions to incorporate new visibility logic, ensuring accurate exercise visibility based on user roles and graph settings. - Updated frontend components to support visibility promotion workflows, including user prompts for managing private exercises during graph visibility changes. - Added tests to validate new visibility logic and ensure robustness in exercise retrieval and promotion processes.
This commit is contained in:
1 parent
7203c871fc
commit
b464047c3a
7 files changed
+447
-11
No files matched your search
@@ -3,6 +3,7 @@ Progressionsgraph zwischen Übungen (Übung → Übung), Migration 032–034.
|
||||
Optional Übungsvarianten als Knoten-Endpunkte; Sequenz-Bulk-Anlage.
|
||||
AuthZ analog training_plan_templates: Bearbeiten/Löschen wie Übungen; Governance-Übergänge zentral.
|
||||
"""
|
||||
import json
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
@@ -256,6 +257,127 @@ def get_progression_graph(
|
||||
return row
|
||||
|
||||
|
||||
def _exercise_ids_from_planning_roadmap(artifact: Optional[Dict[str, Any]]) -> set[int]:
|
||||
ids: set[int] = set()
|
||||
if not artifact or not isinstance(artifact, dict):
|
||||
return ids
|
||||
for slot in artifact.get("slot_contents") or []:
|
||||
if not isinstance(slot, dict):
|
||||
continue
|
||||
primary = slot.get("primary") if isinstance(slot.get("primary"), dict) else {}
|
||||
if primary.get("kind") == "library" and primary.get("exercise_id") is not None:
|
||||
try:
|
||||
ids.add(int(primary["exercise_id"]))
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
for sib in slot.get("siblings") or []:
|
||||
if not isinstance(sib, dict):
|
||||
continue
|
||||
if sib.get("kind") == "library" and sib.get("exercise_id") is not None:
|
||||
try:
|
||||
ids.add(int(sib["exercise_id"]))
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
return ids
|
||||
|
||||
|
||||
def _collect_graph_referenced_exercise_ids(cur, graph_id: int) -> set[int]:
|
||||
ids: set[int] = set()
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT from_exercise_id, to_exercise_id
|
||||
FROM exercise_progression_edges
|
||||
WHERE graph_id = %s
|
||||
""",
|
||||
(graph_id,),
|
||||
)
|
||||
for row in cur.fetchall():
|
||||
for key in ("from_exercise_id", "to_exercise_id"):
|
||||
raw = row.get(key)
|
||||
if raw is not None:
|
||||
ids.add(int(raw))
|
||||
cur.execute(
|
||||
"SELECT planning_roadmap FROM exercise_progression_graphs WHERE id = %s",
|
||||
(graph_id,),
|
||||
)
|
||||
prow = cur.fetchone()
|
||||
if prow and prow.get("planning_roadmap"):
|
||||
art = prow["planning_roadmap"]
|
||||
if isinstance(art, str):
|
||||
try:
|
||||
art = json.loads(art)
|
||||
except json.JSONDecodeError:
|
||||
art = None
|
||||
ids |= _exercise_ids_from_planning_roadmap(art if isinstance(art, dict) else None)
|
||||
return ids
|
||||
|
||||
|
||||
@router.get("/exercise-progression-graphs/{graph_id}/visibility-promotion-candidates")
|
||||
def list_visibility_promotion_candidates(
|
||||
graph_id: int,
|
||||
target_visibility: str = Query(default="club", pattern="^(club|official)$"),
|
||||
tenant: TenantContext = Depends(get_tenant_context),
|
||||
):
|
||||
"""
|
||||
Private Übungen im Graph, die bei Promotion des Graphen mit angehoben werden müssten.
|
||||
"""
|
||||
profile_id = tenant.profile_id
|
||||
role = tenant.global_role
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
row = _require_graph_read(cur, graph_id, profile_id, role)
|
||||
graph_vis = (row.get("visibility") or "private").strip().lower()
|
||||
if graph_vis != "private" or target_visibility != "club":
|
||||
return {
|
||||
"graph_id": graph_id,
|
||||
"graph_visibility": graph_vis,
|
||||
"target_visibility": target_visibility,
|
||||
"exercises": [],
|
||||
}
|
||||
ref_ids = _collect_graph_referenced_exercise_ids(cur, graph_id)
|
||||
if not ref_ids:
|
||||
return {
|
||||
"graph_id": graph_id,
|
||||
"graph_visibility": graph_vis,
|
||||
"target_visibility": target_visibility,
|
||||
"exercises": [],
|
||||
}
|
||||
ph = ",".join(["%s"] * len(ref_ids))
|
||||
cur.execute(
|
||||
f"""
|
||||
SELECT id, title, visibility, club_id, created_by
|
||||
FROM exercises
|
||||
WHERE id IN ({ph})
|
||||
AND LOWER(TRIM(COALESCE(visibility, ''))) = 'private'
|
||||
ORDER BY title
|
||||
""",
|
||||
list(ref_ids),
|
||||
)
|
||||
exercises = []
|
||||
for ex in cur.fetchall():
|
||||
exd = r2d(ex)
|
||||
if not library_content_visible_to_profile(
|
||||
cur,
|
||||
profile_id,
|
||||
role,
|
||||
exd,
|
||||
):
|
||||
continue
|
||||
exercises.append(
|
||||
{
|
||||
"id": exd["id"],
|
||||
"title": exd.get("title"),
|
||||
"visibility": exd.get("visibility"),
|
||||
}
|
||||
)
|
||||
return {
|
||||
"graph_id": graph_id,
|
||||
"graph_visibility": graph_vis,
|
||||
"target_visibility": target_visibility,
|
||||
"exercises": exercises,
|
||||
}
|
||||
|
||||
|
||||
@router.post("/exercise-progression-graphs", status_code=201)
|
||||
def create_progression_graph(
|
||||
body: ProgressionGraphCreate,
|
||||
|
||||
Reference in new issue
Block a user