Implement Club Feature Access Probing and Inventory Count
Deploy Development / deploy (push) Successful in 41s
Test Suite / pytest-backend (push) Successful in 40s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Successful in 1m42s
Deploy Development / deploy (push) Successful in 41s
Test Suite / pytest-backend (push) Successful in 40s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Successful in 1m42s
- Introduced `probe_club_feature_access` to check club feature limits and log access attempts without blocking by default. - Added `_live_inventory_count` function to retrieve current counts for specific features, enhancing feature limit management. - Updated various endpoints to utilize the new probing functionality, ensuring compliance with club feature access rules. - Incremented version to 1.1.0 in version.py to reflect these enhancements in club feature management.
This commit is contained in:
1 parent
c294c27de8
commit
7cfbca40bb
6 files changed
+344
-4
No files matched your search
@@ -37,6 +37,7 @@ 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 club_features import probe_club_feature_access, resolve_club_id_for_probe
|
||||
|
||||
from exercise_rich_text import (
|
||||
RICH_HTML_EXERCISE_FIELDS,
|
||||
@@ -2317,7 +2318,13 @@ def exercise_ai_suggest_endpoint(
|
||||
KI-Vorschlaege (Kurzfassung und/oder Skill-Zuordnung) ohne Speichern.
|
||||
OPENROUTER_API_KEY erforderlich.
|
||||
"""
|
||||
_ = tenant.profile_id
|
||||
probe_club_feature_access(
|
||||
feature_id="ai_calls",
|
||||
action="suggest",
|
||||
club_id=resolve_club_id_for_probe(tenant),
|
||||
profile_id=tenant.profile_id,
|
||||
endpoint="POST /exercises/ai/suggest",
|
||||
)
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
payload = run_exercise_form_ai_suggestion(
|
||||
@@ -2337,6 +2344,13 @@ def exercise_ai_regenerate_endpoint(
|
||||
tenant: TenantContext = Depends(get_tenant_context),
|
||||
):
|
||||
"""Neu-Anfrage KI fuer eine gespeicherte Uebung; schreibendes Ergebnis nur im Frontend (PUT)."""
|
||||
probe_club_feature_access(
|
||||
feature_id="ai_calls",
|
||||
action="regenerate",
|
||||
club_id=resolve_club_id_for_probe(tenant),
|
||||
profile_id=tenant.profile_id,
|
||||
endpoint="POST /exercises/{id}/ai/regenerate",
|
||||
)
|
||||
want_summary = "summary" in body.regenerate
|
||||
want_skills = "skills" in body.regenerate
|
||||
want_instructions = "instructions" in body.regenerate
|
||||
@@ -2421,6 +2435,15 @@ def create_exercise(
|
||||
if body.visibility == "club" and club_id is None:
|
||||
club_id = tenant.effective_club_id
|
||||
|
||||
if club_id is not None:
|
||||
probe_club_feature_access(
|
||||
feature_id="exercises",
|
||||
action="create",
|
||||
club_id=int(club_id),
|
||||
profile_id=profile_id,
|
||||
endpoint="POST /exercises",
|
||||
)
|
||||
|
||||
# §11 Inline-Medien: Kurzsyntax → kanonisches Markup; Verweise erst nach Medien-Anlage möglich
|
||||
create_ids: set[int] = set()
|
||||
for fld in sorted(RICH_HTML_EXERCISE_FIELDS):
|
||||
@@ -3214,6 +3237,23 @@ async def upload_exercise_media(
|
||||
cur = get_cursor(conn)
|
||||
_assert_can_edit_exercise(cur, exercise_id, tenant)
|
||||
|
||||
if has_file:
|
||||
cur.execute(
|
||||
"SELECT club_id FROM exercises WHERE id = %s",
|
||||
(exercise_id,),
|
||||
)
|
||||
ex_club = cur.fetchone()
|
||||
media_club_id = ex_club.get("club_id") if ex_club else None
|
||||
if media_club_id is not None:
|
||||
probe_club_feature_access(
|
||||
feature_id="exercise_media",
|
||||
action="upload",
|
||||
club_id=int(media_club_id),
|
||||
profile_id=profile_id,
|
||||
endpoint="POST /exercises/{id}/media",
|
||||
conn=conn,
|
||||
)
|
||||
|
||||
if _count_exercise_media(cur, exercise_id) >= MAX_EXERCISE_MEDIA:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
|
||||
@@ -7,6 +7,7 @@ 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 club_features import probe_club_feature_access, resolve_club_id_for_probe
|
||||
|
||||
router = APIRouter(prefix="/api/planning", tags=["planning_exercise_suggest"])
|
||||
|
||||
@@ -16,6 +17,14 @@ def post_planning_exercise_suggest(
|
||||
body: PlanningExerciseSuggestRequest,
|
||||
tenant: TenantContext = Depends(get_tenant_context),
|
||||
):
|
||||
if body.include_llm_intent or body.include_llm_rank:
|
||||
probe_club_feature_access(
|
||||
feature_id="ai_calls",
|
||||
action="planning_suggest",
|
||||
club_id=resolve_club_id_for_probe(tenant),
|
||||
profile_id=tenant.profile_id,
|
||||
endpoint="POST /planning/exercise-suggest",
|
||||
)
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
return suggest_planning_exercises(cur, tenant=tenant, body=body)
|
||||
@@ -26,6 +35,18 @@ def post_progression_path_suggest(
|
||||
body: ProgressionPathSuggestRequest,
|
||||
tenant: TenantContext = Depends(get_tenant_context),
|
||||
):
|
||||
if (
|
||||
body.include_llm_intent
|
||||
or body.include_llm_path_qa
|
||||
or body.include_ai_gap_fill
|
||||
):
|
||||
probe_club_feature_access(
|
||||
feature_id="ai_calls",
|
||||
action="progression_path_suggest",
|
||||
club_id=resolve_club_id_for_probe(tenant),
|
||||
profile_id=tenant.profile_id,
|
||||
endpoint="POST /planning/progression-path-suggest",
|
||||
)
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
return suggest_progression_path(cur, tenant=tenant, body=body)
|
||||
Reference in new issue
Block a user