Spaces:
Paused
Paused
Download schemas/user.py from TeamError404/nexus: direct link, hf CLI and curl.
- Browser
- Download file 1.95 kB
-
https://huggingface.co/spaces/TeamError404/nexus/resolve/main/schemas/user.py
- Command line
-
hf download hf://spaces/TeamError404/nexus/schemas/user.py
-
curl -L -o user.py https://huggingface.co/spaces/TeamError404/nexus/resolve/main/schemas/user.py
1.95 kB
| """ | |
| Pydantic schemas for user profiles and user management. | |
| """ | |
| from typing import Optional | |
| from uuid import UUID | |
| from datetime import datetime | |
| from pydantic import BaseModel, EmailStr, ConfigDict, field_validator | |
| import re | |
| from models.user import UserRole | |
| class UserBase(BaseModel): | |
| email: EmailStr | |
| full_name: str | |
| role: UserRole | |
| is_active: bool | |
| avatar_url: Optional[str] = None | |
| class UserCreate(BaseModel): | |
| """Schema for admins to invite/create users.""" | |
| email: EmailStr | |
| full_name: str | |
| password: str | |
| role: UserRole | |
| def validate_password_complexity(cls, v: str) -> str: | |
| if len(v) < 8: | |
| raise ValueError("Password must be at least 8 characters long.") | |
| if not re.search(r"[0-9!@#$%^&*(),.?\":{}|<>]", v): | |
| raise ValueError("Password must contain at least one digit or special character.") | |
| return v | |
| def normalize_role(cls, v: str) -> str: | |
| """ | |
| Normalize roles that might be missing the '3' prefix from older frontend versions | |
| or common display mappings. | |
| """ | |
| if isinstance(v, str): | |
| mapping = { | |
| "sc_agent": "3sc_agent", | |
| "sc_lead": "3sc_lead", | |
| "sc_admin": "3sc_admin" | |
| } | |
| return mapping.get(v.lower(), v) | |
| return v | |
| class UserUpdate(BaseModel): | |
| """Schema for profile updates.""" | |
| full_name: Optional[str] = None | |
| avatar_url: Optional[str] = None | |
| class UserAdminUpdate(BaseModel): | |
| """Schema for admins updating a user.""" | |
| role: Optional[UserRole] = None | |
| is_active: Optional[bool] = None | |
| class UserResponse(UserBase): | |
| """Response schema for returning user data.""" | |
| id: UUID | |
| workspace_id: UUID | |
| created_at: datetime | |
| model_config = ConfigDict(from_attributes=True) | |