Files
voidea/app/models/user.py
T

64 lines
1.9 KiB
Python

"""User model for VoIdea."""
from datetime import datetime
from typing import Any, Optional
from sqlalchemy import Boolean, DateTime, String
from sqlalchemy.dialects.postgresql import JSONB, UUID
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.core.base import SQLBase, TimestampMixin, UUIDMixin
class User(SQLBase, UUIDMixin, TimestampMixin):
__tablename__ = "users"
email: Mapped[str] = mapped_column(
String(255), unique=True, index=True, nullable=False
)
password_hash: Mapped[Optional[str]] = mapped_column(
String(255), nullable=True
)
display_name: Mapped[str] = mapped_column(
String(255), nullable=False
)
avatar_url: Mapped[Optional[str]] = mapped_column(
String(512), nullable=True
)
is_active: Mapped[bool] = mapped_column(
Boolean, default=True, nullable=False
)
is_superuser: Mapped[bool] = mapped_column(
Boolean, default=False, nullable=False
)
# v2.0 role system
role: Mapped[str] = mapped_column(
String(20), default="user", nullable=False, index=True
)
is_owner: Mapped[bool] = mapped_column(
Boolean, default=False, nullable=False
)
permissions: Mapped[Optional[dict[str, Any]]] = mapped_column(
JSONB, nullable=True, default=None
)
accepted_terms_at: Mapped[Optional[datetime]] = mapped_column(
nullable=True
)
accepted_terms_version: Mapped[Optional[str]] = mapped_column(
String(20), nullable=True
)
pipeline_tuning: Mapped[Optional[dict[str, Any]]] = mapped_column(
JSONB, nullable=True, default=None
)
oauth_provider: Mapped[Optional[str]] = mapped_column(
String(50), nullable=True
)
oauth_id: Mapped[Optional[str]] = mapped_column(
String(255), nullable=True
)
ideas = relationship("Idea", back_populates="user", lazy="selectin")