fix(media): Vereinsordner für private/shared; kein library/private mehr
Deploy Development / deploy (push) Successful in 34s
Test Suite / pytest-backend (push) Successful in 25s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 8s
Test Suite / playwright-tests (push) Successful in 23s
Deploy Development / deploy (push) Successful in 34s
Test Suite / pytest-backend (push) Successful in 25s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 8s
Test Suite / playwright-tests (push) Successful in 23s
- library/club/c{id}/private/* und …/shared/* (club visibility)
- Private Archiv-Upload: effective_club_id oder club_id Form; Plattform braucht Header
- media_assets.club_id bei private gesetzt; Dedupe pro Verein
- Übungs-Upload: dedupe_club für private aus exercise.club_id oder Mandant
- PATCH: club_id für private erhalten; Relocate inkl. private
- version 0.8.53
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
4fb77d6927
commit
3f0d02edab
6 files changed
+111
-37
No files matched your search
@@ -2397,12 +2397,30 @@ async def upload_exercise_media(
|
||||
media_root = get_effective_media_root(cur)
|
||||
full_sha = hashlib.sha256(raw).hexdigest()
|
||||
|
||||
if ex_vis == "official":
|
||||
dedupe_club: Optional[int] = None
|
||||
elif ex_vis == "private":
|
||||
dedupe_club = int(ex_club) if ex_club is not None else tenant.effective_club_id
|
||||
if dedupe_club is None:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=(
|
||||
"Private Übungsmedien werden pro Verein gespeichert. Bitte der Übung einen Verein zuordnen "
|
||||
"oder einen aktiven Verein wählen (X-Active-Club-Id)."
|
||||
),
|
||||
)
|
||||
dedupe_club = int(dedupe_club)
|
||||
else:
|
||||
if ex_club is None:
|
||||
raise HTTPException(status_code=400, detail="Vereinsübung ohne club_id")
|
||||
dedupe_club = int(ex_club)
|
||||
|
||||
cur.execute(
|
||||
"""SELECT id, storage_key, byte_size, lifecycle_state, original_filename FROM media_assets
|
||||
WHERE sha256 = %s AND lower(trim(visibility)) = %s
|
||||
AND (club_id IS NOT DISTINCT FROM %s)
|
||||
LIMIT 1""",
|
||||
(full_sha, ex_vis, ex_club),
|
||||
(full_sha, ex_vis, dedupe_club),
|
||||
)
|
||||
existing_asset = cur.fetchone()
|
||||
|
||||
@@ -2491,7 +2509,7 @@ async def upload_exercise_media(
|
||||
)
|
||||
else:
|
||||
try:
|
||||
storage_key = library_storage_key(ex_vis, ex_club, full_sha, ext)
|
||||
storage_key = library_storage_key(ex_vis, dedupe_club if ex_vis != "official" else None, full_sha, ext)
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e)) from e
|
||||
dest_path = path_under_media_root(media_root, storage_key)
|
||||
@@ -2513,7 +2531,7 @@ async def upload_exercise_media(
|
||||
full_sha,
|
||||
file.filename,
|
||||
ex_vis,
|
||||
ex_club,
|
||||
dedupe_club,
|
||||
profile_id,
|
||||
storage_key,
|
||||
),
|
||||
|
||||
@@ -10,6 +10,7 @@ from fastapi import APIRouter, Depends, File, Form, HTTPException, Query, Reques
|
||||
from pydantic import BaseModel, Field, model_validator
|
||||
|
||||
from club_tenancy import (
|
||||
assert_club_member,
|
||||
assert_valid_governance_visibility,
|
||||
club_ids_for_profile_with_roles,
|
||||
is_platform_admin,
|
||||
@@ -293,14 +294,21 @@ def _fetch_filter_uploaders(cur: Any, is_adm: bool, profile_id: int) -> list[dic
|
||||
|
||||
|
||||
def _effective_media_patch_fields(patch_fields: dict, asset: dict) -> dict:
|
||||
"""Nach visibility-Wechsel club_id konsistent setzen (official/private → NULL)."""
|
||||
"""
|
||||
Nach visibility-Wechsel club_id konsistent setzen.
|
||||
|
||||
official → club_id NULL. private/club: club_id aus Patch oder bisheriger Zeile beibehalten
|
||||
(private nutzt club_id für Vereinsordner auf der Platte).
|
||||
"""
|
||||
eff = dict(patch_fields)
|
||||
if eff.get("visibility") is not None:
|
||||
v = str(eff["visibility"]).strip().lower()
|
||||
if v in ("official", "private"):
|
||||
if v == "official":
|
||||
eff["club_id"] = None
|
||||
elif v == "club" and "club_id" not in eff:
|
||||
eff["club_id"] = asset.get("club_id")
|
||||
elif v == "private" and "club_id" not in eff:
|
||||
eff["club_id"] = asset.get("club_id")
|
||||
return eff
|
||||
|
||||
|
||||
@@ -517,8 +525,24 @@ def _ingest_library_media_file(
|
||||
if club_id_form is None:
|
||||
raise HTTPException(status_code=400, detail="Verein erforderlich für Sichtbarkeit „Verein“")
|
||||
next_cid = int(club_id_form)
|
||||
elif vis == "private":
|
||||
if club_id_form is not None:
|
||||
next_cid = int(club_id_form)
|
||||
else:
|
||||
cid = tenant.effective_club_id
|
||||
next_cid = int(cid) if cid is not None else None
|
||||
if next_cid is None:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=(
|
||||
"Private Medien werden pro Verein abgelegt. Bitte aktiven Verein setzen "
|
||||
"(Header X-Active-Club-Id) oder club_id im Formular übergeben — auch für Plattform-Admins."
|
||||
),
|
||||
)
|
||||
if not is_platform_admin(role):
|
||||
assert_club_member(cur, profile_id, next_cid)
|
||||
|
||||
assert_valid_governance_visibility(cur, profile_id, role, vis, next_cid)
|
||||
assert_valid_governance_visibility(cur, profile_id, role, vis, next_cid if vis == "club" else None)
|
||||
|
||||
max_b = _upload_limit_bytes(tenant)
|
||||
if len(raw) > max_b:
|
||||
@@ -983,7 +1007,7 @@ def bulk_media_patch(
|
||||
|
||||
eff = _effective_media_patch_fields(patch_fields, asset)
|
||||
next_vis = str(eff.get("visibility", asset["visibility"])).strip().lower()
|
||||
next_cid = eff["club_id"] if "club_id" in eff else asset.get("club_id")
|
||||
next_cid = eff.get("club_id", asset.get("club_id"))
|
||||
if "visibility" in patch_fields or "club_id" in patch_fields:
|
||||
assert_valid_governance_visibility(
|
||||
cur,
|
||||
@@ -992,11 +1016,21 @@ def bulk_media_patch(
|
||||
next_vis,
|
||||
int(next_cid) if next_cid is not None else None,
|
||||
)
|
||||
if next_vis in ("private", "club") and next_cid is None:
|
||||
failed.append(
|
||||
{
|
||||
"id": asset_id,
|
||||
"detail": (
|
||||
"Für private oder Vereins-Medien wird club_id benötigt (Vereinsordner)."
|
||||
),
|
||||
}
|
||||
)
|
||||
continue
|
||||
|
||||
new_sk: Optional[str] = None
|
||||
if "visibility" in patch_fields or "club_id" in patch_fields:
|
||||
next_club_param: Optional[int] = None
|
||||
if next_vis == "club":
|
||||
if next_vis in ("club", "private"):
|
||||
next_club_param = int(next_cid) if next_cid is not None else None
|
||||
media_root = get_effective_media_root(cur)
|
||||
new_sk = _relocate_asset_file_if_governance_changed(
|
||||
@@ -1018,7 +1052,7 @@ def bulk_media_patch(
|
||||
sets.append("visibility = %s")
|
||||
vals.append(str(eff.get("visibility", asset["visibility"])).strip())
|
||||
sets.append("club_id = %s")
|
||||
vals.append(eff.get("club_id"))
|
||||
vals.append(next_cid)
|
||||
if new_sk:
|
||||
sets.append("storage_key = %s")
|
||||
vals.append(new_sk)
|
||||
@@ -1073,7 +1107,7 @@ def patch_media_asset(
|
||||
|
||||
eff = _effective_media_patch_fields(data, asset)
|
||||
next_vis = str(eff.get("visibility", asset["visibility"])).strip().lower()
|
||||
next_cid = eff["club_id"] if "club_id" in eff else asset.get("club_id")
|
||||
next_cid = eff.get("club_id", asset.get("club_id"))
|
||||
if "visibility" in data or "club_id" in data:
|
||||
assert_valid_governance_visibility(
|
||||
cur,
|
||||
@@ -1082,11 +1116,19 @@ def patch_media_asset(
|
||||
next_vis,
|
||||
int(next_cid) if next_cid is not None else None,
|
||||
)
|
||||
if next_vis in ("private", "club") and next_cid is None:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=(
|
||||
"Für private oder Vereins-Medien wird club_id benötigt (Vereinsordner). "
|
||||
"Bitte im PATCH setzen, z. B. bei Wechsel von „offiziell“ zu „privat“."
|
||||
),
|
||||
)
|
||||
|
||||
new_sk: Optional[str] = None
|
||||
if "visibility" in data or "club_id" in data:
|
||||
next_club_param: Optional[int] = None
|
||||
if next_vis == "club":
|
||||
if next_vis in ("club", "private"):
|
||||
next_club_param = int(next_cid) if next_cid is not None else None
|
||||
media_root = get_effective_media_root(cur)
|
||||
new_sk = _relocate_asset_file_if_governance_changed(
|
||||
@@ -1108,7 +1150,7 @@ def patch_media_asset(
|
||||
sets.append("visibility = %s")
|
||||
vals.append(str(eff.get("visibility", asset["visibility"])).strip())
|
||||
sets.append("club_id = %s")
|
||||
vals.append(eff.get("club_id"))
|
||||
vals.append(next_cid)
|
||||
if new_sk:
|
||||
sets.append("storage_key = %s")
|
||||
vals.append(new_sk)
|
||||
|
||||
Reference in new issue
Block a user