Complete Non-Conformance Report system replacing the PowerApps/SharePoint prototype: FastAPI + SQLAlchemy 2 (async) + Alembic + MySQL 8 backend, React 18 + Vite + TypeScript + MUI frontend, Entra ID auth (MSAL / JWKS, group-gated), Microsoft Graph delegated Mail.Send notifications (OBO), six-stage workflow state machine with server-side enforcement, atomic NCR-YYYY-NNNN numbering, attachments with camera capture, immutable field-level audit trail, admin reopen, reports + CSV export, WeasyPrint PDF traveler, Power BI reporting views + read-only DB user, documented VISUAL ERP job-lookup stub, pytest suite (26 tests), docker-compose deployment. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
from datetime import datetime
|
|
|
|
from sqlalchemy import Boolean, DateTime, ForeignKey, String
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.models.base import Base, utcnow
|
|
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
# Entra object id; null for dev-mode/seeded users.
|
|
entra_oid: Mapped[str | None] = mapped_column(String(64), unique=True, nullable=True)
|
|
email: Mapped[str] = mapped_column(String(255), unique=True, index=True)
|
|
display_name: Mapped[str] = mapped_column(String(255))
|
|
employee_id: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
|
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=utcnow)
|
|
last_login_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
|
|
|
role_rows: Mapped[list["UserRole"]] = relationship(
|
|
back_populates="user", cascade="all, delete-orphan", lazy="selectin"
|
|
)
|
|
|
|
@property
|
|
def roles(self) -> list[str]:
|
|
return sorted(r.role for r in self.role_rows)
|
|
|
|
|
|
class UserRole(Base):
|
|
__tablename__ = "user_roles"
|
|
|
|
user_id: Mapped[int] = mapped_column(
|
|
ForeignKey("users.id", ondelete="CASCADE"), primary_key=True
|
|
)
|
|
role: Mapped[str] = mapped_column(String(40), primary_key=True)
|
|
|
|
user: Mapped[User] = relationship(back_populates="role_rows")
|