feat: update version to 0.7.4 and enhance maturity model functionality
Deploy Development / deploy (push) Successful in 36s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 5s
Test Suite / playwright-tests (push) Failing after 1m59s

- Incremented application version to 0.7.4 and updated database schema version to 20260427027.
- Enhanced maturity model context bindings to support new filtering options for training styles.
- Introduced new API endpoints for importing and exporting maturity model bundles.
- Updated frontend components to include a matrix view and improved admin UI for managing maturity models.
- Documented changes in the changelog for version 0.7.4, detailing new features and improvements.
This commit is contained in:
Lars committed 2026-04-27 12:48:22 +02:00
1 parent 3397b2094d
commit f2c007cc68
8 files changed
+1043 -71

No files matched your search

@@ -0,0 +1,17 @@
-- Migration 027: Kontext-Bindings – Fokus + Trainingsstil ohne Stilrichtung (z. B. Karate + Breitensport)
-- Ersetzt die alte CHECK-Constraint-Kette; partielle Unique-Indizes für alle vier Kombinationen.
-- Datum: 2026-04-27
ALTER TABLE maturity_model_context_bindings DROP CONSTRAINT IF EXISTS chk_mcb_tier;
DROP INDEX IF EXISTS uq_mmcb_focus_style_ttype;
-- Fokus + Stilrichtung + Trainingsstil (alle drei gesetzt)
CREATE UNIQUE INDEX IF NOT EXISTS uq_mmcb_focus_style_training
ON maturity_model_context_bindings (focus_area_id, style_direction_id, training_type_id)
WHERE style_direction_id IS NOT NULL AND training_type_id IS NOT NULL;
-- Fokus + Trainingsstil (ohne Stilrichtung)
CREATE UNIQUE INDEX IF NOT EXISTS uq_mmcb_focus_training
ON maturity_model_context_bindings (focus_area_id, training_type_id)
WHERE style_direction_id IS NULL AND training_type_id IS NOT NULL;
+437 -51
View File
@@ -6,9 +6,11 @@ Kontext zu Fokusbereich, Stilrichtung, Zielgruppe: jeweils M:N (leer = gilt übe
Lesen: alle authentifizierten Nutzer.
Schreiben: admin, superadmin.
"""
from datetime import datetime, timezone
from typing import Any, Dict, List, Optional, Sequence
from fastapi import APIRouter, Depends, HTTPException, Query
from fastapi.responses import JSONResponse
from auth import require_auth
from db import get_db, get_cursor, r2d
@@ -252,6 +254,31 @@ def _binding_model_active(cur, maturity_model_id: int) -> bool:
return bool(b and b.get("status") == "active")
def _binding_matches_query_dims(
style_direction_id: Optional[int],
training_type_id: Optional[int],
b_style: Any,
b_tt: Any,
) -> bool:
"""Zeile passt zur Abfrage, wenn gesetzte Dimensionswerte der Zeile mit der Anfrage übereinstimmen."""
if b_style is not None:
if style_direction_id is None or int(b_style) != int(style_direction_id):
return False
if b_tt is not None:
if training_type_id is None or int(b_tt) != int(training_type_id):
return False
return True
def _binding_dim_count(b_style: Any, b_tt: Any) -> int:
n = 0
if b_style is not None:
n += 1
if b_tt is not None:
n += 1
return n
def _resolve_binding_model_ids(
cur,
focus_area_id: int,
@@ -259,51 +286,44 @@ def _resolve_binding_model_ids(
training_type_id: Optional[int],
) -> List[int]:
"""
Kette Basis → Stilrichtung → Trainingsstil (training_types).
Ohne Basis-Zeile (nur Fokus): leere Liste → Aufrufer nutzt Legacy-Resolve.
Nur **aktive** Modelle werden eingereiht; inaktive Overlays werden übersprungen.
Alle Bindings zum Fokus, die zur Abfrage passen (inkl. Fokus+Trainingsstil ohne Stilrichtung),
sortiert nach Spezifität (weniger spezifisch zuerst). Gleiche model_id nur einmal.
Nur aktive Modelle. Leere Liste → Legacy-Resolve.
"""
chain: List[int] = []
cur.execute(
"""
SELECT maturity_model_id FROM maturity_model_context_bindings
WHERE focus_area_id = %s AND style_direction_id IS NULL AND training_type_id IS NULL
SELECT id, maturity_model_id, style_direction_id, training_type_id
FROM maturity_model_context_bindings
WHERE focus_area_id = %s
""",
(focus_area_id,),
)
r = cur.fetchone()
if not r:
rows = [r2d(r) for r in cur.fetchall()]
matching: List[Dict[str, Any]] = []
for r in rows:
if _binding_matches_query_dims(
style_direction_id,
training_type_id,
r.get("style_direction_id"),
r.get("training_type_id"),
):
matching.append(r)
if not matching:
return []
mid0 = int(r["maturity_model_id"])
if not _binding_model_active(cur, mid0):
return []
chain.append(mid0)
if style_direction_id is not None:
cur.execute(
"""
SELECT maturity_model_id FROM maturity_model_context_bindings
WHERE focus_area_id = %s AND style_direction_id = %s AND training_type_id IS NULL
""",
(focus_area_id, style_direction_id),
matching.sort(
key=lambda r: (
_binding_dim_count(r.get("style_direction_id"), r.get("training_type_id")),
int(r["id"]),
)
r2 = cur.fetchone()
if r2 and _binding_model_active(cur, int(r2["maturity_model_id"])):
chain.append(int(r2["maturity_model_id"]))
if style_direction_id is not None and training_type_id is not None:
cur.execute(
"""
SELECT maturity_model_id FROM maturity_model_context_bindings
WHERE focus_area_id = %s AND style_direction_id = %s AND training_type_id = %s
""",
(focus_area_id, style_direction_id, training_type_id),
)
r3 = cur.fetchone()
if r3 and _binding_model_active(cur, int(r3["maturity_model_id"])):
chain.append(int(r3["maturity_model_id"]))
return chain
)
out: List[int] = []
for r in matching:
mid = int(r["maturity_model_id"])
if not _binding_model_active(cur, mid):
continue
if mid not in out:
out.append(mid)
return out
def _merge_loaded_models(loaded: List[Dict[str, Any]]) -> Dict[str, Any]:
@@ -368,7 +388,7 @@ def _merge_loaded_models(loaded: List[Dict[str, Any]]) -> Dict[str, Any]:
"resolution": {
"merged": len(loaded) > 1,
"source_model_ids": [int(m["id"]) for m in loaded],
"binding_strategy": "hierarchical_override",
"binding_strategy": "specificity_merge",
},
}
return out
@@ -417,21 +437,22 @@ def resolve_maturity_model(
target_group_id: Optional[int] = Query(default=None),
training_type_id: Optional[int] = Query(
default=None,
description="Trainingsstil (training_types, z. B. Leistungssport); nur mit Stilrichtung sinnvoll.",
description="Trainingsstil (training_types, z. B. Breitensport); auch ohne Stilrichtung nutzbar.",
),
session: dict = Depends(require_auth),
):
"""
Liefert die Fähigkeitsmatrix zum Kontext.
**Priorität 1:** Tabelle `maturity_model_context_bindings` (Fokus → optional Stilrichtung → optional Trainingsstil).
Mehrere Modelle werden zusammengeführt: spätere Stufen überschreiben Zelltexte für dieselbe Fähigkeit/Stufe.
**Priorität 1:** `maturity_model_context_bindings`: alle passenden Zeilen zum Fokus (z. B. nur Fokus,
Fokus+Stilrichtung, Fokus+Trainingsstil, alle drei) werden nach Spezifität gemerged; spezifischere
Zuordnungen überschreiben Zelltexte gleicher Fähigkeit/Stufe.
**Priorität 2 (Legacy):** Ein aktives Modell, dessen M:N-Kontext zum Filter passt (Zielgruppe unverändert).
**Priorität 2 (Legacy):** Ein aktives Modell per M:N am Modell (Zielgruppe unverändert).
"""
if focus_area_id is not None:
with get_db() as conn:
cur = get_cursor(conn)
with get_db() as conn:
cur = get_cursor(conn)
if focus_area_id is not None:
chain = _resolve_binding_model_ids(
cur,
int(focus_area_id),
@@ -442,8 +463,6 @@ def resolve_maturity_model(
loaded = [_load_full_model(cur, mid) for mid in chain]
return _merge_loaded_models(loaded)
with get_db() as conn:
cur = get_cursor(conn)
mid = _legacy_resolve_pick_model_id(
cur, focus_area_id, style_direction_id, target_group_id
)
@@ -808,9 +827,6 @@ def upsert_maturity_model_context_binding(data: Dict[str, Any], session: dict =
sd: Optional[int] = int(sd_raw) if sd_raw is not None else None
tt: Optional[int] = int(tt_raw) if tt_raw is not None else None
if sd is None and tt is not None:
raise HTTPException(400, "Trainingsstil nur zusammen mit Stilrichtung erlaubt")
with get_db() as conn:
cur = get_cursor(conn)
if not _base_maturity_model(cur, mid):
@@ -835,7 +851,7 @@ def upsert_maturity_model_context_binding(data: Dict[str, Any], session: dict =
""",
(fa,),
)
elif tt is None:
elif sd is not None and tt is None:
cur.execute(
"""
DELETE FROM maturity_model_context_bindings
@@ -843,6 +859,14 @@ def upsert_maturity_model_context_binding(data: Dict[str, Any], session: dict =
""",
(fa, sd),
)
elif sd is None and tt is not None:
cur.execute(
"""
DELETE FROM maturity_model_context_bindings
WHERE focus_area_id = %s AND style_direction_id IS NULL AND training_type_id = %s
""",
(fa, tt),
)
else:
cur.execute(
"""
@@ -897,3 +921,365 @@ def delete_maturity_model_context_binding(binding_id: int, session: dict = Depen
if not cur.fetchone():
raise HTTPException(404, "Zuordnung nicht gefunden")
return {"ok": True}
# ═══════════════════════════════════════════════════════════════════════════
# Export / Import (JSON)
# ═══════════════════════════════════════════════════════════════════════════
def _strip_model_for_export(full: Dict[str, Any]) -> Dict[str, Any]:
ms_out: List[Dict[str, Any]] = []
for ms in full.get("model_skills") or []:
ms_out.append(
{
"skill_id": ms.get("skill_id"),
"sort_order": ms.get("sort_order", 0),
"relevance": ms.get("relevance"),
"skill_name": ms.get("skill_name"),
"skill_subcategory_name": ms.get("skill_subcategory_name"),
"skill_subcategory_slug": ms.get("skill_subcategory_slug"),
"skill_main_category_name": ms.get("skill_main_category_name"),
"skill_main_category_slug": ms.get("skill_main_category_slug"),
}
)
sl_out: List[Dict[str, Any]] = []
for sl in full.get("skill_levels") or []:
sl_out.append(
{
"skill_id": sl.get("skill_id"),
"level_number": sl.get("level_number"),
"description": sl.get("description") or "",
"observable_criteria": sl.get("observable_criteria"),
"skill_name": sl.get("skill_name"),
}
)
lv_out: List[Dict[str, Any]] = []
for lv in full.get("levels") or []:
lv_out.append(
{
"level_number": lv.get("level_number"),
"name": lv.get("name"),
"description": lv.get("description"),
"sort_order": lv.get("sort_order"),
}
)
return {
"id": full.get("id"),
"name": full.get("name"),
"description": full.get("description"),
"level_count": full.get("level_count"),
"status": full.get("status"),
"version": full.get("version"),
"levels": lv_out,
"model_skills": ms_out,
"skill_levels": sl_out,
}
def _delete_bindings_for_model(cur, model_id: int) -> None:
cur.execute(
"DELETE FROM maturity_model_context_bindings WHERE maturity_model_id = %s",
(model_id,),
)
def _insert_binding_row(cur, model_id: int, fa: int, sd: Optional[int], tt: Optional[int]) -> None:
cur.execute(
"""
INSERT INTO maturity_model_context_bindings (
maturity_model_id, focus_area_id, style_direction_id, training_type_id
) VALUES (%s, %s, %s, %s)
""",
(model_id, fa, sd, tt),
)
def _apply_import_bindings(cur, model_id: int, binds: List[Dict[str, Any]]) -> None:
for b in binds:
fa = int(b["focus_area_id"])
sd_raw = b.get("style_direction_id")
tt_raw = b.get("training_type_id")
sd: Optional[int] = int(sd_raw) if sd_raw is not None else None
tt: Optional[int] = int(tt_raw) if tt_raw is not None else None
cur.execute("SELECT id FROM focus_areas WHERE id = %s", (fa,))
if not cur.fetchone():
continue
if sd is not None:
cur.execute("SELECT id FROM style_directions WHERE id = %s", (sd,))
if not cur.fetchone():
continue
if tt is not None:
cur.execute("SELECT id FROM training_types WHERE id = %s", (tt,))
if not cur.fetchone():
continue
if sd is None and tt is None:
cur.execute(
"""
DELETE FROM maturity_model_context_bindings
WHERE focus_area_id = %s AND style_direction_id IS NULL AND training_type_id IS NULL
""",
(fa,),
)
elif sd is not None and tt is None:
cur.execute(
"""
DELETE FROM maturity_model_context_bindings
WHERE focus_area_id = %s AND style_direction_id = %s AND training_type_id IS NULL
""",
(fa, sd),
)
elif sd is None and tt is not None:
cur.execute(
"""
DELETE FROM maturity_model_context_bindings
WHERE focus_area_id = %s AND style_direction_id IS NULL AND training_type_id = %s
""",
(fa, tt),
)
else:
cur.execute(
"""
DELETE FROM maturity_model_context_bindings
WHERE focus_area_id = %s AND style_direction_id = %s AND training_type_id = %s
""",
(fa, sd, tt),
)
_insert_binding_row(cur, model_id, fa, sd, tt)
def _apply_import_model_payload(cur, model_id: int, m: Dict[str, Any]) -> None:
cur.execute(
"DELETE FROM model_skill_levels WHERE maturity_model_id = %s", (model_id,)
)
cur.execute("DELETE FROM model_skills WHERE maturity_model_id = %s", (model_id,))
cur.execute("DELETE FROM model_levels WHERE maturity_model_id = %s", (model_id,))
lc = int(m.get("level_count") or 5)
if lc < 3 or lc > 10:
raise HTTPException(400, "level_count muss zwischen 3 und 10 liegen")
cur.execute(
"""
UPDATE maturity_models SET
level_count = %s,
name = COALESCE(%s, name),
description = COALESCE(%s, description),
status = COALESCE(%s, status),
version = COALESCE(%s, version),
updated_at = NOW()
WHERE id = %s
""",
(
lc,
m.get("name"),
m.get("description"),
m.get("status"),
m.get("version"),
model_id,
),
)
levels = m.get("levels") or []
if not levels:
_insert_default_levels(cur, model_id, lc)
else:
for lev in levels:
cur.execute(
"""
INSERT INTO model_levels (maturity_model_id, level_number, name, description, sort_order)
VALUES (%s, %s, %s, %s, %s)
""",
(
model_id,
int(lev["level_number"]),
lev.get("name") or f"Stufe {lev['level_number']}",
lev.get("description"),
int(lev.get("sort_order") or lev["level_number"]),
),
)
for ms in m.get("model_skills") or []:
sid = int(ms["skill_id"])
cur.execute("SELECT id FROM skills WHERE id = %s", (sid,))
if not cur.fetchone():
raise HTTPException(400, f"Unbekannte skill_id {sid} (Fähigkeit fehlt in dieser Datenbank)")
cur.execute(
"""
INSERT INTO model_skills (maturity_model_id, skill_id, sort_order, relevance)
VALUES (%s, %s, %s, %s)
""",
(model_id, sid, int(ms.get("sort_order") or 0), ms.get("relevance")),
)
for sl in m.get("skill_levels") or []:
sid = int(sl["skill_id"])
ln = int(sl["level_number"])
if ln < 1 or ln > lc:
continue
desc = (sl.get("description") or "").strip()
if not desc:
continue
cur.execute("SELECT id FROM skills WHERE id = %s", (sid,))
if not cur.fetchone():
raise HTTPException(400, f"skill_levels: unbekannte skill_id {sid}")
cur.execute(
"""
INSERT INTO model_skill_levels (
maturity_model_id, skill_id, level_number, description, observable_criteria
) VALUES (%s, %s, %s, %s, %s)
ON CONFLICT (maturity_model_id, skill_id, level_number)
DO UPDATE SET
description = EXCLUDED.description,
observable_criteria = EXCLUDED.observable_criteria,
updated_at = NOW()
""",
(model_id, sid, ln, desc, sl.get("observable_criteria")),
)
@router.get("/maturity-models/{model_id}/export")
def export_maturity_model_bundle(model_id: int, session: dict = Depends(require_auth)):
_require_admin(session)
with get_db() as conn:
cur = get_cursor(conn)
if not _base_maturity_model(cur, model_id):
raise HTTPException(404, "Reifegradmodell nicht gefunden")
full = _load_full_model(cur, model_id)
cur.execute(
"""
SELECT focus_area_id, style_direction_id, training_type_id
FROM maturity_model_context_bindings
WHERE maturity_model_id = %s
""",
(model_id,),
)
binds = [r2d(r) for r in cur.fetchall()]
bundle = {
"kind": "shinkan.maturity_model.v1",
"export_version": 1,
"exported_at": datetime.now(timezone.utc).isoformat(),
"model": _strip_model_for_export(full),
"context_bindings_for_model": binds,
}
fname = f"reifegradmodell-{model_id}.json"
return JSONResponse(
content=bundle,
headers={"Content-Disposition": f'attachment; filename="{fname}"'},
)
@router.get("/maturity-models/export-resolved")
def export_resolved_maturity_bundle(
focus_area_id: int = Query(..., description="Fokusbereich (Pflicht)"),
style_direction_id: Optional[int] = Query(default=None),
training_type_id: Optional[int] = Query(default=None),
session: dict = Depends(require_auth),
):
"""Exportiert die per Bindings aufgelöste Matrix (inkl. Merge) als JSON."""
_require_admin(session)
with get_db() as conn:
cur = get_cursor(conn)
chain = _resolve_binding_model_ids(
cur, int(focus_area_id), style_direction_id, training_type_id
)
if chain:
loaded = [_load_full_model(cur, mid) for mid in chain]
merged = _merge_loaded_models(loaded)
else:
mid = _legacy_resolve_pick_model_id(
cur, focus_area_id, style_direction_id, None
)
if mid is None:
raise HTTPException(
404,
"Kein Modell für diesen Kontext (keine Bindings und kein Legacy-Treffer)",
)
merged = _load_full_model(cur, mid)
bundle = {
"kind": "shinkan.maturity_matrix_resolved.v1",
"export_version": 1,
"exported_at": datetime.now(timezone.utc).isoformat(),
"resolve_params": {
"focus_area_id": focus_area_id,
"style_direction_id": style_direction_id,
"training_type_id": training_type_id,
},
"matrix": _strip_model_for_export(merged),
"resolution": merged.get("resolution"),
}
return JSONResponse(
content=bundle,
headers={
"Content-Disposition": 'attachment; filename="faehigkeitsmatrix-aufgeloest.json"'
},
)
@router.post("/maturity-models/import")
def import_maturity_model_bundle(data: Dict[str, Any], session: dict = Depends(require_auth)):
_require_admin(session)
kind = data.get("kind")
if kind not in ("shinkan.maturity_model.v1", "shinkan.maturity_matrix_resolved.v1"):
raise HTTPException(
400,
"kind muss shinkan.maturity_model.v1 oder shinkan.maturity_matrix_resolved.v1 sein",
)
mode = (data.get("mode") or "create").strip().lower()
if mode not in ("create", "replace"):
raise HTTPException(400, "mode muss create oder replace sein")
mpart = data.get("model") or data.get("matrix") or {}
name = (mpart.get("name") or "").strip()
if mode == "create" and not name:
raise HTTPException(400, "Modellname fehlt")
import_bindings = bool(data.get("import_bindings", True))
profile_id = session.get("profile_id")
replace_id = data.get("replace_model_id")
if mode == "replace":
if not replace_id:
raise HTTPException(400, "replace_model_id erforderlich bei mode=replace")
replace_id = int(replace_id)
with get_db() as conn:
cur = get_cursor(conn)
if mode == "create":
lc = int(mpart.get("level_count") or 5)
if lc < 3 or lc > 10:
raise HTTPException(400, "level_count ungültig")
cur.execute(
"""
INSERT INTO maturity_models (
name, description, level_count, status, version, created_by
) VALUES (%s, %s, %s, %s, %s, %s)
RETURNING id
""",
(
name,
mpart.get("description"),
lc,
mpart.get("status") or "draft",
mpart.get("version") or "1.0",
profile_id,
),
)
new_id = int(cur.fetchone()["id"])
_apply_import_model_payload(cur, new_id, mpart)
if import_bindings and kind == "shinkan.maturity_model.v1":
binds = data.get("context_bindings_for_model") or []
if binds:
_apply_import_bindings(cur, new_id, binds)
return {"ok": True, "id": new_id, "mode": "create"}
if not _base_maturity_model(cur, replace_id):
raise HTTPException(404, "replace_model_id nicht gefunden")
_apply_import_model_payload(cur, replace_id, mpart)
if import_bindings and kind == "shinkan.maturity_model.v1":
binds = data.get("context_bindings_for_model") or []
_delete_bindings_for_model(cur, replace_id)
if binds:
_apply_import_bindings(cur, replace_id, binds)
return {"ok": True, "id": replace_id, "mode": "replace"}
+12 -3
View File
@@ -1,8 +1,8 @@
# Shinkan Jinkendo Version Information
APP_VERSION = "0.7.3"
APP_VERSION = "0.7.4"
BUILD_DATE = "2026-04-27"
DB_SCHEMA_VERSION = "20260427026"
DB_SCHEMA_VERSION = "20260427027"
MODULE_VERSIONS = {
"auth": "1.0.0",
@@ -19,10 +19,19 @@ MODULE_VERSIONS = {
"admin": "1.0.0",
"membership": "1.0.0",
"catalogs": "1.5.0", # Updated: Trainer Contexts API (Migration 012)
"maturity_models": "1.2.0", # 026: hierarchische Kontext-Bindings + Merge in resolve
"maturity_models": "1.3.0", # 027: Fokus+Trainingsstil; Export/Import; resolve-Merge
}
CHANGELOG = [
{
"version": "0.7.4",
"date": "2026-04-27",
"changes": [
"DB 027: Bindings Fokus+Trainingsstil ohne Stilrichtung",
"resolve: alle passenden Bindings nach Spezifität mergen",
"API: Export/Import JSON (Modell + aufgelöste Matrix)",
],
},
{
"version": "0.7.3",
"date": "2026-04-27",