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
@@ -11,7 +11,11 @@ from typing import Any, Callable, Dict, List, Mapping, Optional, Set, Tuple
|
||||
from fastapi import HTTPException
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from tenant_context import TenantContext, library_content_visibility_sql
|
||||
from tenant_context import (
|
||||
TenantContext,
|
||||
library_content_visibility_for_progression_graph_sql,
|
||||
library_content_visibility_sql,
|
||||
)
|
||||
from planning_exercise_profiles import PlanningTargetProfile
|
||||
from planning_path_qa_pipeline import run_multistage_path_qa
|
||||
from planning_path_rematch import (
|
||||
@@ -263,6 +267,90 @@ def _build_path_target_profile(
|
||||
return target, query_intent_summary, intent
|
||||
|
||||
|
||||
def _supplemental_exercise_ids_from_body(body: ProgressionPathSuggestRequest) -> List[int]:
|
||||
"""Verankerte Graph-Slots immer im Retriever-Kandidatenpool halten."""
|
||||
ids: List[int] = []
|
||||
for coll in (body.slot_assignments, body.evaluate_steps):
|
||||
for raw in coll or []:
|
||||
if raw.exercise_id is not None:
|
||||
try:
|
||||
eid = int(raw.exercise_id)
|
||||
except (TypeError, ValueError):
|
||||
continue
|
||||
if eid > 0:
|
||||
ids.append(eid)
|
||||
return list(dict.fromkeys(ids))
|
||||
|
||||
|
||||
def _planning_visibility_sql(
|
||||
cur,
|
||||
tenant: TenantContext,
|
||||
progression_graph_id: Optional[int],
|
||||
) -> Tuple[str, List[Any]]:
|
||||
if progression_graph_id and int(progression_graph_id) > 0:
|
||||
cur.execute(
|
||||
"SELECT visibility, club_id FROM exercise_progression_graphs WHERE id = %s",
|
||||
(int(progression_graph_id),),
|
||||
)
|
||||
grow = cur.fetchone()
|
||||
if grow:
|
||||
g_club = grow.get("club_id")
|
||||
return library_content_visibility_for_progression_graph_sql(
|
||||
alias="e",
|
||||
profile_id=tenant.profile_id,
|
||||
role=tenant.global_role,
|
||||
effective_club_id=tenant.effective_club_id,
|
||||
graph_visibility=str(grow.get("visibility") or "private"),
|
||||
graph_club_id=int(g_club) if g_club is not None else None,
|
||||
)
|
||||
return library_content_visibility_sql(
|
||||
alias="e",
|
||||
profile_id=tenant.profile_id,
|
||||
role=tenant.global_role,
|
||||
effective_club_id=tenant.effective_club_id,
|
||||
)
|
||||
|
||||
|
||||
def _exercise_allowed_in_progression_graph(
|
||||
exercise_row: Mapping[str, Any],
|
||||
*,
|
||||
graph_visibility: str,
|
||||
graph_club_id: Optional[int],
|
||||
profile_id: int,
|
||||
role: str,
|
||||
) -> bool:
|
||||
"""Prüft, ob eine Übung zur Sichtbarkeit des Progressionsgraphen passt."""
|
||||
from club_tenancy import is_platform_admin
|
||||
|
||||
ex_vis = (exercise_row.get("visibility") or "private").strip().lower()
|
||||
gvis = (graph_visibility or "private").strip().lower()
|
||||
if gvis == "private":
|
||||
if ex_vis == "official":
|
||||
return True
|
||||
if ex_vis == "club":
|
||||
return True
|
||||
if ex_vis == "private":
|
||||
if is_platform_admin(role):
|
||||
return True
|
||||
try:
|
||||
return int(exercise_row.get("created_by") or 0) == int(profile_id)
|
||||
except (TypeError, ValueError):
|
||||
return False
|
||||
return False
|
||||
if gvis == "club":
|
||||
if ex_vis == "official":
|
||||
return True
|
||||
if ex_vis != "club":
|
||||
return False
|
||||
ex_club = exercise_row.get("club_id")
|
||||
if ex_club is None:
|
||||
return False
|
||||
if graph_club_id is None:
|
||||
return True
|
||||
return int(ex_club) == int(graph_club_id)
|
||||
return ex_vis == "official"
|
||||
|
||||
|
||||
def _slot_assignments_by_major_index(
|
||||
assignments: Optional[List[EvaluateStepPayload]],
|
||||
) -> Dict[int, EvaluateStepPayload]:
|
||||
@@ -280,16 +368,32 @@ def _path_step_from_slot_assignment(
|
||||
assignment: EvaluateStepPayload,
|
||||
stage_spec: StageSpecArtifact,
|
||||
major_step: Optional[MajorStep],
|
||||
tenant: Optional[TenantContext] = None,
|
||||
progression_graph_id: Optional[int] = None,
|
||||
) -> Optional[Dict[str, Any]]:
|
||||
"""Bestehende Slot-Zuordnung aus dem Graph-Editor (nach KI-Anlage) übernehmen."""
|
||||
eid = int(assignment.exercise_id)
|
||||
cur.execute(
|
||||
"SELECT id, title, summary FROM exercises WHERE id = %s",
|
||||
"SELECT id, title, summary, visibility, club_id, created_by FROM exercises WHERE id = %s",
|
||||
(eid,),
|
||||
)
|
||||
row = cur.fetchone()
|
||||
if not row:
|
||||
return None
|
||||
if tenant and progression_graph_id:
|
||||
cur.execute(
|
||||
"SELECT visibility, club_id FROM exercise_progression_graphs WHERE id = %s",
|
||||
(int(progression_graph_id),),
|
||||
)
|
||||
grow = cur.fetchone()
|
||||
if grow and not _exercise_allowed_in_progression_graph(
|
||||
row,
|
||||
graph_visibility=str(grow.get("visibility") or "private"),
|
||||
graph_club_id=int(grow["club_id"]) if grow.get("club_id") is not None else None,
|
||||
profile_id=tenant.profile_id,
|
||||
role=tenant.global_role,
|
||||
):
|
||||
return None
|
||||
title = (assignment.title or row.get("title") or "").strip() or str(row.get("title") or "")
|
||||
step = {
|
||||
"exercise_id": eid,
|
||||
@@ -366,6 +470,7 @@ def _run_path_step_retrieval(
|
||||
path_context_note: Optional[str] = None,
|
||||
path_primary_topic: Optional[str] = None,
|
||||
path_technique_excludes: Optional[List[str]] = None,
|
||||
supplemental_exercise_ids: Optional[List[int]] = None,
|
||||
) -> Tuple[List[Dict[str, Any]], PlanningTargetProfile, Dict[str, Any], str]:
|
||||
step_query = step_query_override or step_retrieval_query(
|
||||
semantic_brief, goal_query, step_index, max_steps
|
||||
@@ -469,13 +574,10 @@ def _run_path_step_retrieval(
|
||||
else:
|
||||
weights = apply_path_retrieval_weights(semantic_brief)
|
||||
|
||||
profile_id = tenant.profile_id
|
||||
role = tenant.global_role
|
||||
vis_sql, vis_params = library_content_visibility_sql(
|
||||
alias="e",
|
||||
profile_id=profile_id,
|
||||
role=role,
|
||||
effective_club_id=tenant.effective_club_id,
|
||||
vis_sql, vis_params = _planning_visibility_sql(
|
||||
cur,
|
||||
tenant,
|
||||
progression_graph_id,
|
||||
)
|
||||
|
||||
hits, _skills_by_ex, _full_lib = run_multistage_planning_retrieval(
|
||||
@@ -488,6 +590,7 @@ def _run_path_step_retrieval(
|
||||
intent=intent,
|
||||
intent_weights=weights,
|
||||
pack=pack,
|
||||
supplemental_exercise_ids=supplemental_exercise_ids,
|
||||
)
|
||||
hits = _enrich_planning_hits_with_variant_meta(cur, hits[:32])
|
||||
return hits, target_profile, query_intent_summary, intent
|
||||
@@ -506,6 +609,7 @@ def _make_bridge_search_fn(
|
||||
planned_ids: List[int],
|
||||
path_target_profile: PlanningTargetProfile,
|
||||
path_intent: str,
|
||||
supplemental_exercise_ids: Optional[List[int]] = None,
|
||||
) -> Callable[..., List[Dict[str, Any]]]:
|
||||
def _bridge_search(
|
||||
step_a: Dict[str, Any],
|
||||
@@ -529,6 +633,7 @@ def _make_bridge_search_fn(
|
||||
step_a=step_a,
|
||||
step_b=step_b,
|
||||
path_target_profile=path_target_profile,
|
||||
supplemental_exercise_ids=supplemental_exercise_ids,
|
||||
path_intent=path_intent,
|
||||
)
|
||||
gated = [
|
||||
@@ -740,6 +845,7 @@ def _match_roadmap_slot(
|
||||
path_context_note=path_context_note,
|
||||
path_primary_topic=path_primary or None,
|
||||
path_technique_excludes=path_tech_excludes or None,
|
||||
supplemental_exercise_ids=_supplemental_exercise_ids_from_body(body),
|
||||
)
|
||||
|
||||
hit = _pick_best_path_hit(
|
||||
@@ -933,6 +1039,8 @@ def _build_steps_roadmap_first(
|
||||
assignment=assignments[major_idx],
|
||||
stage_spec=stage_spec,
|
||||
major_step=majors_by_index.get(major_idx),
|
||||
tenant=tenant,
|
||||
progression_graph_id=body.progression_graph_id,
|
||||
)
|
||||
if pinned:
|
||||
steps.append(pinned)
|
||||
@@ -1471,6 +1579,7 @@ def suggest_progression_path(
|
||||
semantic_brief=semantic_brief,
|
||||
path_target_profile=path_target_profile,
|
||||
path_intent=path_intent,
|
||||
supplemental_exercise_ids=_supplemental_exercise_ids_from_body(body),
|
||||
)
|
||||
|
||||
hit = _pick_best_path_hit(hits, used, semantic_brief=semantic_brief)
|
||||
@@ -1531,6 +1640,7 @@ def suggest_progression_path(
|
||||
planned_ids=planned_ids,
|
||||
path_target_profile=path_target_profile,
|
||||
path_intent=path_intent,
|
||||
supplemental_exercise_ids=_supplemental_exercise_ids_from_body(body),
|
||||
)
|
||||
steps, bridge_inserts, unfilled_gaps = insert_bridge_exercises(
|
||||
cur,
|
||||
|
||||
Reference in new issue
Block a user