Core modules: - Laws: CRUD, search, AI-powered QA - Analysis: legal research and case management - Contracts: lifecycle management with templates - Signatures: electronic signature workflow Infrastructure: - FastAPI + SQLite + async SQLAlchemy - Docker deployment support - 54 unit tests passing Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
"""User model for authentication and authorization."""
|
|
import enum
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from sqlalchemy import String, Boolean, DateTime, Enum as SQLEnum
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.core.database import Base
|
|
|
|
|
|
class UserRole(str, enum.Enum):
|
|
"""User role enumeration."""
|
|
ADMIN = "admin"
|
|
LAWYER = "lawyer"
|
|
REVIEWER = "reviewer"
|
|
CLIENT = "client"
|
|
|
|
|
|
class User(Base):
|
|
"""User model for authentication."""
|
|
|
|
__tablename__ = "users"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
username: Mapped[str] = mapped_column(String(50), unique=True, index=True)
|
|
email: Mapped[str] = mapped_column(String(100), unique=True, index=True)
|
|
hashed_password: Mapped[str] = mapped_column(String(255))
|
|
full_name: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
|
|
role: Mapped[UserRole] = mapped_column(
|
|
SQLEnum(UserRole),
|
|
nullable=False
|
|
)
|
|
is_active: Mapped[bool] = mapped_column(Boolean, nullable=False)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime,
|
|
nullable=False
|
|
)
|
|
updated_at: Mapped[datetime] = mapped_column(
|
|
DateTime,
|
|
nullable=False
|
|
)
|
|
|
|
def __init__(
|
|
self,
|
|
username: str,
|
|
email: str,
|
|
hashed_password: str,
|
|
full_name: Optional[str] = None,
|
|
role: UserRole = UserRole.CLIENT,
|
|
is_active: bool = True,
|
|
**kwargs
|
|
):
|
|
self.username = username
|
|
self.email = email
|
|
self.hashed_password = hashed_password
|
|
self.full_name = full_name
|
|
self.role = role
|
|
self.is_active = is_active
|
|
self.created_at = datetime.utcnow()
|
|
self.updated_at = datetime.utcnow()
|
|
|
|
def __repr__(self) -> str:
|
|
return f"<User(id={self.id}, username={self.username}, role={self.role})>"
|