Files
patrickandClaude Sonnet 5 d71d95e17f
CI / backend-tests (push) Failing after 1m32s
CI / frontend-build (push) Successful in 17s
feat(personal): Personal/Qualifikationen-Modul (Roadmap Phase 1)
Neues Modul für die BOS-Ressourcenplattform-Erweiterung: Einheit (Zug/Gruppe,
self-referenzierend), Qualifikationstyp (Führerschein/Lehrgang/Berechtigung),
BenutzerQualifikation (mit Gültigkeit) und ObjekttypQualifikationsanforderung
(M:N) - beantwortet "wer darf dieses Fahrzeug fahren?" über
GET /objekte/{id}/berechtigung/{benutzer_id}.

Benutzer und Objekt bekommen optionale einheit_id (additiv, analog
fahrzeug_id-Muster). Nebenbei Bugfix: PATCH /benutzer konnte einheit_id nicht
auf null setzen (Feld-vorhanden-Check via model_fields_set statt is not None).

Frontend: neuer Admin-Tab "Personal" (Einheiten, Qualifikationstypen,
Benutzer-Qualifikationszuordnung), Einheit-Auswahl im Benutzer-Formular.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KC8HYvv6UkCVYheYiTw9DD
2026-09-05 11:13:37 +02:00

63 lines
2.3 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)
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")