- Add viewer role to backend enum + Alembic migration - SSO auto-provisioned users now get viewer (lowest privilege) by default - Wire admin/users page to real API (replace mock data), with add/edit/deactivate - Fix frontend UserRole enum to match backend (TM_MANAGER, REVIEWER) - Replace hardcoded mock user in Sidebar with real auth, filter admin-only nav items, wire logout - Add seed script to set default admins (daveporter, vadymsamoilenko) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
62 lines
2.1 KiB
Python
62 lines
2.1 KiB
Python
import enum
|
|
import uuid
|
|
|
|
from sqlalchemy import Enum, ForeignKey, String
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.models.base import Base, TimestampMixin, generate_uuid
|
|
|
|
|
|
class UserRole(str, enum.Enum):
|
|
admin = "admin"
|
|
tm_manager = "tm_manager"
|
|
reviewer = "reviewer"
|
|
viewer = "viewer"
|
|
|
|
|
|
class UserStatus(str, enum.Enum):
|
|
active = "active"
|
|
inactive = "inactive"
|
|
|
|
|
|
class User(Base, TimestampMixin):
|
|
__tablename__ = "users"
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(
|
|
primary_key=True, default=generate_uuid
|
|
)
|
|
email: Mapped[str] = mapped_column(String(255), unique=True, nullable=False)
|
|
name: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
password_hash: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
|
auth_provider: Mapped[str] = mapped_column(String(50), nullable=False, server_default="local")
|
|
role: Mapped[UserRole] = mapped_column(
|
|
Enum(UserRole, name="user_role", create_constraint=True),
|
|
nullable=False,
|
|
)
|
|
status: Mapped[UserStatus] = mapped_column(
|
|
Enum(UserStatus, name="user_status", create_constraint=True),
|
|
default=UserStatus.active,
|
|
nullable=False,
|
|
)
|
|
|
|
# Relationships
|
|
user_clients = relationship("UserClient", back_populates="user", lazy="selectin")
|
|
jobs_created = relationship("Job", back_populates="creator", lazy="selectin")
|
|
feedback = relationship("Feedback", back_populates="user", lazy="selectin")
|
|
audit_logs = relationship("AuditLog", back_populates="user", lazy="selectin")
|
|
|
|
|
|
class UserClient(Base):
|
|
__tablename__ = "user_clients"
|
|
|
|
user_id: Mapped[uuid.UUID] = mapped_column(
|
|
ForeignKey("users.id", ondelete="CASCADE"), primary_key=True
|
|
)
|
|
client_id: Mapped[uuid.UUID] = mapped_column(
|
|
ForeignKey("clients.id", ondelete="CASCADE"), primary_key=True
|
|
)
|
|
role_override: Mapped[str | None] = mapped_column(String(50), nullable=True)
|
|
|
|
# Relationships
|
|
user = relationship("User", back_populates="user_clients")
|
|
client = relationship("Client", back_populates="user_clients")
|