Enhance Tenant Context and Access Control Features
Deploy Development / deploy (push) Successful in 43s
Test Suite / pytest-backend (push) Failing after 0s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 14s
Test Suite / k6 /health Baseline (push) Failing after 4m0s
Test Suite / playwright-tests (push) Failing after 3m41s
Deploy Development / deploy (push) Successful in 43s
Test Suite / pytest-backend (push) Failing after 0s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 14s
Test Suite / k6 /health Baseline (push) Failing after 4m0s
Test Suite / playwright-tests (push) Failing after 3m41s
- Introduced `email_verified` and `account_state` attributes in the `TenantContext` to improve user state management. - Updated the `resolve_tenant_context` function to dynamically fetch `email_verified` status from the database and determine `account_state` based on user roles and memberships. - Implemented `assert_min_account_state` checks across various endpoints to enforce access control based on user account status. - Incremented version to 1.1.0 in version.py to reflect these enhancements in tenant context management and access control.
This commit is contained in:
1 parent
7cfbca40bb
commit
30dc30c7aa
21 files changed
+1124
-22
No files matched your search
@@ -12,6 +12,7 @@ from typing import Any, Dict, List, Optional
|
||||
from fastapi import Depends, Header, HTTPException
|
||||
|
||||
from auth import require_auth, require_auth_flexible
|
||||
from account_lifecycle import resolve_account_state
|
||||
from club_tenancy import is_platform_admin, memberships_with_roles
|
||||
from db import get_db, get_cursor
|
||||
|
||||
@@ -142,6 +143,8 @@ class TenantContext:
|
||||
effective_club_id: Optional[int]
|
||||
club_ids: frozenset[int]
|
||||
memberships: List[Dict[str, Any]]
|
||||
email_verified: bool = True
|
||||
account_state: str = "active_member"
|
||||
|
||||
|
||||
def resolve_tenant_context(
|
||||
@@ -153,6 +156,7 @@ def resolve_tenant_context(
|
||||
memberships: Optional[List[Dict[str, Any]]] = None,
|
||||
stored_active_club_id: Optional[int] = None,
|
||||
invalid_header_policy: str = "reject",
|
||||
email_verified: Optional[bool] = None,
|
||||
) -> TenantContext:
|
||||
"""
|
||||
Mitgliedschaften: wenn nicht übergeben, lädt ``active_only=True`` aus der DB.
|
||||
@@ -176,6 +180,21 @@ def resolve_tenant_context(
|
||||
|
||||
club_ids = frozenset(int(r["id"]) for r in membership_rows if r.get("id") is not None)
|
||||
|
||||
if email_verified is None:
|
||||
cur.execute(
|
||||
"SELECT COALESCE(email_verified, false) AS email_verified FROM profiles WHERE id = %s",
|
||||
(profile_id,),
|
||||
)
|
||||
prof_row = cur.fetchone()
|
||||
email_verified = bool(prof_row.get("email_verified")) if prof_row else False
|
||||
else:
|
||||
email_verified = bool(email_verified)
|
||||
account_state = resolve_account_state(
|
||||
email_verified=email_verified,
|
||||
global_role=role_lc,
|
||||
has_active_membership=len(club_ids) > 0,
|
||||
)
|
||||
|
||||
if is_platform_admin(role_lc):
|
||||
if header_cid is not None:
|
||||
if not _club_exists(cur, header_cid):
|
||||
@@ -194,6 +213,8 @@ def resolve_tenant_context(
|
||||
effective_club_id=effective,
|
||||
club_ids=club_ids,
|
||||
memberships=membership_rows,
|
||||
email_verified=email_verified,
|
||||
account_state=account_state,
|
||||
)
|
||||
|
||||
chosen_header = header_cid
|
||||
@@ -222,6 +243,8 @@ def resolve_tenant_context(
|
||||
effective_club_id=effective,
|
||||
club_ids=club_ids,
|
||||
memberships=membership_rows,
|
||||
email_verified=email_verified,
|
||||
account_state=account_state,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user