feat: implement tenant context resolution and update profiles API
- Introduced tenant context resolution in the profiles API, allowing for effective club identification based on user memberships. - Updated the `GET /profiles/me` endpoint to return `effective_club_id` and removed reliance on the deprecated `X-Active-Club-Id` header. - Bumped application version to 0.8.22 in both backend and frontend files. - Enhanced changelog to document the new version and changes made in this release.
This commit is contained in:
1 parent
413a096432
commit
4b6fd49940
8 files changed
+362
-11
No files matched your search
@@ -12,6 +12,7 @@ from fastapi import APIRouter, HTTPException, Header, Depends
|
||||
from db import get_db, get_cursor, r2d
|
||||
from auth import require_auth
|
||||
from club_tenancy import assert_club_member, memberships_with_roles, is_platform_admin
|
||||
from tenant_context import resolve_tenant_context
|
||||
from models import ProfileCreate, ProfileUpdate
|
||||
|
||||
router = APIRouter(prefix="/api", tags=["profiles"])
|
||||
@@ -34,9 +35,12 @@ def get_pid(x_profile_id: Optional[str] = Header(default=None)) -> str:
|
||||
|
||||
# ── Current User Profile ──────────────────────────────────────────────────────
|
||||
@router.get("/profiles/me")
|
||||
def get_current_profile(session=Depends(require_auth)):
|
||||
"""Get current user's profile (for auth check on refresh)."""
|
||||
profile_id = session['profile_id']
|
||||
def get_current_profile(
|
||||
session=Depends(require_auth),
|
||||
x_active_club_id: Optional[str] = Header(default=None, alias="X-Active-Club-Id"),
|
||||
):
|
||||
"""Profil inkl. Vereinsmitgliedschaften; effective_club_id = aufgelöster Request-Kontext (Header vor Profilfeld)."""
|
||||
profile_id = session["profile_id"]
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
cur.execute("SELECT * FROM profiles WHERE id=%s", (profile_id,))
|
||||
@@ -45,7 +49,20 @@ def get_current_profile(session=Depends(require_auth)):
|
||||
raise HTTPException(404, "Profil nicht gefunden")
|
||||
data = r2d(row)
|
||||
data.pop("pin_hash", None)
|
||||
data["clubs"] = memberships_with_roles(cur, profile_id)
|
||||
clubs = memberships_with_roles(cur, profile_id)
|
||||
data["clubs"] = clubs
|
||||
ac_raw = data.get("active_club_id")
|
||||
stored_ac = int(ac_raw) if ac_raw is not None and ac_raw != "" else None
|
||||
tenant = resolve_tenant_context(
|
||||
cur,
|
||||
profile_id=int(profile_id),
|
||||
global_role=session.get("role") or "",
|
||||
header_raw=x_active_club_id,
|
||||
memberships=clubs,
|
||||
stored_active_club_id=stored_ac,
|
||||
invalid_header_policy="ignore",
|
||||
)
|
||||
data["effective_club_id"] = tenant.effective_club_id
|
||||
return data
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user