feat: enhance governance visibility checks and update login rate limit
- Updated governance visibility logic in `assert_valid_governance_visibility` to enforce club membership checks for platform admins and ensure proper club existence validation. - Increased login request limit from 5 to 30 per minute to improve user experience. - Refactored exercise update logic to better handle visibility and club ID requirements, ensuring compliance with governance rules.
This commit is contained in:
1 parent
0181575962
commit
870a7611dc
5 files changed
+64
-18
No files matched your search
@@ -853,23 +853,59 @@ def update_exercise(
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
|
||||
# Existiert die Übung?
|
||||
cur.execute("SELECT created_by FROM exercises WHERE id = %s", (exercise_id,))
|
||||
cur.execute(
|
||||
"SELECT created_by, visibility, club_id FROM exercises WHERE id = %s",
|
||||
(exercise_id,),
|
||||
)
|
||||
row = cur.fetchone()
|
||||
if not row:
|
||||
raise HTTPException(status_code=404, detail="Übung nicht gefunden")
|
||||
|
||||
# Permission Check
|
||||
if _row_created_by(row) != profile_id:
|
||||
raise HTTPException(status_code=403, detail="Nur der Ersteller darf editieren")
|
||||
|
||||
# UPDATE (nur gesetzte Felder)
|
||||
fields = []
|
||||
params = []
|
||||
ex_vis = (row.get("visibility") or "private").strip().lower()
|
||||
ex_cid = row.get("club_id")
|
||||
if ex_cid is not None:
|
||||
ex_cid = int(ex_cid)
|
||||
|
||||
data = body.dict(exclude_unset=True)
|
||||
|
||||
# Basis-Felder
|
||||
next_vis = ex_vis
|
||||
if "visibility" in data and data["visibility"] is not None:
|
||||
v_raw = str(data["visibility"]).strip().lower()
|
||||
if v_raw:
|
||||
next_vis = v_raw
|
||||
|
||||
next_club = ex_cid
|
||||
if "club_id" in data:
|
||||
raw_c = data["club_id"]
|
||||
if raw_c in (None, "", []):
|
||||
next_club = None
|
||||
else:
|
||||
next_club = int(raw_c)
|
||||
|
||||
if next_vis == "club":
|
||||
if next_club is None:
|
||||
next_club = tenant.effective_club_id
|
||||
if next_club is None:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="Vereins-Übung: club_id angeben oder aktiven Verein wählen (X-Active-Club-Id).",
|
||||
)
|
||||
data["club_id"] = next_club
|
||||
|
||||
if next_vis != ex_vis:
|
||||
data["visibility"] = next_vis
|
||||
|
||||
gov_club = next_club if next_vis == "club" else None
|
||||
assert_valid_governance_visibility(
|
||||
cur, profile_id, tenant.global_role, next_vis, gov_club
|
||||
)
|
||||
|
||||
fields = []
|
||||
params = []
|
||||
|
||||
for field in ["title", "summary", "goal", "execution", "preparation", "trainer_notes",
|
||||
"duration_min", "duration_max", "group_size_min", "group_size_max",
|
||||
"visibility", "status", "club_id"]:
|
||||
@@ -877,12 +913,10 @@ def update_exercise(
|
||||
fields.append(f"{field} = %s")
|
||||
params.append(data[field])
|
||||
|
||||
# Equipment (JSONB)
|
||||
if "equipment" in data:
|
||||
fields.append("equipment = %s")
|
||||
params.append(json.dumps(data["equipment"]) if data["equipment"] else None)
|
||||
|
||||
# UPDATE ausführen (wenn Basis-Felder geändert wurden)
|
||||
if fields:
|
||||
fields.append("updated_at = NOW()")
|
||||
params.append(exercise_id)
|
||||
@@ -890,10 +924,8 @@ def update_exercise(
|
||||
cur.execute(query, params)
|
||||
conn.commit()
|
||||
|
||||
# M:N Relations aktualisieren (wenn angegeben)
|
||||
assign_exercise_relations(cur, conn, exercise_id, data)
|
||||
|
||||
# Vollständiges Objekt zurückgeben
|
||||
exercise = enrich_exercise_detail(exercise_id, cur)
|
||||
|
||||
return exercise
|
||||
|
||||
Reference in new issue
Block a user