From a02df32ce236157674890c5ac2932f4b7113fc2f Mon Sep 17 00:00:00 2001 From: Lars Date: Mon, 27 Apr 2026 09:52:18 +0200 Subject: [PATCH] fix: set created_by automatically on MediaWiki import - Added imported_by parameter to _run_import and _upsert_exercise - Exercises now automatically get created_by set to importing user - Fixes visibility issue where imported exercises were invisible Related: Wiki import - exercise visibility fix --- backend/routers/import_wiki.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/backend/routers/import_wiki.py b/backend/routers/import_wiki.py index fc24287..2fc1f41 100644 --- a/backend/routers/import_wiki.py +++ b/backend/routers/import_wiki.py @@ -172,6 +172,7 @@ async def execute_import( reimport=body.reimport_existing, dry_run=body.dry_run, limit=body.limit, + imported_by=profile_id, ) return { @@ -269,6 +270,7 @@ async def _run_import( reimport: bool, dry_run: bool, limit: Optional[int], + imported_by: int, ): """Hintergrund-Task: Importiert alle Seiten einer Kategorie.""" client = SmwClient() @@ -350,7 +352,7 @@ async def _run_import( # Speichern try: if import_type == "exercise": - local_id = _upsert_exercise(mapped, reimport) + local_id = _upsert_exercise(mapped, reimport, imported_by) elif import_type == "skill": local_id = _upsert_skill(mapped, reimport) else: @@ -445,7 +447,7 @@ def _update_log( conn.commit() -def _upsert_exercise(mapped: dict, reimport: bool) -> Optional[int]: +def _upsert_exercise(mapped: dict, reimport: bool, created_by: int) -> Optional[int]: """Legt Übung an oder aktualisiert sie (wenn reimport=True).""" import json as _json @@ -486,8 +488,8 @@ def _upsert_exercise(mapped: dict, reimport: bool) -> Optional[int]: """INSERT INTO exercises (title, summary, goal, execution, preparation, trainer_notes, duration_min, duration_max, group_size_min, group_size_max, - equipment, visibility, status, import_source, import_id) - VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) + equipment, visibility, status, import_source, import_id, created_by) + VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) RETURNING id""", ( mapped.get("title"), mapped.get("summary"), mapped.get("goal"), @@ -499,6 +501,7 @@ def _upsert_exercise(mapped: dict, reimport: bool) -> Optional[int]: mapped.get("status", "draft"), "mediawiki", mapped.get("import_id"), + created_by, ) ) ex_id = cur.fetchone()['id']