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
@@ -37,6 +37,8 @@ from media_rights import assert_rights_for_exercise_link, validate_rights_declar
|
||||
from media_legal_hold import assert_not_under_legal_hold
|
||||
from ai_prompt_context import ExerciseFormAiFocusRow, ExerciseFormAiPromptContext
|
||||
from ai_prompt_job import run_exercise_form_ai_suggestion
|
||||
from account_lifecycle import assert_min_account_state
|
||||
from capabilities import probe_capability
|
||||
from club_features import probe_club_feature_access, resolve_club_id_for_probe
|
||||
|
||||
from exercise_rich_text import (
|
||||
@@ -2318,6 +2320,14 @@ def exercise_ai_suggest_endpoint(
|
||||
KI-Vorschlaege (Kurzfassung und/oder Skill-Zuordnung) ohne Speichern.
|
||||
OPENROUTER_API_KEY erforderlich.
|
||||
"""
|
||||
assert_min_account_state(tenant, "active_member", endpoint="POST /exercises/ai/suggest")
|
||||
probe_capability(
|
||||
tenant,
|
||||
"exercises.ai.suggest",
|
||||
action="suggest",
|
||||
club_id=resolve_club_id_for_probe(tenant),
|
||||
endpoint="POST /exercises/ai/suggest",
|
||||
)
|
||||
probe_club_feature_access(
|
||||
feature_id="ai_calls",
|
||||
action="suggest",
|
||||
@@ -2344,6 +2354,14 @@ def exercise_ai_regenerate_endpoint(
|
||||
tenant: TenantContext = Depends(get_tenant_context),
|
||||
):
|
||||
"""Neu-Anfrage KI fuer eine gespeicherte Uebung; schreibendes Ergebnis nur im Frontend (PUT)."""
|
||||
assert_min_account_state(tenant, "active_member", endpoint="POST /exercises/{id}/ai/regenerate")
|
||||
probe_capability(
|
||||
tenant,
|
||||
"exercises.ai.regenerate",
|
||||
action="regenerate",
|
||||
club_id=resolve_club_id_for_probe(tenant),
|
||||
endpoint="POST /exercises/{id}/ai/regenerate",
|
||||
)
|
||||
probe_club_feature_access(
|
||||
feature_id="ai_calls",
|
||||
action="regenerate",
|
||||
@@ -2436,6 +2454,14 @@ def create_exercise(
|
||||
club_id = tenant.effective_club_id
|
||||
|
||||
if club_id is not None:
|
||||
assert_min_account_state(tenant, "active_member", endpoint="POST /exercises")
|
||||
probe_capability(
|
||||
tenant,
|
||||
"exercises.create",
|
||||
action="create",
|
||||
club_id=int(club_id),
|
||||
endpoint="POST /exercises",
|
||||
)
|
||||
probe_club_feature_access(
|
||||
feature_id="exercises",
|
||||
action="create",
|
||||
@@ -3245,6 +3271,15 @@ async def upload_exercise_media(
|
||||
ex_club = cur.fetchone()
|
||||
media_club_id = ex_club.get("club_id") if ex_club else None
|
||||
if media_club_id is not None:
|
||||
assert_min_account_state(tenant, "active_member", endpoint="POST /exercises/{id}/media")
|
||||
probe_capability(
|
||||
tenant,
|
||||
"exercises.media.upload",
|
||||
action="upload",
|
||||
club_id=int(media_club_id),
|
||||
endpoint="POST /exercises/{id}/media",
|
||||
conn=conn,
|
||||
)
|
||||
probe_club_feature_access(
|
||||
feature_id="exercise_media",
|
||||
action="upload",
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
"""
|
||||
GET /api/me/entitlements — effektive Capabilities + Feature-Kontingente (M4).
|
||||
"""
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
|
||||
from db import get_db, get_cursor
|
||||
from entitlements import build_me_entitlements
|
||||
from tenant_context import TenantContext, get_tenant_context
|
||||
|
||||
router = APIRouter(prefix="/api", tags=["entitlements"])
|
||||
|
||||
|
||||
@router.get("/me/entitlements")
|
||||
def get_me_entitlements(
|
||||
tenant: TenantContext = Depends(get_tenant_context),
|
||||
club_id: Optional[int] = Query(default=None, ge=1, description="Verein (Default: effective_club_id)"),
|
||||
):
|
||||
"""
|
||||
Effektive Rechte für Frontend: Account-Status, Capabilities, Feature-Limits.
|
||||
|
||||
Spez: CAPABILITY_CATALOG.v1.md §7.1
|
||||
"""
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
return build_me_entitlements(cur, tenant, club_id=club_id)
|
||||
@@ -7,6 +7,8 @@ from db import get_db, get_cursor
|
||||
from tenant_context import TenantContext, get_tenant_context
|
||||
from planning_exercise_suggest import PlanningExerciseSuggestRequest, suggest_planning_exercises
|
||||
from planning_exercise_path_builder import ProgressionPathSuggestRequest, suggest_progression_path
|
||||
from account_lifecycle import assert_min_account_state
|
||||
from capabilities import probe_capability
|
||||
from club_features import probe_club_feature_access, resolve_club_id_for_probe
|
||||
|
||||
router = APIRouter(prefix="/api/planning", tags=["planning_exercise_suggest"])
|
||||
@@ -18,6 +20,14 @@ def post_planning_exercise_suggest(
|
||||
tenant: TenantContext = Depends(get_tenant_context),
|
||||
):
|
||||
if body.include_llm_intent or body.include_llm_rank:
|
||||
assert_min_account_state(tenant, "active_member", endpoint="POST /planning/exercise-suggest")
|
||||
probe_capability(
|
||||
tenant,
|
||||
"planning.ai.suggest",
|
||||
action="planning_suggest",
|
||||
club_id=resolve_club_id_for_probe(tenant),
|
||||
endpoint="POST /planning/exercise-suggest",
|
||||
)
|
||||
probe_club_feature_access(
|
||||
feature_id="ai_calls",
|
||||
action="planning_suggest",
|
||||
@@ -40,6 +50,16 @@ def post_progression_path_suggest(
|
||||
or body.include_llm_path_qa
|
||||
or body.include_ai_gap_fill
|
||||
):
|
||||
assert_min_account_state(
|
||||
tenant, "active_member", endpoint="POST /planning/progression-path-suggest"
|
||||
)
|
||||
probe_capability(
|
||||
tenant,
|
||||
"planning.ai.progression_path",
|
||||
action="progression_path_suggest",
|
||||
club_id=resolve_club_id_for_probe(tenant),
|
||||
endpoint="POST /planning/progression-path-suggest",
|
||||
)
|
||||
probe_club_feature_access(
|
||||
feature_id="ai_calls",
|
||||
action="progression_path_suggest",
|
||||
|
||||
@@ -22,6 +22,7 @@ from club_tenancy import (
|
||||
is_superadmin,
|
||||
memberships_with_roles,
|
||||
)
|
||||
from capabilities import club_roles_in_club
|
||||
from tenant_context import resolve_tenant_context, TenantContext, get_tenant_context
|
||||
from models import ProfileCreate, ProfileUpdate
|
||||
|
||||
@@ -118,6 +119,11 @@ def get_current_profile(
|
||||
invalid_header_policy="ignore",
|
||||
)
|
||||
data["effective_club_id"] = tenant.effective_club_id
|
||||
data["account_state"] = tenant.account_state
|
||||
if tenant.effective_club_id is not None:
|
||||
data["club_roles"] = club_roles_in_club(tenant, tenant.effective_club_id)
|
||||
else:
|
||||
data["club_roles"] = []
|
||||
return data
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user