feat: implement exercise promotion logic for training units
Deploy Development / deploy (push) Successful in 33s
Test Suite / pytest-backend (push) Successful in 6s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 7s
Test Suite / playwright-tests (push) Successful in 45s

- Added functionality to promote private exercises used in training units to club visibility, allowing better access for trainers and members.
- Introduced helper functions to retrieve distinct exercise IDs and group club IDs for scheduled units.
- Updated the create, update, and quick create training unit methods to include exercise promotion logic, enhancing exercise management within clubs.
This commit is contained in:
Lars committed 2026-05-07 10:09:25 +02:00
1 parent c6a7d668c5
commit f9d518fb78
5 files changed
+502 -20

No files matched your search

+43 -19
View File
@@ -17,6 +17,7 @@ from pydantic import BaseModel, Field, model_validator
from db import get_db, get_cursor, r2d
from club_tenancy import (
assert_valid_governance_visibility,
can_manage_club_org,
club_admin_shares_club_with_creator,
has_club_role,
is_platform_admin,
@@ -778,6 +779,10 @@ def bulk_patch_exercises_metadata(
Übungen vollständig durch diese Liste ersetzt (leeres Array entfernt alle).
Berechtigt: Ersteller der jeweiligen Übung oder Plattform-Admin (admin/superadmin).
Zusätzlich: Vereinsorga (club_admin) darf **nur** bei reiner Sichtbarkeitsänderung auf ``club``
für den eigenen Verein (`club_id` / aktiver Verein) fremde Übungen freigeben — analog
Trainingseinheit-Speichern.
Governance wie bei Einzel-PUT (official nur Plattform-Admin; club mit Mitgliedschaft bzw. Admin).
"""
profile_id = tenant.profile_id
@@ -861,14 +866,6 @@ def bulk_patch_exercises_metadata(
owner = rowd.get("created_by")
if owner is not None:
owner = int(owner)
if owner != profile_id and not is_platform_admin(role):
failed.append(
{
"id": ex_id,
"detail": "Keine Berechtigung (nur Ersteller oder Plattform-Admin)",
}
)
continue
ex_vis = (rowd.get("visibility") or "private").strip().lower()
ex_cid_raw = rowd.get("club_id")
@@ -882,18 +879,45 @@ def bulk_patch_exercises_metadata(
if patch_visibility and body.club_id is not None:
next_club = int(body.club_id)
if patch_visibility and next_vis == "club" and next_club is None:
eff = tenant.effective_club_id
next_club = int(eff) if eff is not None else None
if patch_visibility and next_vis == "club" and next_club is None:
failed.append(
{
"id": ex_id,
"detail": "Vereins-Übung: club_id angeben oder aktiven Verein wählen (X-Active-Club-Id).",
}
)
continue
other_meta_patches = (
patch_status
or patch_focus_areas
or patch_style_dirs
or patch_training_types
or patch_target_groups
)
is_owner_or_platform = owner == profile_id or is_platform_admin(role)
if not is_owner_or_platform:
org_club_promo_only = (
patch_visibility
and not other_meta_patches
and next_vis == "club"
and next_club is not None
and can_manage_club_org(cur, profile_id, int(next_club), role)
)
if not org_club_promo_only:
failed.append(
{
"id": ex_id,
"detail": "Keine Berechtigung (Ersteller, Plattform-Admin oder Vereinsorga bei reiner Vereinsfreigabe).",
}
)
continue
if patch_visibility:
if next_vis == "club":
if next_club is None:
next_club = tenant.effective_club_id
if next_club is None:
failed.append(
{
"id": ex_id,
"detail": "Vereins-Übung: club_id angeben oder aktiven Verein wählen (X-Active-Club-Id).",
}
)
continue
gov_club = next_club if next_vis == "club" else None
try:
assert_valid_governance_visibility(cur, profile_id, role, next_vis, gov_club)