mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-29 19:35:20 +02:00
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>
78 lines
2.3 KiB
Python
78 lines
2.3 KiB
Python
import uuid
|
|
from datetime import datetime
|
|
from typing import Any
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field
|
|
|
|
from app.db import VisionProvider
|
|
|
|
|
|
class VisionLLMConfigBase(BaseModel):
|
|
name: str = Field(..., max_length=100)
|
|
description: str | None = Field(None, max_length=500)
|
|
provider: VisionProvider = Field(...)
|
|
custom_provider: str | None = Field(None, max_length=100)
|
|
model_name: str = Field(..., max_length=100)
|
|
api_key: str = Field(...)
|
|
api_base: str | None = Field(None, max_length=500)
|
|
api_version: str | None = Field(None, max_length=50)
|
|
litellm_params: dict[str, Any] | None = Field(default=None)
|
|
|
|
|
|
class VisionLLMConfigCreate(VisionLLMConfigBase):
|
|
search_space_id: int | None = Field(
|
|
None,
|
|
description="Search space ID. None = global admin config visible to all spaces",
|
|
)
|
|
|
|
|
|
class VisionLLMConfigUpdate(BaseModel):
|
|
name: str | None = Field(None, max_length=100)
|
|
description: str | None = Field(None, max_length=500)
|
|
provider: VisionProvider | None = None
|
|
custom_provider: str | None = Field(None, max_length=100)
|
|
model_name: str | None = Field(None, max_length=100)
|
|
api_key: str | None = None
|
|
api_base: str | None = Field(None, max_length=500)
|
|
api_version: str | None = Field(None, max_length=50)
|
|
litellm_params: dict[str, Any] | None = None
|
|
|
|
|
|
class VisionLLMConfigRead(VisionLLMConfigBase):
|
|
id: int
|
|
created_at: datetime
|
|
search_space_id: int | None = None
|
|
user_id: uuid.UUID | None = None
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class VisionLLMConfigPublic(BaseModel):
|
|
id: int
|
|
name: str
|
|
description: str | None = None
|
|
provider: VisionProvider
|
|
custom_provider: str | None = None
|
|
model_name: str
|
|
api_base: str | None = None
|
|
api_version: str | None = None
|
|
litellm_params: dict[str, Any] | None = None
|
|
created_at: datetime
|
|
search_space_id: int | None = None
|
|
user_id: uuid.UUID | None = None
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class GlobalVisionLLMConfigRead(BaseModel):
|
|
id: int = Field(...)
|
|
name: str
|
|
description: str | None = None
|
|
provider: str
|
|
custom_provider: str | None = None
|
|
model_name: str
|
|
api_base: str | None = None
|
|
api_version: str | None = None
|
|
litellm_params: dict[str, Any] | None = None
|
|
is_global: bool = True
|
|
is_auto_mode: bool = False
|