fix: super admins bypass AI build quota limits
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -80,6 +80,7 @@ async def get_quota(
|
|||||||
account_id=current_user.account_id,
|
account_id=current_user.account_id,
|
||||||
db=db,
|
db=db,
|
||||||
billing_anchor=current_user.ai_billing_cycle_anchor_at,
|
billing_anchor=current_user.ai_billing_cycle_anchor_at,
|
||||||
|
is_super_admin=current_user.is_super_admin,
|
||||||
)
|
)
|
||||||
return AIQuotaStatusResponse(
|
return AIQuotaStatusResponse(
|
||||||
**quota_status,
|
**quota_status,
|
||||||
@@ -99,12 +100,13 @@ async def start_conversation(
|
|||||||
"""Stage 1: Create a new AI wizard conversation with foundation metadata."""
|
"""Stage 1: Create a new AI wizard conversation with foundation metadata."""
|
||||||
_require_ai_enabled()
|
_require_ai_enabled()
|
||||||
|
|
||||||
# Check daily quota (anti-abuse)
|
# Check daily quota (anti-abuse) — super admins bypass
|
||||||
allowed, quota_status = await check_ai_quota(
|
allowed, quota_status = await check_ai_quota(
|
||||||
user_id=current_user.id,
|
user_id=current_user.id,
|
||||||
account_id=current_user.account_id,
|
account_id=current_user.account_id,
|
||||||
db=db,
|
db=db,
|
||||||
billing_anchor=current_user.ai_billing_cycle_anchor_at,
|
billing_anchor=current_user.ai_billing_cycle_anchor_at,
|
||||||
|
is_super_admin=current_user.is_super_admin,
|
||||||
)
|
)
|
||||||
if not allowed:
|
if not allowed:
|
||||||
reset_key = (
|
reset_key = (
|
||||||
|
|||||||
@@ -85,12 +85,14 @@ async def check_ai_quota(
|
|||||||
account_id: UUID,
|
account_id: UUID,
|
||||||
db: AsyncSession,
|
db: AsyncSession,
|
||||||
billing_anchor: Optional[datetime] = None,
|
billing_anchor: Optional[datetime] = None,
|
||||||
|
is_super_admin: bool = False,
|
||||||
) -> tuple[bool, dict]:
|
) -> tuple[bool, dict]:
|
||||||
"""Check if user can make an AI generation.
|
"""Check if user can make an AI generation.
|
||||||
|
|
||||||
Returns (allowed, quota_status_dict).
|
Returns (allowed, quota_status_dict).
|
||||||
Monthly counts only rows with counts_toward_quota=True.
|
Monthly counts only rows with counts_toward_quota=True.
|
||||||
Daily counts only rows with generation_type in ('scaffold', 'branch_detail').
|
Daily counts only rows with generation_type in ('scaffold', 'branch_detail').
|
||||||
|
Super admins bypass all limits.
|
||||||
"""
|
"""
|
||||||
plan = await get_user_plan(account_id, db)
|
plan = await get_user_plan(account_id, db)
|
||||||
monthly_limit, daily_limit = await _get_effective_limits(account_id, plan, db)
|
monthly_limit, daily_limit = await _get_effective_limits(account_id, plan, db)
|
||||||
@@ -120,6 +122,10 @@ async def check_ai_quota(
|
|||||||
|
|
||||||
allowed = True
|
allowed = True
|
||||||
deny_reason = None
|
deny_reason = None
|
||||||
|
if is_super_admin:
|
||||||
|
# Super admins bypass all limits
|
||||||
|
monthly_limit = None
|
||||||
|
daily_limit = None
|
||||||
if monthly_limit is not None and monthly_count >= monthly_limit:
|
if monthly_limit is not None and monthly_count >= monthly_limit:
|
||||||
allowed = False
|
allowed = False
|
||||||
deny_reason = "monthly"
|
deny_reason = "monthly"
|
||||||
|
|||||||
Reference in New Issue
Block a user