feat(compliance): P-06 Upload-Einwilligungsdialog v1-conservative
Deploy Development / deploy (push) Successful in 39s
Test Suite / pytest-backend (push) Successful in 34s
Test Suite / lint-backend (push) Successful in 1s
Test Suite / build-frontend (push) Successful in 11s
Test Suite / playwright-tests (push) Failing after 1m23s
Deploy Development / deploy (push) Successful in 39s
Test Suite / pytest-backend (push) Successful in 34s
Test Suite / lint-backend (push) Successful in 1s
Test Suite / build-frontend (push) Successful in 11s
Test Suite / playwright-tests (push) Failing after 1m23s
Implementiert server-seitige Rechteerklärungspflicht für alle Medien-Uploads
und Sichtbarkeits-Promotions (konservative Erstannahme: alle Uploads).
Backend:
- backend/media_rights.py (NEU): Kernmodul — validate_rights_declaration,
check_rights_coverage, assert_rights_for_promotion, assert_rights_for_exercise_link,
write_rights_declaration, update_rights_quick_fields
- backend/migrations/048_media_rights_declarations.sql (NEU): Tabelle
media_asset_rights_declarations (Append-only Audit-Log), Felder
rights_status/rights_visibility_level in media_assets
- backend/routers/media_assets.py: P-06-Pflichtprüfung in PATCH (single + bulk),
POST /api/media-assets/{id}/rights-declarations (Re-Deklaration),
GET /api/admin/media-rights/legacy-summary|legacy-assets (Admin-Endpoints)
- backend/routers/exercises.py: P-06-Felder in upload_exercise_media,
assert_rights_for_exercise_link in attach_exercise_media_from_asset
- backend/main.py: admin_rights_router registriert
Frontend:
- frontend/src/components/RightsDeclarationDialog.jsx (NEU): 9-Felder-Dialog
(konservativ: immer alle Fragen), Client-Validierung, VORLÄUFIG-Hinweis
- frontend/src/pages/MediaLibraryPage.jsx: Dialog-Intercept vor Upload,
Altbestand-Indikator (legacy_unreviewed)
- frontend/src/utils/api.js: P-06-Felder in bulkUploadMediaAssets weitergeleitet
Tests:
- backend/tests/test_media_rights_declaration.py (NEU): 28 Unit-/Integrationstests
- backend/tests/test_media_assets_archive.py: P-06 fetchone-Slots + Mock ergänzt
- backend/tests/test_media_assets_copyright_promotion.py: check_rights_coverage gemockt
- tests/dev-smoke-test.spec.js: 5 P-06 E2E-Tests ergänzt
Dokumentation:
- docs/compliance-implementation.md: P-06-Abschnitt
- docs/compliance-package-register.md: Status ⚠️ teilweise umgesetzt (KRIT-04 offen)
- docs/compliance-roadmap.md: P-06 im Freigaben-Log
Offen: KRIT-04 (rechtliche Finalisierung Einwilligungsformulierung) — technisch
vollständig, Rechtstext VORLÄUFIG.
version: 0.8.75
module: media_rights 1.0.0, media_assets 1.13.0, exercises 2.20.0
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
8cda5c27ec
commit
34235ef46d
18 files changed
+1829
-41
No files matched your search
@@ -205,6 +205,7 @@ app.include_router(club_join_requests.router)
|
||||
app.include_router(admin_users.router)
|
||||
app.include_router(platform_media_storage.router)
|
||||
app.include_router(media_assets.router)
|
||||
app.include_router(media_assets.admin_rights_router)
|
||||
app.include_router(skills.router)
|
||||
app.include_router(training_planning.router)
|
||||
app.include_router(training_framework_programs.router)
|
||||
|
||||
@@ -0,0 +1,349 @@
|
||||
"""P-06: Zentrale Rechte-Policy fuer Medien-Uploads und Promotionen.
|
||||
|
||||
Konservative Erstannahmen (p06-v1-conservative):
|
||||
- Alle Uploads (inkl. private) erfordern vollstaendige Erklaerung
|
||||
- Personenfragen bei allen Sichtbarkeiten Pflicht zu beantworten
|
||||
- Promotion zu hoeherem Niveau erfordert neue Erklaerung
|
||||
- Altmedien ('legacy_unreviewed') duerfen nicht promoted werden
|
||||
|
||||
VORLAEUTIG: Juristische Validierung der Felder und Texte steht aus.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Optional
|
||||
|
||||
from fastapi import HTTPException
|
||||
|
||||
DECLARATION_VERSION = "p06-v1-conservative"
|
||||
|
||||
# Sichtbarkeits-Hierarchie: private(1) < club(2) < official(3)
|
||||
VISIBILITY_LEVELS: dict[str, int] = {
|
||||
"private": 1,
|
||||
"club": 2,
|
||||
"official": 3,
|
||||
}
|
||||
|
||||
|
||||
def visibility_level(vis: str) -> int:
|
||||
return VISIBILITY_LEVELS.get((vis or "").strip().lower(), 0)
|
||||
|
||||
|
||||
def rights_covers_target(declared_for: Optional[str], target_vis: str) -> bool:
|
||||
"""True wenn die vorhandene Erklaerung die Ziel-Sichtbarkeit abdeckt."""
|
||||
if not declared_for:
|
||||
return False
|
||||
return visibility_level(declared_for) >= visibility_level(target_vis)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# Validierung einer eingehenden Erklaerung
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
def validate_rights_declaration(decl: dict[str, Any], target_visibility: str) -> None:
|
||||
"""Pruefen ob alle Pflichtfelder der konservativen Erstannahme vorliegen.
|
||||
|
||||
Wirft HTTPException 400 mit maschinenlesbarem code bei Verstoss.
|
||||
Gilt fuer alle Sichtbarkeiten (private/club/official) identisch.
|
||||
"""
|
||||
# 1. rights_holder_confirmed ist immer Pflicht
|
||||
if not decl.get("rights_holder_confirmed"):
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail={
|
||||
"code": "RIGHTS_DECLARATION_REQUIRED",
|
||||
"message": (
|
||||
"Bitte bestaetigen, dass du die erforderlichen Rechte an diesem Medium besitzt."
|
||||
),
|
||||
},
|
||||
)
|
||||
|
||||
# 2. contains_identifiable_persons muss explizit beantwortet sein
|
||||
if decl.get("contains_identifiable_persons") is None:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail={
|
||||
"code": "RIGHTS_DECLARATION_REQUIRED",
|
||||
"message": "Bitte angeben, ob erkennbare Personen abgebildet sind.",
|
||||
},
|
||||
)
|
||||
|
||||
# 3. Wenn Personen vorhanden: Einwilligung Pflicht
|
||||
if decl.get("contains_identifiable_persons") is True:
|
||||
if not decl.get("person_consent_confirmed"):
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail={
|
||||
"code": "PERSON_CONSENT_REQUIRED",
|
||||
"message": (
|
||||
"Bitte bestaetigen, dass die Einwilligungen aller erkennbaren Personen vorliegen."
|
||||
),
|
||||
},
|
||||
)
|
||||
|
||||
# 4. contains_minors muss explizit beantwortet sein
|
||||
if decl.get("contains_minors") is None:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail={
|
||||
"code": "RIGHTS_DECLARATION_REQUIRED",
|
||||
"message": "Bitte angeben, ob Minderjaehrige abgebildet sind.",
|
||||
},
|
||||
)
|
||||
|
||||
# 5. Wenn Minderjaehrige: Elterneinwilligung Pflicht
|
||||
if decl.get("contains_minors") is True:
|
||||
if not decl.get("parental_consent_confirmed"):
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail={
|
||||
"code": "PARENTAL_CONSENT_REQUIRED",
|
||||
"message": (
|
||||
"Bitte bestaetigen, dass die Einwilligungen der Sorgeberechtigten vorliegen."
|
||||
),
|
||||
},
|
||||
)
|
||||
|
||||
# 6. contains_music muss explizit beantwortet sein
|
||||
if decl.get("contains_music") is None:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail={
|
||||
"code": "RIGHTS_DECLARATION_REQUIRED",
|
||||
"message": "Bitte angeben, ob das Medium Musik enthaelt.",
|
||||
},
|
||||
)
|
||||
|
||||
# 7. Wenn Musik: Musikrechte Pflicht
|
||||
if decl.get("contains_music") is True:
|
||||
if not decl.get("music_rights_confirmed"):
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail={
|
||||
"code": "MUSIC_RIGHTS_REQUIRED",
|
||||
"message": (
|
||||
"Bitte bestaetigen, dass die erforderlichen Musikrechte vorliegen."
|
||||
),
|
||||
},
|
||||
)
|
||||
|
||||
# 8. contains_third_party_content muss explizit beantwortet sein
|
||||
if decl.get("contains_third_party_content") is None:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail={
|
||||
"code": "RIGHTS_DECLARATION_REQUIRED",
|
||||
"message": "Bitte angeben, ob fremde geschuetzte Inhalte (Logos, Grafiken etc.) enthalten sind.",
|
||||
},
|
||||
)
|
||||
|
||||
# 9. Wenn Fremdmaterial: Rechte Pflicht
|
||||
if decl.get("contains_third_party_content") is True:
|
||||
if not decl.get("third_party_rights_confirmed"):
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail={
|
||||
"code": "THIRD_PARTY_RIGHTS_REQUIRED",
|
||||
"message": (
|
||||
"Bitte bestaetigen, dass die Rechte an allen enthaltenen Fremdmaterialien vorliegen."
|
||||
),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# Pruefen ob vorhandene Erklaerung Zielsichtbarkeit abdeckt
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
def check_rights_coverage(cur: Any, asset_id: int, target_visibility: str) -> str:
|
||||
"""Status der Rechteabdeckung fuer ein Asset und eine Zielsichtbarkeit.
|
||||
|
||||
Returns:
|
||||
'ok' - vorhandene Erklaerung reicht aus
|
||||
'insufficient' - Erklaerung vorhanden, aber fuer niedrigere Sichtbarkeit
|
||||
'legacy' - Altmedium ohne Erklaerung
|
||||
'blocked' - durch Admin gesperrt
|
||||
'no_declaration' - neues Medium ohne Erklaerung (sollte nicht vorkommen)
|
||||
"""
|
||||
cur.execute(
|
||||
"SELECT rights_status, rights_declared_for_visibility FROM media_assets WHERE id = %s",
|
||||
(asset_id,),
|
||||
)
|
||||
row = cur.fetchone()
|
||||
if not row:
|
||||
return "no_declaration"
|
||||
|
||||
# psycopg2 RealDictCursor oder ähnlich
|
||||
if hasattr(row, "keys"):
|
||||
rs = row["rights_status"]
|
||||
rdv = row["rights_declared_for_visibility"]
|
||||
else:
|
||||
rs, rdv = row[0], row[1]
|
||||
|
||||
rs = (rs or "").strip().lower()
|
||||
rdv = (rdv or "").strip().lower() if rdv else None
|
||||
|
||||
if rs == "blocked":
|
||||
return "blocked"
|
||||
if rs == "legacy_unreviewed":
|
||||
return "legacy"
|
||||
if rs == "declared":
|
||||
if rights_covers_target(rdv, target_visibility):
|
||||
return "ok"
|
||||
return "insufficient"
|
||||
return "no_declaration"
|
||||
|
||||
|
||||
def assert_rights_for_promotion(cur: Any, asset_id: int, target_visibility: str) -> None:
|
||||
"""Wirft HTTPException wenn das Asset keine gueltige Erklaerung fuer target_visibility hat."""
|
||||
status = check_rights_coverage(cur, asset_id, target_visibility)
|
||||
if status == "ok":
|
||||
return
|
||||
if status == "legacy":
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail={
|
||||
"code": "LEGACY_REDECLARATION_REQUIRED",
|
||||
"message": (
|
||||
"Dieses Medium wurde vor Einfuehrung der Einwilligungspflicht hochgeladen. "
|
||||
"Bitte eine Rechterklaerung nachreichen, bevor die Sichtbarkeit erhoeht wird."
|
||||
),
|
||||
"asset_id": asset_id,
|
||||
},
|
||||
)
|
||||
if status == "insufficient":
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail={
|
||||
"code": "RIGHTS_SCOPE_INSUFFICIENT",
|
||||
"message": (
|
||||
f"Die vorhandene Erklaerung gilt nicht fuer die Ziel-Sichtbarkeit '{target_visibility}'. "
|
||||
"Bitte eine neue Erklaerung fuer diese Sichtbarkeit abgeben."
|
||||
),
|
||||
"asset_id": asset_id,
|
||||
"target_visibility": target_visibility,
|
||||
},
|
||||
)
|
||||
if status == "blocked":
|
||||
raise HTTPException(
|
||||
status_code=403,
|
||||
detail={
|
||||
"code": "RIGHTS_BLOCKED",
|
||||
"message": "Dieses Medium ist durch einen Administrator gesperrt.",
|
||||
"asset_id": asset_id,
|
||||
},
|
||||
)
|
||||
# no_declaration (neues Medium ohne Erklaerung)
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail={
|
||||
"code": "RIGHTS_DECLARATION_REQUIRED",
|
||||
"message": "Fuer dieses Medium liegt keine Rechterklaerung vor.",
|
||||
"asset_id": asset_id,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def assert_rights_for_exercise_link(cur: Any, asset_id: int, exercise_visibility: str) -> None:
|
||||
"""Pruefen ob das Asset in eine Uebung mit dieser Sichtbarkeit eingebunden werden darf."""
|
||||
status = check_rights_coverage(cur, asset_id, exercise_visibility)
|
||||
if status == "ok":
|
||||
return
|
||||
if status == "legacy" and exercise_visibility == "private":
|
||||
# Altmedien duerfen in private Uebungen eingebunden bleiben (kein Upgrade-Risiko)
|
||||
return
|
||||
if status == "legacy":
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail={
|
||||
"code": "LEGACY_REDECLARATION_REQUIRED",
|
||||
"message": (
|
||||
"Das gewahlte Archiv-Medium hat noch keine Rechterklaerung nach neuem Standard. "
|
||||
"Bitte zuerst eine Erklaerung fuer dieses Medium abgeben."
|
||||
),
|
||||
"asset_id": asset_id,
|
||||
},
|
||||
)
|
||||
if status == "insufficient":
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail={
|
||||
"code": "RIGHTS_SCOPE_INSUFFICIENT",
|
||||
"message": (
|
||||
f"Das Archiv-Medium hat keine Erklaerung fuer Sichtbarkeit '{exercise_visibility}'. "
|
||||
"Bitte zuerst eine neue Erklaerung fuer dieses Medium abgeben."
|
||||
),
|
||||
"asset_id": asset_id,
|
||||
},
|
||||
)
|
||||
if status == "blocked":
|
||||
raise HTTPException(
|
||||
status_code=403,
|
||||
detail={
|
||||
"code": "RIGHTS_BLOCKED",
|
||||
"message": "Dieses Medium ist gesperrt und kann nicht verwendet werden.",
|
||||
"asset_id": asset_id,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# Declaration-Log schreiben + Schnellfelder aktualisieren
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
def write_rights_declaration(
|
||||
cur: Any,
|
||||
asset_id: int,
|
||||
profile_id: int,
|
||||
action_type: str,
|
||||
target_visibility: str,
|
||||
decl: dict[str, Any],
|
||||
) -> int:
|
||||
"""Schreibt einen neuen Eintrag in media_asset_rights_declarations (append-only).
|
||||
|
||||
Returns: id des neuen Eintrags
|
||||
"""
|
||||
cur.execute(
|
||||
"""INSERT INTO media_asset_rights_declarations (
|
||||
media_asset_id, declared_by_profile_id, action_type, target_visibility,
|
||||
declaration_version,
|
||||
rights_holder_confirmed,
|
||||
contains_identifiable_persons, person_consent_confirmed,
|
||||
contains_minors, parental_consent_confirmed,
|
||||
contains_music, music_rights_confirmed,
|
||||
contains_third_party_content, third_party_rights_confirmed
|
||||
) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
RETURNING id""",
|
||||
(
|
||||
asset_id,
|
||||
profile_id,
|
||||
action_type,
|
||||
target_visibility,
|
||||
DECLARATION_VERSION,
|
||||
bool(decl.get("rights_holder_confirmed")),
|
||||
decl.get("contains_identifiable_persons"),
|
||||
decl.get("person_consent_confirmed"),
|
||||
decl.get("contains_minors"),
|
||||
decl.get("parental_consent_confirmed"),
|
||||
decl.get("contains_music"),
|
||||
decl.get("music_rights_confirmed"),
|
||||
decl.get("contains_third_party_content"),
|
||||
decl.get("third_party_rights_confirmed"),
|
||||
),
|
||||
)
|
||||
row = cur.fetchone()
|
||||
if hasattr(row, "keys"):
|
||||
return int(row["id"])
|
||||
return int(row[0])
|
||||
|
||||
|
||||
def update_rights_quick_fields(cur: Any, asset_id: int, target_visibility: str) -> None:
|
||||
"""Setzt die Schnellfelder in media_assets nach erfolgreicher Deklaration."""
|
||||
cur.execute(
|
||||
"""UPDATE media_assets
|
||||
SET rights_status = 'declared',
|
||||
rights_declared_for_visibility = %s,
|
||||
rights_declared_at = NOW(),
|
||||
updated_at = NOW()
|
||||
WHERE id = %s""",
|
||||
(target_visibility, asset_id),
|
||||
)
|
||||
@@ -0,0 +1,75 @@
|
||||
-- Migration 048: P-06 Upload-Einwilligungsdialog
|
||||
-- Append-only Deklarations-Log + Schnellfelder in media_assets
|
||||
-- Alle bestehenden Medien erhalten rights_status = 'legacy_unreviewed'
|
||||
|
||||
-- Deklarations-Log (append-only, wird nie geaendert oder geloescht)
|
||||
CREATE TABLE IF NOT EXISTS media_asset_rights_declarations (
|
||||
id SERIAL PRIMARY KEY,
|
||||
media_asset_id INT NOT NULL REFERENCES media_assets(id) ON DELETE CASCADE,
|
||||
declared_by_profile_id INT REFERENCES profiles(id) ON DELETE SET NULL,
|
||||
declared_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
|
||||
-- Kontext der Erklaerung
|
||||
action_type VARCHAR(50) NOT NULL
|
||||
CHECK (action_type IN (
|
||||
'upload', -- Erstupload
|
||||
'promote_club', -- Promotion zu club
|
||||
'promote_official', -- Promotion zu official
|
||||
're_declaration', -- Freiwillige Nacherklaerung
|
||||
'legacy_re_declaration' -- Altmedium: erste Erklaerung nachgereicht
|
||||
)),
|
||||
target_visibility VARCHAR(32) NOT NULL
|
||||
CHECK (target_visibility IN ('private', 'club', 'official')),
|
||||
-- Textversion der Erklaerung; 'p06-v1-conservative' = konservative Erstannahmen
|
||||
-- VORLAEUTIG: Texte noch nicht juristisch geprueft
|
||||
declaration_version VARCHAR(40) NOT NULL DEFAULT 'p06-v1-conservative',
|
||||
|
||||
-- Pflichtfeld (alle Sichtbarkeiten, alle Aktionen)
|
||||
rights_holder_confirmed BOOLEAN NOT NULL,
|
||||
|
||||
-- Personen (konservative Annahme: immer abgefragt, auch bei 'private')
|
||||
contains_identifiable_persons BOOLEAN,
|
||||
person_consent_confirmed BOOLEAN, -- Pflicht wenn contains_identifiable_persons = true
|
||||
|
||||
-- Minderjaehrige
|
||||
contains_minors BOOLEAN,
|
||||
parental_consent_confirmed BOOLEAN, -- Pflicht wenn contains_minors = true
|
||||
|
||||
-- Drittmaterial
|
||||
contains_music BOOLEAN,
|
||||
music_rights_confirmed BOOLEAN, -- Pflicht wenn contains_music = true
|
||||
contains_third_party_content BOOLEAN,
|
||||
third_party_rights_confirmed BOOLEAN, -- Pflicht wenn contains_third_party_content = true
|
||||
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_mard_asset
|
||||
ON media_asset_rights_declarations (media_asset_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_mard_profile
|
||||
ON media_asset_rights_declarations (declared_by_profile_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_mard_action_type
|
||||
ON media_asset_rights_declarations (action_type);
|
||||
|
||||
-- Schnellfelder in media_assets (kein Ersatz fuer den Log, nur fuer effiziente Abfragen)
|
||||
ALTER TABLE media_assets
|
||||
ADD COLUMN IF NOT EXISTS rights_status VARCHAR(32)
|
||||
NOT NULL DEFAULT 'legacy_unreviewed'
|
||||
CHECK (rights_status IN ('legacy_unreviewed', 'declared', 'blocked')),
|
||||
ADD COLUMN IF NOT EXISTS rights_declared_for_visibility VARCHAR(32)
|
||||
CHECK (rights_declared_for_visibility IN ('private', 'club', 'official')),
|
||||
ADD COLUMN IF NOT EXISTS rights_declared_at TIMESTAMPTZ;
|
||||
|
||||
-- Bestehende Medien: explicit legacy_unreviewed setzen (redundant zum DEFAULT, zur Klarheit)
|
||||
UPDATE media_assets
|
||||
SET rights_status = 'legacy_unreviewed'
|
||||
WHERE rights_status = 'legacy_unreviewed'; -- no-op, setzt Default explizit
|
||||
|
||||
COMMENT ON TABLE media_asset_rights_declarations IS
|
||||
'P-06: Append-only Erklaerungslog fuer Upload-Einwilligungen. '
|
||||
'Eintraege werden nie geaendert. Juristische Validierung der Felder und Texte steht aus.';
|
||||
|
||||
COMMENT ON COLUMN media_assets.rights_status IS
|
||||
'P-06: legacy_unreviewed = Altbestand ohne P-06-Erklaerung; '
|
||||
'declared = gueltige Erklaerung fuer rights_declared_for_visibility; '
|
||||
'blocked = durch Admin gesperrt (P-11-Schnittstelle).';
|
||||
@@ -29,6 +29,7 @@ from club_tenancy import (
|
||||
)
|
||||
from tenant_context import TenantContext, get_tenant_context, get_tenant_context_flexible, library_content_visibility_sql
|
||||
from media_storage import get_effective_media_root, library_storage_key, path_under_media_root
|
||||
from media_rights import assert_rights_for_exercise_link, validate_rights_declaration, write_rights_declaration, update_rights_quick_fields
|
||||
from exercise_rich_text import (
|
||||
RICH_HTML_EXERCISE_FIELDS,
|
||||
assert_no_inline_media_references_on_create,
|
||||
@@ -2526,6 +2527,16 @@ async def upload_exercise_media(
|
||||
description: str = Form(""),
|
||||
context: str = Form("ablauf"),
|
||||
is_primary: bool = Form(False),
|
||||
# P-06: Rechte-Erklaerung (Pflicht bei Datei-Upload mit neuem media_asset)
|
||||
rights_holder_confirmed: Optional[bool] = Form(None),
|
||||
contains_identifiable_persons: Optional[bool] = Form(None),
|
||||
person_consent_confirmed: Optional[bool] = Form(None),
|
||||
contains_minors: Optional[bool] = Form(None),
|
||||
parental_consent_confirmed: Optional[bool] = Form(None),
|
||||
contains_music: Optional[bool] = Form(None),
|
||||
music_rights_confirmed: Optional[bool] = Form(None),
|
||||
contains_third_party_content: Optional[bool] = Form(None),
|
||||
third_party_rights_confirmed: Optional[bool] = Form(None),
|
||||
):
|
||||
profile_id = tenant.profile_id
|
||||
if media_type not in ("image", "video", "document", "sketch"):
|
||||
@@ -2783,6 +2794,21 @@ async def upload_exercise_media(
|
||||
)
|
||||
ar = cur.fetchone()
|
||||
aid = r2d(ar)["id"]
|
||||
# P-06: Rechterklaerung fuer neues Media-Asset validieren und schreiben
|
||||
p06_decl = {
|
||||
"rights_holder_confirmed": rights_holder_confirmed,
|
||||
"contains_identifiable_persons": contains_identifiable_persons,
|
||||
"person_consent_confirmed": person_consent_confirmed,
|
||||
"contains_minors": contains_minors,
|
||||
"parental_consent_confirmed": parental_consent_confirmed,
|
||||
"contains_music": contains_music,
|
||||
"music_rights_confirmed": music_rights_confirmed,
|
||||
"contains_third_party_content": contains_third_party_content,
|
||||
"third_party_rights_confirmed": third_party_rights_confirmed,
|
||||
}
|
||||
validate_rights_declaration(p06_decl, ex_vis)
|
||||
write_rights_declaration(cur, aid, profile_id, "upload", ex_vis, p06_decl)
|
||||
update_rights_quick_fields(cur, aid, ex_vis)
|
||||
db_path = f"/media/{storage_key}"
|
||||
cur.execute(
|
||||
f"""INSERT INTO exercise_media (
|
||||
@@ -2867,6 +2893,15 @@ def attach_exercise_media_from_asset(
|
||||
):
|
||||
raise HTTPException(status_code=403, detail="Keine Berechtigung für dieses Archiv-Medium")
|
||||
|
||||
# P-06: Rechtspruefung — Asset muss Einwilligung fuer Sichtbarkeit der Uebung haben
|
||||
cur.execute(
|
||||
"SELECT visibility FROM exercises WHERE id = %s",
|
||||
(exercise_id,),
|
||||
)
|
||||
ex_row = cur.fetchone()
|
||||
ex_vis = (r2d(ex_row).get("visibility") or "private").strip().lower() if ex_row else "private"
|
||||
assert_rights_for_exercise_link(cur, body.media_asset_id, ex_vis)
|
||||
|
||||
cur.execute(
|
||||
"SELECT 1 FROM exercise_media WHERE exercise_id = %s AND media_asset_id = %s",
|
||||
(exercise_id, body.media_asset_id),
|
||||
|
||||
@@ -37,6 +37,14 @@ from media_lifecycle import (
|
||||
from media_storage import get_effective_media_root, library_storage_key, path_under_media_root, relocate_local_media_file
|
||||
from tenant_context import TenantContext, get_tenant_context, get_tenant_context_flexible
|
||||
|
||||
from media_rights import (
|
||||
assert_rights_for_promotion,
|
||||
update_rights_quick_fields,
|
||||
validate_rights_declaration,
|
||||
write_rights_declaration,
|
||||
check_rights_coverage,
|
||||
VISIBILITY_LEVELS,
|
||||
)
|
||||
from routers.exercises import _upload_limit_bytes, resolve_upload_mime_type
|
||||
|
||||
router = APIRouter(prefix="/api/media-assets", tags=["media-assets"])
|
||||
@@ -70,6 +78,30 @@ class MediaAssetPatch(BaseModel):
|
||||
visibility: Optional[str] = Field(None, pattern="^(private|club|official)$")
|
||||
club_id: Optional[int] = None
|
||||
tags: Optional[list[str]] = None
|
||||
# P-06: optionale Rechte-Erklaerung (wird Pflicht wenn Promotion zu hoeherer Sichtbarkeit)
|
||||
rights_holder_confirmed: Optional[bool] = None
|
||||
contains_identifiable_persons: Optional[bool] = None
|
||||
person_consent_confirmed: Optional[bool] = None
|
||||
contains_minors: Optional[bool] = None
|
||||
parental_consent_confirmed: Optional[bool] = None
|
||||
contains_music: Optional[bool] = None
|
||||
music_rights_confirmed: Optional[bool] = None
|
||||
contains_third_party_content: Optional[bool] = None
|
||||
third_party_rights_confirmed: Optional[bool] = None
|
||||
|
||||
|
||||
class RightsDeclarationBody(BaseModel):
|
||||
"""P-06: Explizite Re-Deklaration / Nachdeklaration fuer ein bestehendes Medium."""
|
||||
target_visibility: str = Field(..., pattern="^(private|club|official)$")
|
||||
rights_holder_confirmed: bool
|
||||
contains_identifiable_persons: bool
|
||||
person_consent_confirmed: Optional[bool] = None
|
||||
contains_minors: bool
|
||||
parental_consent_confirmed: Optional[bool] = None
|
||||
contains_music: bool
|
||||
music_rights_confirmed: Optional[bool] = None
|
||||
contains_third_party_content: bool
|
||||
third_party_rights_confirmed: Optional[bool] = None
|
||||
|
||||
|
||||
class MediaBulkLifecycleBody(BaseModel):
|
||||
@@ -101,6 +133,16 @@ class MediaBulkPatchBody(BaseModel):
|
||||
visibility: Optional[str] = Field(None, pattern="^(private|club|official)$")
|
||||
club_id: Optional[int] = None
|
||||
tags: Optional[list[str]] = None
|
||||
# P-06: Rechterklaerung (gilt fuer alle Assets des Batches bei Promotion)
|
||||
rights_holder_confirmed: Optional[bool] = None
|
||||
contains_identifiable_persons: Optional[bool] = None
|
||||
person_consent_confirmed: Optional[bool] = None
|
||||
contains_minors: Optional[bool] = None
|
||||
parental_consent_confirmed: Optional[bool] = None
|
||||
contains_music: Optional[bool] = None
|
||||
music_rights_confirmed: Optional[bool] = None
|
||||
contains_third_party_content: Optional[bool] = None
|
||||
third_party_rights_confirmed: Optional[bool] = None
|
||||
|
||||
|
||||
_LIFECYCLE_LIST_FILTERS = frozenset({"active", "trash_soft", "trash_hidden", "all"})
|
||||
@@ -628,8 +670,13 @@ def _ingest_library_media_file(
|
||||
content_type: Optional[str],
|
||||
visibility: str,
|
||||
club_id_form: Optional[int],
|
||||
decl: Optional[dict] = None,
|
||||
) -> dict:
|
||||
"""Neues Archiv-Medium oder aktiver Dedupe-Treffer (sha256 + Sichtbarkeit + Verein). Kein exercise_media."""
|
||||
"""Neues Archiv-Medium oder aktiver Dedupe-Treffer (sha256 + Sichtbarkeit + Verein). Kein exercise_media.
|
||||
|
||||
decl: P-06 Rechterklaerung (bereits validiert). Bei Dedupe-Treffer wird eine neue Erklaerung
|
||||
fuer die aktuelle Aktion geschrieben falls decl uebergeben wird.
|
||||
"""
|
||||
profile_id = tenant.profile_id
|
||||
role = tenant.global_role or ""
|
||||
vis = (visibility or "private").strip().lower()
|
||||
@@ -781,6 +828,10 @@ def _ingest_library_media_file(
|
||||
)
|
||||
ar = cur.fetchone()
|
||||
aid = int(r2d(ar)["id"])
|
||||
# P-06: Erklaerung schreiben und Schnellfelder setzen
|
||||
if decl is not None:
|
||||
write_rights_declaration(cur, aid, tenant.profile_id, "upload", vis, decl)
|
||||
update_rights_quick_fields(cur, aid, vis)
|
||||
return {"status": "created", "media_asset_id": aid, "original_filename": filename or storage_key}
|
||||
|
||||
|
||||
@@ -790,8 +841,22 @@ async def bulk_upload_media_assets(
|
||||
files: list[UploadFile] = File(..., description="Mehrere Dateien (jpeg, png, gif, mp4, pdf)"),
|
||||
visibility: str = Form("private"),
|
||||
club_id: Optional[int] = Form(None),
|
||||
# P-06 Rechterklaerung (gilt fuer alle Dateien des Batches)
|
||||
rights_holder_confirmed: bool = Form(...),
|
||||
contains_identifiable_persons: bool = Form(...),
|
||||
person_consent_confirmed: Optional[bool] = Form(None),
|
||||
contains_minors: bool = Form(...),
|
||||
parental_consent_confirmed: Optional[bool] = Form(None),
|
||||
contains_music: bool = Form(...),
|
||||
music_rights_confirmed: Optional[bool] = Form(None),
|
||||
contains_third_party_content: bool = Form(...),
|
||||
third_party_rights_confirmed: Optional[bool] = Form(None),
|
||||
):
|
||||
"""Mehrere Dateien ins Archiv; Dedupe wie Übungs-Upload. Pro Datei eigene DB-Transaktion."""
|
||||
"""Mehrere Dateien ins Archiv; Dedupe wie Übungs-Upload. Pro Datei eigene DB-Transaktion.
|
||||
|
||||
P-06: Eine Rechterklaerung gilt fuer alle Dateien des Batches.
|
||||
VORLAEUTIG: Texte und Pflichtfelder noch nicht juristisch geprueft (p06-v1-conservative).
|
||||
"""
|
||||
if not files:
|
||||
raise HTTPException(status_code=400, detail="Keine Dateien übermittelt")
|
||||
if len(files) > _MAX_BULK_LIBRARY_FILES:
|
||||
@@ -800,6 +865,20 @@ async def bulk_upload_media_assets(
|
||||
detail=f"Maximal {_MAX_BULK_LIBRARY_FILES} Dateien pro Anfrage",
|
||||
)
|
||||
|
||||
decl = {
|
||||
"rights_holder_confirmed": rights_holder_confirmed,
|
||||
"contains_identifiable_persons": contains_identifiable_persons,
|
||||
"person_consent_confirmed": person_consent_confirmed,
|
||||
"contains_minors": contains_minors,
|
||||
"parental_consent_confirmed": parental_consent_confirmed,
|
||||
"contains_music": contains_music,
|
||||
"music_rights_confirmed": music_rights_confirmed,
|
||||
"contains_third_party_content": contains_third_party_content,
|
||||
"third_party_rights_confirmed": third_party_rights_confirmed,
|
||||
}
|
||||
target_vis = (visibility or "private").strip().lower()
|
||||
validate_rights_declaration(decl, target_vis)
|
||||
|
||||
results: list[dict[str, Any]] = []
|
||||
created = duplicate = failed = 0
|
||||
|
||||
@@ -821,7 +900,9 @@ async def bulk_upload_media_assets(
|
||||
uf.content_type,
|
||||
visibility,
|
||||
club_id,
|
||||
decl=decl,
|
||||
)
|
||||
conn.commit()
|
||||
results.append({"filename": fn, "ok": True, **r})
|
||||
if r["status"] == "created":
|
||||
created += 1
|
||||
@@ -1174,6 +1255,40 @@ def bulk_media_patch(
|
||||
)
|
||||
continue
|
||||
|
||||
# P-06: Rechteprüfung bei Promotion
|
||||
cur_vis = (asset.get("visibility") or "private").strip().lower()
|
||||
bulk_p06_decl: Optional[dict] = None
|
||||
bulk_p06_action: Optional[str] = None
|
||||
if VISIBILITY_LEVELS.get(next_vis, 0) > VISIBILITY_LEVELS.get(cur_vis, 0):
|
||||
coverage = check_rights_coverage(cur, asset_id, next_vis)
|
||||
if coverage != "ok":
|
||||
p06_fields = {
|
||||
"rights_holder_confirmed": patch_fields.get("rights_holder_confirmed"),
|
||||
"contains_identifiable_persons": patch_fields.get("contains_identifiable_persons"),
|
||||
"person_consent_confirmed": patch_fields.get("person_consent_confirmed"),
|
||||
"contains_minors": patch_fields.get("contains_minors"),
|
||||
"parental_consent_confirmed": patch_fields.get("parental_consent_confirmed"),
|
||||
"contains_music": patch_fields.get("contains_music"),
|
||||
"music_rights_confirmed": patch_fields.get("music_rights_confirmed"),
|
||||
"contains_third_party_content": patch_fields.get("contains_third_party_content"),
|
||||
"third_party_rights_confirmed": patch_fields.get("third_party_rights_confirmed"),
|
||||
}
|
||||
if p06_fields.get("rights_holder_confirmed") is None:
|
||||
code = "LEGACY_REDECLARATION_REQUIRED" if coverage == "legacy" else "RIGHTS_SCOPE_INSUFFICIENT"
|
||||
failed.append({
|
||||
"id": asset_id,
|
||||
"detail": f"{code}: Rechterklaerung fuer '{next_vis}' erforderlich.",
|
||||
})
|
||||
continue
|
||||
try:
|
||||
validate_rights_declaration(p06_fields, next_vis)
|
||||
except HTTPException as p06e:
|
||||
d = p06e.detail
|
||||
failed.append({"id": asset_id, "detail": d.get("message") if isinstance(d, dict) else str(d)})
|
||||
continue
|
||||
bulk_p06_decl = p06_fields
|
||||
bulk_p06_action = "legacy_re_declaration" if coverage == "legacy" else "promote_club" if next_vis == "club" else "promote_official"
|
||||
|
||||
new_sk: Optional[str] = None
|
||||
if "visibility" in patch_fields or "club_id" in patch_fields:
|
||||
next_club_param: Optional[int] = None
|
||||
@@ -1212,6 +1327,12 @@ def bulk_media_patch(
|
||||
f"UPDATE media_assets SET {', '.join(sets)} WHERE id = %s",
|
||||
tuple(vals),
|
||||
)
|
||||
# P-06: Declaration-Log schreiben wenn neue Erklaerung bei Promotion
|
||||
if bulk_p06_decl is not None and bulk_p06_action is not None:
|
||||
write_rights_declaration(
|
||||
cur, asset_id, profile_id, bulk_p06_action, next_vis, bulk_p06_decl
|
||||
)
|
||||
update_rights_quick_fields(cur, asset_id, next_vis)
|
||||
conn.commit()
|
||||
updated.append(asset_id)
|
||||
except HTTPException as he:
|
||||
@@ -1255,6 +1376,8 @@ def patch_media_asset(
|
||||
eff = _effective_media_patch_fields(data, asset)
|
||||
next_vis = str(eff.get("visibility", asset["visibility"])).strip().lower()
|
||||
next_cid = eff.get("club_id", asset.get("club_id"))
|
||||
_p06_pending_decl: Optional[dict] = None
|
||||
_p06_action: Optional[str] = None
|
||||
if "visibility" in data or "club_id" in data:
|
||||
assert_valid_governance_visibility(
|
||||
cur,
|
||||
@@ -1286,6 +1409,61 @@ def patch_media_asset(
|
||||
),
|
||||
)
|
||||
|
||||
# P-06: Rechteprüfung bei Sichtbarkeits-Promotion
|
||||
cur_vis = (asset.get("visibility") or "private").strip().lower()
|
||||
if VISIBILITY_LEVELS.get(next_vis, 0) > VISIBILITY_LEVELS.get(cur_vis, 0):
|
||||
coverage = check_rights_coverage(cur, asset_id, next_vis)
|
||||
if coverage != "ok":
|
||||
# Neue Erklaerung muss im Body mitgeliefert werden
|
||||
p06_fields = {
|
||||
"rights_holder_confirmed": data.get("rights_holder_confirmed"),
|
||||
"contains_identifiable_persons": data.get("contains_identifiable_persons"),
|
||||
"person_consent_confirmed": data.get("person_consent_confirmed"),
|
||||
"contains_minors": data.get("contains_minors"),
|
||||
"parental_consent_confirmed": data.get("parental_consent_confirmed"),
|
||||
"contains_music": data.get("contains_music"),
|
||||
"music_rights_confirmed": data.get("music_rights_confirmed"),
|
||||
"contains_third_party_content": data.get("contains_third_party_content"),
|
||||
"third_party_rights_confirmed": data.get("third_party_rights_confirmed"),
|
||||
}
|
||||
if coverage == "legacy":
|
||||
if p06_fields.get("rights_holder_confirmed") is None:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail={
|
||||
"code": "LEGACY_REDECLARATION_REQUIRED",
|
||||
"message": (
|
||||
"Dieses Medium wurde vor Einfuehrung der Einwilligungspflicht "
|
||||
"hochgeladen. Bitte eine vollstaendige Rechterklaerung (P-06-Felder) "
|
||||
"zusammen mit dem PATCH uebergeben."
|
||||
),
|
||||
"asset_id": asset_id,
|
||||
},
|
||||
)
|
||||
else:
|
||||
if p06_fields.get("rights_holder_confirmed") is None:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail={
|
||||
"code": "RIGHTS_SCOPE_INSUFFICIENT",
|
||||
"message": (
|
||||
f"Die vorhandene Erklaerung deckt '{next_vis}' nicht ab. "
|
||||
"Bitte eine neue Erklaerung (P-06-Felder) mitschicken."
|
||||
),
|
||||
"asset_id": asset_id,
|
||||
"target_visibility": next_vis,
|
||||
},
|
||||
)
|
||||
validate_rights_declaration(p06_fields, next_vis)
|
||||
_p06_pending_decl = p06_fields
|
||||
_p06_action = "legacy_re_declaration" if coverage == "legacy" else "promote_club" if next_vis == "club" else "promote_official"
|
||||
else:
|
||||
_p06_pending_decl = None
|
||||
_p06_action = None
|
||||
else:
|
||||
_p06_pending_decl = None
|
||||
_p06_action = None
|
||||
|
||||
new_sk: Optional[str] = None
|
||||
if "visibility" in data or "club_id" in data:
|
||||
next_club_param: Optional[int] = None
|
||||
@@ -1322,6 +1500,12 @@ def patch_media_asset(
|
||||
f"UPDATE media_assets SET {', '.join(sets)} WHERE id = %s",
|
||||
tuple(vals),
|
||||
)
|
||||
# P-06: Declaration-Log schreiben wenn neue Erklaerung bei Promotion
|
||||
if _p06_pending_decl is not None and _p06_action is not None:
|
||||
write_rights_declaration(
|
||||
cur, asset_id, profile_id, _p06_action, next_vis, _p06_pending_decl
|
||||
)
|
||||
update_rights_quick_fields(cur, asset_id, next_vis)
|
||||
conn.commit()
|
||||
has_tags = _media_assets_tags_column_present(cur)
|
||||
if has_tags:
|
||||
@@ -1342,3 +1526,143 @@ def patch_media_asset(
|
||||
if not has_tags:
|
||||
out["tags"] = []
|
||||
return out
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# P-06: Re-Deklaration / Nachdeklaration
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@router.post("/{asset_id}/rights-declarations")
|
||||
def create_rights_declaration(
|
||||
asset_id: int,
|
||||
body: RightsDeclarationBody,
|
||||
tenant: TenantContext = Depends(get_tenant_context),
|
||||
):
|
||||
"""P-06: Explizite Rechte-Erklaerung fuer ein bestehendes Medium.
|
||||
|
||||
Verwendung:
|
||||
- Altmedium ('legacy_unreviewed'): Erste Erklaerung nach P-06 (action_type='legacy_re_declaration')
|
||||
- Medium mit Erklaerung fuer niedrigere Sichtbarkeit: Neue Erklaerung fuer Zielsichtbarkeit
|
||||
(action_type='re_declaration')
|
||||
|
||||
Die Erklaerung aendert NICHT die Sichtbarkeit des Mediums; dafuer PATCH verwenden.
|
||||
"""
|
||||
profile_id = tenant.profile_id
|
||||
decl = body.model_dump() if hasattr(body, "model_dump") else body.dict()
|
||||
target_vis = decl.pop("target_visibility")
|
||||
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
cur.execute(
|
||||
"SELECT id, uploaded_by_profile_id, lifecycle_state, rights_status FROM media_assets WHERE id = %s",
|
||||
(asset_id,),
|
||||
)
|
||||
row = cur.fetchone()
|
||||
if not row:
|
||||
raise HTTPException(status_code=404, detail="Medium nicht gefunden")
|
||||
asset = r2d(row)
|
||||
assert_can_edit_media_asset_metadata(cur, tenant, asset)
|
||||
|
||||
validate_rights_declaration(decl, target_vis)
|
||||
|
||||
rs = (asset.get("rights_status") or "legacy_unreviewed").strip().lower()
|
||||
action_type = "legacy_re_declaration" if rs == "legacy_unreviewed" else "re_declaration"
|
||||
decl_id = write_rights_declaration(cur, asset_id, profile_id, action_type, target_vis, decl)
|
||||
update_rights_quick_fields(cur, asset_id, target_vis)
|
||||
conn.commit()
|
||||
return {
|
||||
"declaration_id": decl_id,
|
||||
"asset_id": asset_id,
|
||||
"action_type": action_type,
|
||||
"target_visibility": target_vis,
|
||||
"rights_status": "declared",
|
||||
}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# P-06: Admin – Legacy-Übersicht
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
admin_rights_router = APIRouter(prefix="/api/admin/media-rights", tags=["admin", "media-rights"])
|
||||
|
||||
|
||||
@admin_rights_router.get("/legacy-summary")
|
||||
def get_legacy_rights_summary(
|
||||
tenant: TenantContext = Depends(get_tenant_context),
|
||||
):
|
||||
"""P-06 Admin: Zusammenfassung wie viele Medien noch im legacy_unreviewed-Status sind."""
|
||||
role = tenant.global_role
|
||||
if not is_platform_admin(role):
|
||||
raise HTTPException(status_code=403, detail="Keine Berechtigung (Plattform-Admin erforderlich)")
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT rights_status, COUNT(*) AS cnt
|
||||
FROM media_assets
|
||||
WHERE lifecycle_state = 'active'
|
||||
GROUP BY rights_status
|
||||
ORDER BY rights_status
|
||||
"""
|
||||
)
|
||||
rows = [r2d(r) for r in cur.fetchall()]
|
||||
totals = {r["rights_status"]: int(r["cnt"]) for r in rows}
|
||||
total_active = sum(totals.values())
|
||||
cur.execute(
|
||||
"SELECT COUNT(*) AS cnt FROM media_asset_rights_declarations"
|
||||
)
|
||||
decl_count_row = cur.fetchone()
|
||||
total_declarations = int(r2d(decl_count_row)["cnt"]) if decl_count_row else 0
|
||||
return {
|
||||
"total_active_assets": total_active,
|
||||
"legacy_unreviewed": totals.get("legacy_unreviewed", 0),
|
||||
"declared": totals.get("declared", 0),
|
||||
"blocked": totals.get("blocked", 0),
|
||||
"total_declarations_logged": total_declarations,
|
||||
}
|
||||
|
||||
|
||||
@admin_rights_router.get("/legacy-assets")
|
||||
def get_legacy_rights_assets(
|
||||
limit: int = Query(100, ge=1, le=500),
|
||||
offset: int = Query(0, ge=0),
|
||||
visibility: Optional[str] = Query(None, pattern="^(private|club|official)$"),
|
||||
tenant: TenantContext = Depends(get_tenant_context),
|
||||
):
|
||||
"""P-06 Admin: Liste der Medien mit rights_status = 'legacy_unreviewed' oder 'blocked'."""
|
||||
role = tenant.global_role
|
||||
if not is_platform_admin(role):
|
||||
raise HTTPException(status_code=403, detail="Keine Berechtigung (Plattform-Admin erforderlich)")
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
conditions = ["ma.lifecycle_state = 'active'", "ma.rights_status != 'declared'"]
|
||||
params: list[Any] = []
|
||||
if visibility:
|
||||
conditions.append("ma.visibility = %s")
|
||||
params.append(visibility)
|
||||
where = " AND ".join(conditions)
|
||||
cur.execute(
|
||||
f"""
|
||||
SELECT ma.id, ma.original_filename, ma.visibility, ma.rights_status,
|
||||
ma.created_at, ma.uploaded_by_profile_id,
|
||||
p.username AS uploader_username
|
||||
FROM media_assets ma
|
||||
LEFT JOIN profiles p ON p.id = ma.uploaded_by_profile_id
|
||||
WHERE {where}
|
||||
ORDER BY ma.created_at DESC
|
||||
LIMIT %s OFFSET %s
|
||||
""",
|
||||
(*params, limit, offset),
|
||||
)
|
||||
assets = [r2d(r) for r in cur.fetchall()]
|
||||
cur.execute(
|
||||
f"""
|
||||
SELECT COUNT(*) AS cnt
|
||||
FROM media_assets ma
|
||||
WHERE {where}
|
||||
""",
|
||||
tuple(params),
|
||||
)
|
||||
total_row = cur.fetchone()
|
||||
total = int(r2d(total_row)["cnt"]) if total_row else 0
|
||||
return {"total": total, "limit": limit, "offset": offset, "assets": assets}
|
||||
@@ -130,8 +130,8 @@ def test_attach_from_asset_duplicate_returns_400(client: TestClient) -> None:
|
||||
|
||||
mock_cur = MagicMock()
|
||||
mock_cur.fetchone.side_effect = [
|
||||
{"created_by": 1, "visibility": "private", "club_id": None},
|
||||
{"c": 0},
|
||||
{"created_by": 1, "visibility": "private", "club_id": None}, # _assert_can_edit_exercise
|
||||
{"c": 0}, # _count_exercise_media
|
||||
{
|
||||
"id": 5,
|
||||
"mime_type": "image/jpeg",
|
||||
@@ -142,14 +142,15 @@ def test_attach_from_asset_duplicate_returns_400(client: TestClient) -> None:
|
||||
"uploaded_by_profile_id": 1,
|
||||
"lifecycle_state": "active",
|
||||
"storage_key": _SK_OFF_A,
|
||||
},
|
||||
{"id": 1},
|
||||
}, # asset lookup
|
||||
{"visibility": "private"}, # P-06: exercise visibility
|
||||
{"id": 1}, # duplicate check -> 400
|
||||
]
|
||||
mock_cm = _mock_db(mock_cur)
|
||||
|
||||
with patch("routers.exercises.get_db", return_value=mock_cm), patch(
|
||||
"routers.exercises.get_cursor", return_value=mock_cur
|
||||
):
|
||||
), patch("routers.exercises.assert_rights_for_exercise_link"):
|
||||
r = client.post(
|
||||
"/api/exercises/3/media/from-asset",
|
||||
headers={"X-Auth-Token": "t", "Content-Type": "application/json"},
|
||||
@@ -196,8 +197,8 @@ def test_attach_from_asset_ok_mocked(client: TestClient) -> None:
|
||||
}
|
||||
mock_cur = MagicMock()
|
||||
mock_cur.fetchone.side_effect = [
|
||||
{"created_by": 1, "visibility": "private", "club_id": None},
|
||||
{"c": 0},
|
||||
{"created_by": 1, "visibility": "private", "club_id": None}, # _assert_can_edit_exercise
|
||||
{"c": 0}, # _count_exercise_media
|
||||
{
|
||||
"id": 5,
|
||||
"mime_type": "image/jpeg",
|
||||
@@ -208,15 +209,16 @@ def test_attach_from_asset_ok_mocked(client: TestClient) -> None:
|
||||
"uploaded_by_profile_id": 1,
|
||||
"lifecycle_state": "active",
|
||||
"storage_key": _SK_OFF_B,
|
||||
},
|
||||
None,
|
||||
inserted,
|
||||
}, # asset lookup
|
||||
{"visibility": "private"}, # P-06: exercise visibility
|
||||
None, # duplicate check -> None (no duplicate)
|
||||
inserted, # INSERT RETURNING
|
||||
]
|
||||
mock_cm = _mock_db(mock_cur)
|
||||
|
||||
with patch("routers.exercises.get_db", return_value=mock_cm), patch(
|
||||
"routers.exercises.get_cursor", return_value=mock_cur
|
||||
):
|
||||
), patch("routers.exercises.assert_rights_for_exercise_link"):
|
||||
r = client.post(
|
||||
"/api/exercises/3/media/from-asset",
|
||||
headers={"X-Auth-Token": "t", "Content-Type": "application/json"},
|
||||
|
||||
@@ -73,6 +73,8 @@ _PERMISSION_PATCHES = [
|
||||
("routers.media_assets._media_assets_tags_column_present", {"return_value": False}),
|
||||
("routers.media_assets.get_effective_media_root", {"return_value": "/tmp/media"}),
|
||||
("routers.media_assets._relocate_asset_file_if_governance_changed", {"return_value": None}),
|
||||
# P-06: bestehende Tests testen Copyright, nicht Rechteerklaerung – "ok" mocken
|
||||
("routers.media_assets.check_rights_coverage", {"return_value": "ok"}),
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,446 @@
|
||||
"""
|
||||
P-06: Rechte-Erklaerung – Backend-Tests.
|
||||
|
||||
Abgedeckt:
|
||||
1. validate_rights_declaration – alle Pflichtfelder
|
||||
2. check_rights_coverage – ok / insufficient / legacy / blocked
|
||||
3. assert_rights_for_promotion – richtiges Fehlermuster
|
||||
4. PATCH /api/media-assets/{id} – Promotion mit und ohne P-06
|
||||
5. POST /api/media-assets/{id}/rights-declarations – Re-Deklaration
|
||||
6. POST /api/media-assets/bulk-patch – P-06-Pfad im Bulk
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from contextlib import ExitStack
|
||||
from unittest.mock import MagicMock, patch, call
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from fastapi import HTTPException
|
||||
|
||||
os.environ.setdefault("SKIP_DB_MIGRATE", "1")
|
||||
|
||||
from main import app
|
||||
from media_rights import (
|
||||
validate_rights_declaration,
|
||||
check_rights_coverage,
|
||||
assert_rights_for_promotion,
|
||||
rights_covers_target,
|
||||
visibility_level,
|
||||
)
|
||||
from tenant_context import TenantContext, get_tenant_context
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Helpers
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
_SUPERADMIN_TENANT = TenantContext(
|
||||
profile_id=1,
|
||||
global_role="superadmin",
|
||||
effective_club_id=None,
|
||||
club_ids=frozenset(),
|
||||
memberships=[],
|
||||
)
|
||||
|
||||
_FULL_DECL = {
|
||||
"rights_holder_confirmed": True,
|
||||
"contains_identifiable_persons": False,
|
||||
"person_consent_confirmed": None,
|
||||
"contains_minors": False,
|
||||
"parental_consent_confirmed": None,
|
||||
"contains_music": False,
|
||||
"music_rights_confirmed": None,
|
||||
"contains_third_party_content": False,
|
||||
"third_party_rights_confirmed": None,
|
||||
}
|
||||
|
||||
_PRIVATE_ASSET = {
|
||||
"id": 42,
|
||||
"visibility": "private",
|
||||
"club_id": 7,
|
||||
"uploaded_by_profile_id": 1,
|
||||
"lifecycle_state": "active",
|
||||
"copyright_notice": "Rechteinhaber 2026",
|
||||
"original_filename": "foto.jpg",
|
||||
"sha256": "a" * 64,
|
||||
"storage_key": f"library/verein-7/image/{'a' * 64}.jpg",
|
||||
"storage_backend": "local",
|
||||
"mime_type": "image/jpeg",
|
||||
"byte_size": 1024,
|
||||
"created_at": None,
|
||||
"tags": [],
|
||||
"rights_status": "legacy_unreviewed",
|
||||
"rights_declared_for_visibility": None,
|
||||
}
|
||||
|
||||
_DECLARED_ASSET = {**_PRIVATE_ASSET, "rights_status": "declared", "rights_declared_for_visibility": "private"}
|
||||
_BLOCKED_ASSET = {**_PRIVATE_ASSET, "rights_status": "blocked", "rights_declared_for_visibility": None}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client() -> TestClient:
|
||||
return TestClient(app)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _clear_overrides():
|
||||
yield
|
||||
app.dependency_overrides.pop(get_tenant_context, None)
|
||||
|
||||
|
||||
def _make_db_mocks(asset: dict) -> tuple[MagicMock, MagicMock]:
|
||||
mock_cur = MagicMock()
|
||||
mock_cur.fetchone.return_value = asset
|
||||
mock_conn = MagicMock()
|
||||
mock_cm = MagicMock()
|
||||
mock_cm.__enter__.return_value = mock_conn
|
||||
mock_cm.__exit__.return_value = False
|
||||
return mock_cm, mock_cur
|
||||
|
||||
|
||||
_PERMISSION_PATCHES = [
|
||||
("routers.media_assets.assert_can_edit_media_asset_metadata", {}),
|
||||
("routers.media_assets.assert_valid_governance_visibility", {}),
|
||||
("routers.media_assets._media_assets_tags_column_present", {"return_value": False}),
|
||||
("routers.media_assets.get_effective_media_root", {"return_value": "/tmp/media"}),
|
||||
("routers.media_assets._relocate_asset_file_if_governance_changed", {"return_value": None}),
|
||||
]
|
||||
|
||||
|
||||
def _enter_permission_patches(stack: ExitStack) -> None:
|
||||
for target, kwargs in _PERMISSION_PATCHES:
|
||||
stack.enter_context(patch(target, **kwargs))
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
# 1. validate_rights_declaration – Unit-Tests (kein HTTP)
|
||||
# ===========================================================================
|
||||
|
||||
class TestValidateRightsDeclaration:
|
||||
|
||||
def test_missing_rights_holder_raises(self):
|
||||
decl = {**_FULL_DECL, "rights_holder_confirmed": False}
|
||||
with pytest.raises(HTTPException) as exc:
|
||||
validate_rights_declaration(decl, "private")
|
||||
assert exc.value.status_code == 400
|
||||
assert exc.value.detail["code"] == "RIGHTS_DECLARATION_REQUIRED"
|
||||
|
||||
def test_identifiable_persons_none_raises(self):
|
||||
decl = {**_FULL_DECL, "contains_identifiable_persons": None}
|
||||
with pytest.raises(HTTPException) as exc:
|
||||
validate_rights_declaration(decl, "private")
|
||||
assert exc.value.status_code == 400
|
||||
assert exc.value.detail["code"] == "RIGHTS_DECLARATION_REQUIRED"
|
||||
|
||||
def test_person_consent_required_when_persons_present(self):
|
||||
decl = {**_FULL_DECL, "contains_identifiable_persons": True, "person_consent_confirmed": None}
|
||||
with pytest.raises(HTTPException) as exc:
|
||||
validate_rights_declaration(decl, "club")
|
||||
assert exc.value.detail["code"] == "PERSON_CONSENT_REQUIRED"
|
||||
|
||||
def test_minors_none_raises(self):
|
||||
decl = {**_FULL_DECL, "contains_minors": None}
|
||||
with pytest.raises(HTTPException) as exc:
|
||||
validate_rights_declaration(decl, "private")
|
||||
assert exc.value.detail["code"] == "RIGHTS_DECLARATION_REQUIRED"
|
||||
|
||||
def test_parental_consent_required_when_minors_present(self):
|
||||
decl = {**_FULL_DECL, "contains_minors": True, "parental_consent_confirmed": False}
|
||||
with pytest.raises(HTTPException) as exc:
|
||||
validate_rights_declaration(decl, "official")
|
||||
assert exc.value.detail["code"] == "PARENTAL_CONSENT_REQUIRED"
|
||||
|
||||
def test_music_none_raises(self):
|
||||
decl = {**_FULL_DECL, "contains_music": None}
|
||||
with pytest.raises(HTTPException) as exc:
|
||||
validate_rights_declaration(decl, "private")
|
||||
assert exc.value.detail["code"] == "RIGHTS_DECLARATION_REQUIRED"
|
||||
|
||||
def test_music_rights_required_when_music_present(self):
|
||||
decl = {**_FULL_DECL, "contains_music": True, "music_rights_confirmed": False}
|
||||
with pytest.raises(HTTPException) as exc:
|
||||
validate_rights_declaration(decl, "private")
|
||||
assert exc.value.detail["code"] == "MUSIC_RIGHTS_REQUIRED"
|
||||
|
||||
def test_third_party_none_raises(self):
|
||||
decl = {**_FULL_DECL, "contains_third_party_content": None}
|
||||
with pytest.raises(HTTPException) as exc:
|
||||
validate_rights_declaration(decl, "private")
|
||||
assert exc.value.detail["code"] == "RIGHTS_DECLARATION_REQUIRED"
|
||||
|
||||
def test_third_party_rights_required_when_content_present(self):
|
||||
decl = {**_FULL_DECL, "contains_third_party_content": True, "third_party_rights_confirmed": None}
|
||||
with pytest.raises(HTTPException) as exc:
|
||||
validate_rights_declaration(decl, "official")
|
||||
assert exc.value.detail["code"] == "THIRD_PARTY_RIGHTS_REQUIRED"
|
||||
|
||||
def test_full_clean_decl_passes(self):
|
||||
validate_rights_declaration(_FULL_DECL, "official")
|
||||
|
||||
def test_full_decl_with_all_true_passes(self):
|
||||
decl = {
|
||||
"rights_holder_confirmed": True,
|
||||
"contains_identifiable_persons": True,
|
||||
"person_consent_confirmed": True,
|
||||
"contains_minors": True,
|
||||
"parental_consent_confirmed": True,
|
||||
"contains_music": True,
|
||||
"music_rights_confirmed": True,
|
||||
"contains_third_party_content": True,
|
||||
"third_party_rights_confirmed": True,
|
||||
}
|
||||
validate_rights_declaration(decl, "official")
|
||||
|
||||
def test_private_also_requires_full_declaration(self):
|
||||
"""Konservative Erstannahme: private erfordert dieselbe Erklaerung wie official."""
|
||||
decl = {**_FULL_DECL, "contains_identifiable_persons": None}
|
||||
with pytest.raises(HTTPException):
|
||||
validate_rights_declaration(decl, "private")
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
# 2. check_rights_coverage – Unit-Tests mit Mock-Cursor
|
||||
# ===========================================================================
|
||||
|
||||
class TestCheckRightsCoverage:
|
||||
|
||||
def _cur(self, row):
|
||||
cur = MagicMock()
|
||||
cur.fetchone.return_value = row
|
||||
return cur
|
||||
|
||||
def test_no_asset_returns_no_declaration(self):
|
||||
cur = self._cur(None)
|
||||
assert check_rights_coverage(cur, 1, "private") == "no_declaration"
|
||||
|
||||
def test_blocked_returns_blocked(self):
|
||||
cur = self._cur({"rights_status": "blocked", "rights_declared_for_visibility": None})
|
||||
assert check_rights_coverage(cur, 1, "private") == "blocked"
|
||||
|
||||
def test_legacy_returns_legacy(self):
|
||||
cur = self._cur({"rights_status": "legacy_unreviewed", "rights_declared_for_visibility": None})
|
||||
assert check_rights_coverage(cur, 1, "club") == "legacy"
|
||||
|
||||
def test_declared_private_covers_private(self):
|
||||
cur = self._cur({"rights_status": "declared", "rights_declared_for_visibility": "private"})
|
||||
assert check_rights_coverage(cur, 1, "private") == "ok"
|
||||
|
||||
def test_declared_private_insufficient_for_club(self):
|
||||
cur = self._cur({"rights_status": "declared", "rights_declared_for_visibility": "private"})
|
||||
assert check_rights_coverage(cur, 1, "club") == "insufficient"
|
||||
|
||||
def test_declared_official_covers_all(self):
|
||||
cur = self._cur({"rights_status": "declared", "rights_declared_for_visibility": "official"})
|
||||
assert check_rights_coverage(cur, 1, "private") == "ok"
|
||||
cur2 = self._cur({"rights_status": "declared", "rights_declared_for_visibility": "official"})
|
||||
assert check_rights_coverage(cur2, 1, "club") == "ok"
|
||||
cur3 = self._cur({"rights_status": "declared", "rights_declared_for_visibility": "official"})
|
||||
assert check_rights_coverage(cur3, 1, "official") == "ok"
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
# 3. assert_rights_for_promotion – Fehlermuster
|
||||
# ===========================================================================
|
||||
|
||||
class TestAssertRightsForPromotion:
|
||||
|
||||
def _cur(self, row):
|
||||
cur = MagicMock()
|
||||
cur.fetchone.return_value = row
|
||||
return cur
|
||||
|
||||
def test_ok_passes(self):
|
||||
cur = self._cur({"rights_status": "declared", "rights_declared_for_visibility": "official"})
|
||||
assert_rights_for_promotion(cur, 1, "official") # no raise
|
||||
|
||||
def test_legacy_raises_legacy_code(self):
|
||||
cur = self._cur({"rights_status": "legacy_unreviewed", "rights_declared_for_visibility": None})
|
||||
with pytest.raises(HTTPException) as exc:
|
||||
assert_rights_for_promotion(cur, 1, "club")
|
||||
assert exc.value.status_code == 400
|
||||
assert exc.value.detail["code"] == "LEGACY_REDECLARATION_REQUIRED"
|
||||
|
||||
def test_blocked_raises_403(self):
|
||||
cur = self._cur({"rights_status": "blocked", "rights_declared_for_visibility": None})
|
||||
with pytest.raises(HTTPException) as exc:
|
||||
assert_rights_for_promotion(cur, 1, "official")
|
||||
assert exc.value.status_code == 403
|
||||
assert exc.value.detail["code"] == "RIGHTS_BLOCKED"
|
||||
|
||||
def test_insufficient_raises_scope_code(self):
|
||||
cur = self._cur({"rights_status": "declared", "rights_declared_for_visibility": "private"})
|
||||
with pytest.raises(HTTPException) as exc:
|
||||
assert_rights_for_promotion(cur, 1, "official")
|
||||
assert exc.value.status_code == 400
|
||||
assert exc.value.detail["code"] == "RIGHTS_SCOPE_INSUFFICIENT"
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
# 4. PATCH /api/media-assets/{id} – P-06-Promotion via HTTP
|
||||
# ===========================================================================
|
||||
|
||||
class TestPatchP06Promotion:
|
||||
|
||||
def test_promote_legacy_without_decl_returns_400(self, client):
|
||||
"""PATCH private->club ohne P-06-Felder muss LEGACY_REDECLARATION_REQUIRED liefern."""
|
||||
app.dependency_overrides[get_tenant_context] = lambda: _SUPERADMIN_TENANT
|
||||
mock_cm, mock_cur = _make_db_mocks(_PRIVATE_ASSET)
|
||||
mock_cur.fetchone.side_effect = [_PRIVATE_ASSET, {"rights_status": "legacy_unreviewed", "rights_declared_for_visibility": None}]
|
||||
|
||||
with ExitStack() as stack:
|
||||
stack.enter_context(patch("routers.media_assets.get_db", return_value=mock_cm))
|
||||
stack.enter_context(patch("routers.media_assets.get_cursor", return_value=mock_cur))
|
||||
_enter_permission_patches(stack)
|
||||
r = client.patch(
|
||||
"/api/media-assets/42",
|
||||
json={"visibility": "club", "club_id": 7, "copyright_notice": "Rechteinhaber 2026"},
|
||||
headers={"X-Auth-Token": "t"},
|
||||
)
|
||||
|
||||
assert r.status_code == 400
|
||||
d = r.json()["detail"]
|
||||
assert d["code"] == "LEGACY_REDECLARATION_REQUIRED"
|
||||
|
||||
def test_promote_legacy_with_full_decl_calls_write_declaration(self, client):
|
||||
"""PATCH private->club mit vollstaendiger P-06-Erklaerung schreibt Declaration-Log."""
|
||||
app.dependency_overrides[get_tenant_context] = lambda: _SUPERADMIN_TENANT
|
||||
mock_cm, mock_cur = _make_db_mocks(_PRIVATE_ASSET)
|
||||
updated_asset = {**_PRIVATE_ASSET, "visibility": "club"}
|
||||
mock_cur.fetchone.side_effect = [
|
||||
_PRIVATE_ASSET,
|
||||
{"rights_status": "legacy_unreviewed", "rights_declared_for_visibility": None},
|
||||
updated_asset,
|
||||
]
|
||||
|
||||
with ExitStack() as stack:
|
||||
stack.enter_context(patch("routers.media_assets.get_db", return_value=mock_cm))
|
||||
stack.enter_context(patch("routers.media_assets.get_cursor", return_value=mock_cur))
|
||||
_enter_permission_patches(stack)
|
||||
wr = stack.enter_context(patch("routers.media_assets.write_rights_declaration", return_value=1))
|
||||
uq = stack.enter_context(patch("routers.media_assets.update_rights_quick_fields"))
|
||||
r = client.patch(
|
||||
"/api/media-assets/42",
|
||||
json={
|
||||
"visibility": "club",
|
||||
"club_id": 7,
|
||||
"copyright_notice": "Rechteinhaber 2026",
|
||||
**_FULL_DECL,
|
||||
},
|
||||
headers={"X-Auth-Token": "t"},
|
||||
)
|
||||
|
||||
assert r.status_code == 200
|
||||
assert wr.called
|
||||
call_args = wr.call_args
|
||||
assert call_args.args[3] == "legacy_re_declaration"
|
||||
assert call_args.args[4] == "club"
|
||||
assert uq.called
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
# 5. POST /api/media-assets/{id}/rights-declarations – Re-Deklaration
|
||||
# ===========================================================================
|
||||
|
||||
class TestPostRightsDeclaration:
|
||||
|
||||
def test_redeclaration_for_legacy_asset_succeeds(self, client):
|
||||
"""Nachdeklaration fuer Altmedium setzt action_type='legacy_re_declaration'."""
|
||||
app.dependency_overrides[get_tenant_context] = lambda: _SUPERADMIN_TENANT
|
||||
mock_cm, mock_cur = _make_db_mocks(_PRIVATE_ASSET)
|
||||
mock_cur.fetchone.return_value = _PRIVATE_ASSET
|
||||
|
||||
with ExitStack() as stack:
|
||||
stack.enter_context(patch("routers.media_assets.get_db", return_value=mock_cm))
|
||||
stack.enter_context(patch("routers.media_assets.get_cursor", return_value=mock_cur))
|
||||
stack.enter_context(patch("routers.media_assets.assert_can_edit_media_asset_metadata"))
|
||||
wr = stack.enter_context(patch("routers.media_assets.write_rights_declaration", return_value=99))
|
||||
stack.enter_context(patch("routers.media_assets.update_rights_quick_fields"))
|
||||
r = client.post(
|
||||
"/api/media-assets/42/rights-declarations",
|
||||
json={"target_visibility": "club", **_FULL_DECL},
|
||||
headers={"X-Auth-Token": "t"},
|
||||
)
|
||||
|
||||
assert r.status_code == 200
|
||||
data = r.json()
|
||||
assert data["action_type"] == "legacy_re_declaration"
|
||||
assert data["declaration_id"] == 99
|
||||
assert wr.called
|
||||
|
||||
def test_redeclaration_incomplete_decl_returns_400_or_422(self, client):
|
||||
"""Fehlende Erklaerungsfelder fuehren zu 400 (business logic) oder 422 (Pydantic)."""
|
||||
app.dependency_overrides[get_tenant_context] = lambda: _SUPERADMIN_TENANT
|
||||
mock_cm, mock_cur = _make_db_mocks(_PRIVATE_ASSET)
|
||||
|
||||
with ExitStack() as stack:
|
||||
stack.enter_context(patch("routers.media_assets.get_db", return_value=mock_cm))
|
||||
stack.enter_context(patch("routers.media_assets.get_cursor", return_value=mock_cur))
|
||||
stack.enter_context(patch("routers.media_assets.assert_can_edit_media_asset_metadata"))
|
||||
r = client.post(
|
||||
"/api/media-assets/42/rights-declarations",
|
||||
# Fehlende Pflichtfelder (contains_identifiable_persons etc.) -> Pydantic 422 ODER
|
||||
# validate_rights_declaration 400 je nach welche Felder fehlen
|
||||
json={"target_visibility": "private", "rights_holder_confirmed": True},
|
||||
headers={"X-Auth-Token": "t"},
|
||||
)
|
||||
|
||||
assert r.status_code in (400, 422)
|
||||
|
||||
def test_redeclaration_asset_not_found_returns_404(self, client):
|
||||
app.dependency_overrides[get_tenant_context] = lambda: _SUPERADMIN_TENANT
|
||||
mock_cm, mock_cur = _make_db_mocks(None)
|
||||
|
||||
with ExitStack() as stack:
|
||||
stack.enter_context(patch("routers.media_assets.get_db", return_value=mock_cm))
|
||||
stack.enter_context(patch("routers.media_assets.get_cursor", return_value=mock_cur))
|
||||
stack.enter_context(patch("routers.media_assets.assert_can_edit_media_asset_metadata"))
|
||||
r = client.post(
|
||||
"/api/media-assets/999/rights-declarations",
|
||||
json={"target_visibility": "private", **_FULL_DECL},
|
||||
headers={"X-Auth-Token": "t"},
|
||||
)
|
||||
|
||||
assert r.status_code == 404
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
# 6. Bulk-Patch – P-06-Promotion im Batch
|
||||
# ===========================================================================
|
||||
|
||||
class TestBulkPatchP06:
|
||||
|
||||
def test_bulk_promote_legacy_without_decl_reports_failure(self, client):
|
||||
"""Bulk-Patch: Legacy-Asset ohne P-06-Felder landet in 'failed', nicht 422."""
|
||||
app.dependency_overrides[get_tenant_context] = lambda: _SUPERADMIN_TENANT
|
||||
mock_cm, mock_cur = _make_db_mocks(_PRIVATE_ASSET)
|
||||
mock_cur.fetchone.side_effect = [
|
||||
_PRIVATE_ASSET,
|
||||
{"rights_status": "legacy_unreviewed", "rights_declared_for_visibility": None},
|
||||
]
|
||||
|
||||
with ExitStack() as stack:
|
||||
stack.enter_context(patch("routers.media_assets.get_db", return_value=mock_cm))
|
||||
stack.enter_context(patch("routers.media_assets.get_cursor", return_value=mock_cur))
|
||||
stack.enter_context(patch("routers.media_assets.assert_can_edit_media_asset_metadata"))
|
||||
stack.enter_context(patch("routers.media_assets.assert_valid_governance_visibility"))
|
||||
stack.enter_context(patch("routers.media_assets._media_assets_tags_column_present", return_value=False))
|
||||
stack.enter_context(patch("routers.media_assets.get_effective_media_root", return_value="/tmp"))
|
||||
stack.enter_context(patch("routers.media_assets._relocate_asset_file_if_governance_changed", return_value=None))
|
||||
r = client.post(
|
||||
"/api/media-assets/bulk-patch",
|
||||
json={
|
||||
"media_asset_ids": [42],
|
||||
"visibility": "club",
|
||||
"club_id": 7,
|
||||
"copyright_notice": "Rechteinhaber 2026",
|
||||
},
|
||||
headers={"X-Auth-Token": "t"},
|
||||
)
|
||||
|
||||
assert r.status_code == 200
|
||||
data = r.json()
|
||||
assert data["failed_count"] == 1
|
||||
assert data["updated_count"] == 0
|
||||
assert "LEGACY_REDECLARATION_REQUIRED" in data["failed"][0]["detail"] or \
|
||||
"RIGHTS_SCOPE_INSUFFICIENT" in data["failed"][0]["detail"]
|
||||
+13
-5
@@ -1,8 +1,8 @@
|
||||
# Shinkan Jinkendo Version Information
|
||||
|
||||
APP_VERSION = "0.8.74"
|
||||
BUILD_DATE = "2026-05-10"
|
||||
DB_SCHEMA_VERSION = "20260510047"
|
||||
APP_VERSION = "0.8.75"
|
||||
BUILD_DATE = "2026-05-11"
|
||||
DB_SCHEMA_VERSION = "20260511048"
|
||||
|
||||
MODULE_VERSIONS = {
|
||||
"legal_documents": "1.2.0", # jsPDF-Download auf LegalPage (oeffentlich) + Admin; Abschnitts-Sortierung/-Einfuegen
|
||||
@@ -14,11 +14,12 @@ MODULE_VERSIONS = {
|
||||
"club_join_requests": "1.0.1", # Depends(get_tenant_context)
|
||||
"admin_users": "1.0.0", # GET /api/admin/users
|
||||
"platform_media_storage": "1.0.0", # GET/PUT /api/admin/platform-media-storage (Superadmin-Pfad unter MEDIA_ROOT)
|
||||
"media_assets": "1.12.3", # P-04b: Umlautkorrektur Fehlermeldung; Tests gehaertet
|
||||
"media_rights": "1.0.0", # P-06: zentrales Policy-Modul (validate, coverage, write declaration)
|
||||
"media_assets": "1.13.0", # P-06: Rechte-Erklaerung bei Upload/Promotion; Re-Deklarations-Endpoint; Admin-Legacy-Summary
|
||||
"groups": "0.1.0",
|
||||
"skills": "0.1.0",
|
||||
"methods": "0.1.0",
|
||||
"exercises": "2.19.1", # Verein: PUT default_club_media_copyright + Prompt beim Speichern (fehlende File-Asset-Copyrights)
|
||||
"exercises": "2.20.0", # P-06: upload_exercise_media + from-asset Rechtspruefung
|
||||
"training_units": "0.2.0",
|
||||
"training_programs": "0.1.0",
|
||||
"planning": "0.8.1", # Vorlagen Leseprüfung library_content_visible_to_profile
|
||||
@@ -30,6 +31,13 @@ MODULE_VERSIONS = {
|
||||
}
|
||||
|
||||
CHANGELOG = [
|
||||
{
|
||||
"version": "0.8.75",
|
||||
"date": "2026-05-11",
|
||||
"changes": [
|
||||
"P-06 (Upload-Einwilligungsdialog) technisch umgesetzt unter konservativen Erstannahmen (p06-v1-conservative): Migration 048 (media_asset_rights_declarations + rights_status/rights_declared_for_visibility/rights_declared_at in media_assets); zentrales Policy-Modul media_rights.py; Bulk-Upload und PATCH/Bulk-Patch mit P-06-Enforcement; Re-Deklarations-Endpoint (POST /api/media-assets/{id}/rights-declarations); Admin-Legacy-Summary (GET /api/admin/media-rights/legacy-summary+/legacy-assets); exercises.py: P-06 bei upload_exercise_media und from-asset; Frontend: RightsDeclarationDialog + Altbestand-Indikator in Medienbibliothek. KRIT-04 bleibt offen bis juristische Validierung.",
|
||||
],
|
||||
},
|
||||
{
|
||||
"version": "0.8.74",
|
||||
"date": "2026-05-10",
|
||||
|
||||
Reference in new issue
Block a user