Files
timemaster/backend/app/schemas/user.py
T
patrickandClaude Opus 4.8 c9c197ddae
Security Audit / Python Dependency Audit (push) Has been cancelled
Security Audit / Node.js Dependency Audit (push) Has been cancelled
feat: agent-11 PR2 – Urlaubsanspruch (Verfall scharf, Pro-rata, Teilzeit)
Korrektheit der Urlaubskonten (Feature-Parität mit Urlaubsverwaltung):

- Verfall scharfgeschaltet: neuer effektiv verfügbarer Saldo (available_days)
  schließt verfallenen, noch nicht verbrauchten Resturlaub aus; Konto-Warnung
  beim Antrag nutzt jetzt available statt remaining. (Verfallsdatum bleibt in
  company.settings, UI bereits vorhanden.)
- Anteilige Berechnung (Zwölftel) im Ein-/Austrittsjahr anhand neuer Felder
  users.entry_date / exit_date; opt-in pro Firma (vacation_prorate_first_year).
- Teilzeit: Anspruch optional aus Arbeitstagen/Woche des WorkSchedule abgeleitet
  (vacation_from_schedule), Basis vacation_default_days.
- _get_or_create_balance berechnet den Grundanspruch jetzt frisch
  (_compute_entitlement); _carryover_expired/effective_available als Service-API,
  Router delegiert.

Frontend: CompanySettingsPage (Jahresurlaub + Pro-rata- und Teilzeit-Toggles),
UsersPage (Ein-/Austrittsdatum im Edit-Modal), AbsencesPage ("Verfügbar" + Hinweis
bei verfallenem Resturlaub).

Migration 0036. 183/183 Tests grün. Deployed auf 137 + 164.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 12:03:42 +02:00

118 lines
3.4 KiB
Python

import uuid
from datetime import datetime, date
from pydantic import BaseModel, EmailStr, Field, model_validator
from app.models.user import AuthProvider, UserRole
PERSONNEL_NUMBER_PATTERN = r"^[0-9]+$"
class UserOut(BaseModel):
model_config = {"from_attributes": True}
id: uuid.UUID
company_id: uuid.UUID | None
department_id: uuid.UUID | None
email: str
first_name: str
last_name: str
full_name: str
role: UserRole
auth_provider: AuthProvider
is_active: bool
last_login: datetime | None
created_at: datetime
kuerzel: str | None = None
personnel_number: str | None = None
can_manual_time_entry: bool = False
work_schedule_id: uuid.UUID | None = None
entry_date: date | None = None
exit_date: date | None = None
class UserUpdate(BaseModel):
first_name: str | None = Field(None, min_length=1, max_length=100)
last_name: str | None = Field(None, min_length=1, max_length=100)
department_id: uuid.UUID | None = None
role: UserRole | None = None
work_schedule_id: uuid.UUID | None = None
kuerzel: str | None = Field(None, max_length=20)
personnel_number: str | None = Field(None, max_length=50, pattern=PERSONNEL_NUMBER_PATTERN)
can_manual_time_entry: bool | None = None
is_active: bool | None = None
entry_date: date | None = None
exit_date: date | None = None
class InviteRequest(BaseModel):
email: EmailStr
first_name: str = Field(min_length=1, max_length=100)
last_name: str = Field(min_length=1, max_length=100)
role: UserRole = UserRole.EMPLOYEE
department_id: uuid.UUID | None = None
personnel_number: str | None = Field(None, max_length=50, pattern=PERSONNEL_NUMBER_PATTERN)
# Wenn gesetzt → User wird sofort aktiv (kein Invite-E-Mail nötig)
initial_password: str | None = Field(None, min_length=8, max_length=128)
@model_validator(mode="after")
def password_strength(self):
pw = self.initial_password
if pw is None:
return self
if not any(c.isupper() for c in pw):
raise ValueError("initial_password must contain at least one uppercase letter")
if not any(c.isdigit() for c in pw):
raise ValueError("initial_password must contain at least one digit")
return self
class InviteAccept(BaseModel):
token: str
password: str = Field(min_length=8, max_length=128)
@model_validator(mode="after")
def password_strength(self):
pw = self.password
if not any(c.isupper() for c in pw):
raise ValueError("Password must contain at least one uppercase letter")
if not any(c.isdigit() for c in pw):
raise ValueError("Password must contain at least one digit")
return self
class UserListResponse(BaseModel):
total: int
items: list[UserOut]
class SetKioskPinRequest(BaseModel):
pin: str = Field(min_length=4, max_length=6, pattern=r"^\d+$")
class NextPersonnelNumberResponse(BaseModel):
next: str
class UserImportRowError(BaseModel):
row: int
email: str | None = None
message: str
class UserImportRowResult(BaseModel):
row: int
email: str
personnel_number: str | None = None
action: str # "created" | "reactivated" | "skipped" | "error"
message: str | None = None
class UserImportResult(BaseModel):
total_rows: int
created: int
reactivated: int
errors: int
items: list[UserImportRowResult]