Offer the current exercise through an explicit API switch.
Deploy Development / deploy (push) Successful in 53s
Test Suite / pytest-backend (push) Failing after 29s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 16s
Test Suite / k6 /health Baseline (push) Successful in 35s
Test Suite / playwright-tests (push) Failing after 7m42s
Deploy Development / deploy (push) Successful in 53s
Test Suite / pytest-backend (push) Failing after 29s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 16s
Test Suite / k6 /health Baseline (push) Successful in 35s
Test Suite / playwright-tests (push) Failing after 7m42s
The exercise list turns the live catalog on or off for the caller's edit rights. A distribution key reads that current selection and the changes since its last cursor. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
4ad62b6e38
commit
b59b7eae16
13 files changed
+488
-5
No files matched your search
@@ -30,6 +30,8 @@ from distribution_service import (
|
||||
issue_key,
|
||||
list_changes,
|
||||
list_release_drift,
|
||||
load_catalog,
|
||||
load_catalog_exercise,
|
||||
load_asset,
|
||||
load_availability,
|
||||
load_manifest,
|
||||
@@ -144,6 +146,65 @@ class ReasonBody(BaseModel):
|
||||
reason_code: str
|
||||
|
||||
|
||||
@router.get("/catalog")
|
||||
def get_catalog(cursor: Optional[str] = None, authorization: Optional[str] = Header(default=None)):
|
||||
binding = _machine(authorization)
|
||||
try:
|
||||
assert_exercise_object(binding.get("objects"))
|
||||
except HTTPException as exc:
|
||||
exc.headers = {**(exc.headers or {}), **NO_STORE}
|
||||
raise exc
|
||||
held: Optional[HTTPException] = None
|
||||
payload = None
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
try:
|
||||
payload = load_catalog(cur, binding, cursor)
|
||||
except InvalidCursor:
|
||||
held = HTTPException(
|
||||
status_code=400,
|
||||
detail={"code": "invalid_cursor", "message": "Cursor ungültig."},
|
||||
)
|
||||
except HTTPException as exc:
|
||||
held = exc
|
||||
else:
|
||||
conn.commit()
|
||||
if held is not None:
|
||||
held.headers = {**(held.headers or {}), **NO_STORE}
|
||||
raise held
|
||||
return Response(
|
||||
content=__import__("json").dumps(payload, ensure_ascii=False, separators=(",", ":")),
|
||||
media_type="application/json",
|
||||
headers=NO_STORE,
|
||||
)
|
||||
|
||||
|
||||
@router.get("/catalog/{source_id}")
|
||||
def get_catalog_exercise(source_id: str, authorization: Optional[str] = Header(default=None)):
|
||||
binding = _machine(authorization)
|
||||
try:
|
||||
assert_exercise_object(binding.get("objects"))
|
||||
except HTTPException as exc:
|
||||
exc.headers = {**(exc.headers or {}), **NO_STORE}
|
||||
raise exc
|
||||
held: Optional[HTTPException] = None
|
||||
payload = None
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
try:
|
||||
payload = load_catalog_exercise(cur, binding, source_id)
|
||||
except HTTPException as exc:
|
||||
held = exc
|
||||
if held is not None:
|
||||
held.headers = {**(held.headers or {}), **NO_STORE}
|
||||
raise held
|
||||
return Response(
|
||||
content=__import__("json").dumps(payload, ensure_ascii=False, separators=(",", ":")),
|
||||
media_type="application/json",
|
||||
headers=NO_STORE,
|
||||
)
|
||||
|
||||
|
||||
@router.get("/changes")
|
||||
def get_changes(
|
||||
cursor: Optional[str] = None,
|
||||
|
||||
@@ -451,6 +451,11 @@ _MAX_BULK_METADATA_IDS = 500
|
||||
_MAX_BULK_RELATION_IDS_PER_KIND = 80
|
||||
|
||||
|
||||
class ExerciseApiOfferingPatch(BaseModel):
|
||||
exercise_ids: list[int] = Field(..., min_length=1, max_length=_MAX_BULK_METADATA_IDS)
|
||||
api_offered: bool
|
||||
|
||||
|
||||
class ExerciseBulkMetadataPatch(BaseModel):
|
||||
"""Massenänderung: Sichtbarkeit/Status und/oder Zuordnungen (Kataloge)."""
|
||||
|
||||
@@ -1501,6 +1506,41 @@ def _assert_can_delete_exercise(cur, tenant: TenantContext, row: dict) -> None:
|
||||
)
|
||||
|
||||
|
||||
@router.patch("/exercises/api-offering")
|
||||
def patch_exercise_api_offering(
|
||||
body: ExerciseApiOfferingPatch,
|
||||
tenant: TenantContext = Depends(get_tenant_context),
|
||||
):
|
||||
"""Schaltet die aktuelle API-Bereitstellung. Rechte sind die Bearbeitungsrechte der Übung."""
|
||||
unique_ids = sorted({int(item) for item in body.exercise_ids if item is not None and int(item) > 0})
|
||||
if not unique_ids:
|
||||
raise HTTPException(status_code=400, detail="Keine gültigen Übungs-IDs")
|
||||
updated: List[Dict[str, Any]] = []
|
||||
denied: List[Dict[str, Any]] = []
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
for ex_id in unique_ids:
|
||||
cur.execute("SELECT id, title FROM exercises WHERE id = %s", (ex_id,))
|
||||
row = cur.fetchone()
|
||||
if not row:
|
||||
denied.append({"id": ex_id, "detail": "Übung nicht gefunden"})
|
||||
continue
|
||||
item = r2d(row)
|
||||
try:
|
||||
_assert_can_edit_exercise(cur, ex_id, tenant)
|
||||
except HTTPException as exc:
|
||||
detail = exc.detail if isinstance(exc.detail, str) else str(exc.detail)
|
||||
denied.append({"id": ex_id, "title": item.get("title"), "detail": detail})
|
||||
continue
|
||||
cur.execute(
|
||||
"UPDATE exercises SET api_offered = %s, updated_at = NOW() WHERE id = %s",
|
||||
(bool(body.api_offered), ex_id),
|
||||
)
|
||||
updated.append({"id": ex_id, "title": item.get("title"), "api_offered": bool(body.api_offered)})
|
||||
conn.commit()
|
||||
return {"updated": updated, "denied": denied}
|
||||
|
||||
|
||||
@router.patch("/exercises/bulk-metadata")
|
||||
def bulk_patch_exercises_metadata(
|
||||
body: ExerciseBulkMetadataPatch,
|
||||
@@ -2140,7 +2180,7 @@ def list_exercises(
|
||||
|
||||
# Query (primary_focus_name für Listen-Ansicht gemäß Spec-Beispiel „focus_area“-Label)
|
||||
query = f"""
|
||||
SELECT e.id, e.title, e.summary, e.visibility, e.status,
|
||||
SELECT e.id, e.title, e.summary, e.visibility, e.status, e.api_offered,
|
||||
e.exercise_kind, e.method_archetype,
|
||||
e.created_by, p.name as creator_name,
|
||||
e.club_id, c.name as club_name,
|
||||
@@ -2213,6 +2253,7 @@ def list_exercises(
|
||||
d["training_type_names"] = _coerce_json_str_list(d.get("training_type_names"))
|
||||
d["variant_count"] = int(d.get("variant_count") or 0)
|
||||
d["media_count"] = int(d.get("media_count") or 0)
|
||||
d["api_offered"] = bool(d.get("api_offered"))
|
||||
if include_variants:
|
||||
v = d.get("variants")
|
||||
if isinstance(v, str):
|
||||
|
||||
Reference in new issue
Block a user