mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-02 20:32:39 +02:00
Epic 5 Complete: Billing, Subscriptions, and Admin Features
Resolve all 5 deferred items from Epic 5 adversarial code review: - Migration 124: Add CASCADE to subscriptionstatus enum drop (prevent orphaned references) - Stripe rate limiting: In-memory per-user limiter (20 calls/60s) on verify-checkout-session - Subscription request cooldown: 24h cooldown before resubmitting rejected requests - Token reset date: Initialize on first subscription activation - Checkout URL validation: Confirmed HTTPS-only (Stripe always returns HTTPS) Implement Story 5.4 (Usage Tracking & Rate Limit Enforcement): - Page quota pre-check at HTTP upload layer - Extend UserRead schema with token quota fields - Frontend 402 error handling in document upload - Quota indicator in dashboard sidebar Story 5.5 (Admin Seed & Approval Flow): - Seed admin user migration with default credentials warning - Subscription approval/rejection routes with admin guard - 24h rejection cooldown enforcement Story 5.6 (Admin-Only Model Config): - Global model config visible across all search spaces - Per-search-space model configs with user access control - Superuser CRUD for global configs Additional fixes from code review: - PageLimitService: PAST_DUE subscriptions enforce free-tier limits - TokenQuotaService: PAST_DUE subscriptions enforce free-tier limits - Config routes: Fixed user_id.is_(None) filter on mutation endpoints - Stripe webhook: Added guard against silent plan downgrade on unrecognized price_id All changes formatted with Ruff (Python) and Biome (TypeScript). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
20c4f128bb
commit
4eb6ed18d6
41 changed files with 1771 additions and 318 deletions
|
|
@ -73,6 +73,24 @@ async def create_documents(
|
|||
"You don't have permission to create documents in this search space",
|
||||
)
|
||||
|
||||
# Page quota pre-check for connector documents
|
||||
from app.services.page_limit_service import (
|
||||
PageLimitExceededError,
|
||||
PageLimitService,
|
||||
)
|
||||
|
||||
estimated_pages = len(request.content) # 1 page per document/URL
|
||||
try:
|
||||
page_service = PageLimitService(session)
|
||||
await page_service.check_page_limit(str(user.id), estimated_pages)
|
||||
except PageLimitExceededError as e:
|
||||
raise HTTPException(
|
||||
status_code=402,
|
||||
detail=f"Page quota exceeded ({e.pages_used}/{e.pages_limit}). "
|
||||
f"This request requires ~{estimated_pages} pages. "
|
||||
f"Upgrade your plan for more pages.",
|
||||
) from e
|
||||
|
||||
if request.document_type == DocumentType.EXTENSION:
|
||||
from app.tasks.celery_tasks.document_tasks import (
|
||||
process_extension_document_task,
|
||||
|
|
@ -169,6 +187,30 @@ async def create_documents_file_upload(
|
|||
f"exceeds the {MAX_FILE_SIZE_BYTES // (1024 * 1024)} MB per-file limit.",
|
||||
)
|
||||
|
||||
# Page quota pre-check
|
||||
from app.services.page_limit_service import (
|
||||
PageLimitExceededError,
|
||||
PageLimitService,
|
||||
)
|
||||
|
||||
total_estimated_pages = sum(
|
||||
PageLimitService.estimate_pages_from_metadata(
|
||||
file.filename or "", file.size or 0
|
||||
)
|
||||
for file in files
|
||||
)
|
||||
|
||||
try:
|
||||
page_service = PageLimitService(session)
|
||||
await page_service.check_page_limit(str(user.id), total_estimated_pages)
|
||||
except PageLimitExceededError as e:
|
||||
raise HTTPException(
|
||||
status_code=402,
|
||||
detail=f"Page quota exceeded ({e.pages_used}/{e.pages_limit}). "
|
||||
f"This upload requires ~{total_estimated_pages} pages. "
|
||||
f"Upgrade your plan for more pages.",
|
||||
) from e
|
||||
|
||||
# ===== Read all files concurrently to avoid blocking the event loop =====
|
||||
async def _read_and_save(file: UploadFile) -> tuple[str, str, int]:
|
||||
"""Read upload content and write to temp file off the event loop."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue