- B904 (55): add `from err` / `from None` to raise-in-except across 13 files - F821 (1): add missing HTTPException import in routes_language_qc.py - F841 (7): remove unused variable assignments (current_user, job_title, tts_provider, etc.) - W293 (13): strip trailing whitespace from blank lines - C416 (4): rewrite unnecessary dict comprehensions as dict() - C401 (1): rewrite unnecessary generator as set comprehension - E701 (4): split multi-statement lines in cost_tracker.py - E741 (1): rename ambiguous `l` to `lang` in cloud_run_dispatch.py - B007 (4): prefix unused loop variables with _ in tts.py, video_renderer.py - I001 (1): sort imports in tasks/__init__.py (move stdlib to top) - E402 (3): move threading/time/signals imports to top of tasks/__init__.py - UP042 (9): replace (str, Enum) with StrEnum in all model/schema enums Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
70 lines
1.7 KiB
Python
70 lines
1.7 KiB
Python
from datetime import datetime
|
|
from enum import StrEnum
|
|
from typing import Annotated
|
|
|
|
from bson import ObjectId
|
|
from pydantic import BaseModel, BeforeValidator, EmailStr, Field
|
|
|
|
|
|
def validate_object_id(v) -> str:
|
|
"""Convert ObjectId to string"""
|
|
if isinstance(v, ObjectId):
|
|
return str(v)
|
|
if isinstance(v, str):
|
|
return v
|
|
raise ValueError('Invalid ObjectId')
|
|
|
|
|
|
PyObjectId = Annotated[str, BeforeValidator(validate_object_id)]
|
|
|
|
|
|
class UserRole(StrEnum):
|
|
CLIENT = "client"
|
|
REVIEWER = "reviewer"
|
|
LINGUIST = "linguist"
|
|
PRODUCTION = "production"
|
|
PROJECT_MANAGER = "project_manager"
|
|
ADMIN = "admin"
|
|
|
|
|
|
class AuthProvider(StrEnum):
|
|
LOCAL = "local"
|
|
MICROSOFT = "microsoft"
|
|
|
|
|
|
class User(BaseModel):
|
|
id: PyObjectId | None = Field(None, alias="_id")
|
|
email: EmailStr
|
|
hashed_password: str | None = None # Optional for Microsoft users
|
|
full_name: str
|
|
role: UserRole = UserRole.CLIENT
|
|
auth_provider: AuthProvider = AuthProvider.LOCAL
|
|
is_active: bool = True
|
|
pm_client_ids: list[str] = [] # Client IDs where this user is Project Manager (admin-assigned)
|
|
languages: list[str] = [] # BCP-47 language codes the user is competent in (R-8)
|
|
created_at: datetime | None = None
|
|
updated_at: datetime | None = None
|
|
|
|
class Config:
|
|
populate_by_name = True
|
|
use_enum_values = True
|
|
|
|
|
|
class UserInDB(User):
|
|
pass
|
|
|
|
|
|
class UserCreate(BaseModel):
|
|
email: EmailStr
|
|
password: str
|
|
full_name: str
|
|
role: UserRole = UserRole.CLIENT
|
|
|
|
|
|
class UserUpdate(BaseModel):
|
|
email: EmailStr | None = None
|
|
full_name: str | None = None
|
|
role: UserRole | None = None
|
|
is_active: bool | None = None
|
|
pm_client_ids: list[str] | None = None
|
|
languages: list[str] | None = None
|