Neue Stammdaten-Tabelle einsatzfunktion (Migration 0031), benutzer bekommt optionales einsatzfunktion_id-Feld - analog zu einheit_id modelliert, eine Person hat im Regelfall genau eine primäre Einsatzfunktion. Bewusst getrennt von den technischen App-Rollen (RolleTyp), die nur steuern, was jemand in MABEA tun darf, nicht welche Funktion er im Einsatz hat. CRUD-Endpunkt /einsatzfunktionen nach Kategorie-Muster, Duplikat-Prüfung vorab (Projekt-Konvention). Admin-UI: Auswahl + Inline-Neuanlage in der Benutzerverwaltung (BenutzerSection). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CVgbozhYmuEhiEJHffRXCV
65 lines
2.5 KiB
Python
65 lines
2.5 KiB
Python
import enum
|
|
|
|
from sqlalchemy import Boolean, ForeignKey, String
|
|
from sqlalchemy.dialects.postgresql import ENUM as PgEnum
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.db.base import Base
|
|
|
|
|
|
class KnotenTyp(str, enum.Enum):
|
|
haupt = "haupt"
|
|
satellit = "satellit"
|
|
|
|
|
|
class RolleTyp(str, enum.Enum):
|
|
mitarbeiter = "mitarbeiter"
|
|
materialverantwortlicher = "materialverantwortlicher"
|
|
leitungsverantwortlicher = "leitungsverantwortlicher"
|
|
administration = "administration"
|
|
|
|
|
|
# create_type=False: die PostgreSQL-ENUM-Typen werden ausschließlich per Alembic-Migration
|
|
# angelegt (0001_initial_schema), damit Migration und ORM-Modell nicht auseinanderlaufen.
|
|
knoten_typ_pg = PgEnum(KnotenTyp, name="knoten_typ", create_type=False)
|
|
rolle_typ_pg = PgEnum(RolleTyp, name="rolle_typ", create_type=False)
|
|
|
|
|
|
class Systemknoten(Base):
|
|
"""Hauptserver oder Satellit (Karte 13). V1 nutzt ausschließlich den Hauptserver-Datensatz."""
|
|
|
|
__tablename__ = "systemknoten"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
name: Mapped[str] = mapped_column(String, unique=True, nullable=False)
|
|
typ: Mapped[KnotenTyp] = mapped_column(knoten_typ_pg, nullable=False, default=KnotenTyp.satellit)
|
|
|
|
|
|
class Benutzer(Base):
|
|
__tablename__ = "benutzer"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
name: Mapped[str] = mapped_column(String, nullable=False)
|
|
login: Mapped[str] = mapped_column(String, unique=True, nullable=False)
|
|
passwort_hash: Mapped[str] = mapped_column(String, nullable=False)
|
|
aktiv: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)
|
|
email: Mapped[str | None] = mapped_column(String) # Sprint 6 / Karte 05 (Migration 0003)
|
|
einheit_id: Mapped[int | None] = mapped_column(ForeignKey("einheit.id")) # Personal-Modul (Migration 0012)
|
|
# PERS-004: primäre Funktion im Einsatzkontext, optional.
|
|
einsatzfunktion_id: Mapped[int | None] = mapped_column(ForeignKey("einsatzfunktion.id"))
|
|
|
|
rollen: Mapped[list["BenutzerRolle"]] = relationship(back_populates="benutzer", lazy="selectin")
|
|
|
|
@property
|
|
def rollen_namen(self) -> list[str]:
|
|
return [r.rolle.value for r in self.rollen]
|
|
|
|
|
|
class BenutzerRolle(Base):
|
|
__tablename__ = "benutzer_rolle"
|
|
|
|
benutzer_id: Mapped[int] = mapped_column(ForeignKey("benutzer.id"), primary_key=True)
|
|
rolle: Mapped[RolleTyp] = mapped_column(rolle_typ_pg, primary_key=True)
|
|
|
|
benutzer: Mapped["Benutzer"] = relationship(back_populates="rollen")
|