fix: set created_by automatically on MediaWiki import
Some checks failed
Deploy Development / deploy (push) Successful in 37s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 5s
Test Suite / playwright-tests (push) Failing after 1m58s

- 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
This commit is contained in:
Lars 2026-04-27 09:52:18 +02:00
parent e6ce7e241c
commit a02df32ce2

View File

@ -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']