- staff: PUT /api/waiters/{id}/password (set, change, or take away; 6+ chars)
so the password sign-in mode works for everyone; PUT /{id}/pin with the PIN in
the body (was in the address: reset-pin?pin= removed); PINs 4-6 digits when
adding; a password can be given when adding; has_password on staff; editing
clears emptied fields and keeps usernames unique; delete only without history
(orders, items, shifts) and never yourself
- schedule: times checked (schedule.bad_time), one person's overlapping shifts
refused (schedule.overlap, past midnight understood), everyone active can be
scheduled (the kitchen too), changes need core.staff.manage
- manager: src/pages/staff (list with search and filters, person dialog with
photo, PIN / password dialog, zones) and src/pages/schedule (by person, by
hour with opening hours, shift dialog with clash check, view settings kept in
the browser); the never-used "automatic start/close" switches dropped; v1
StaffTab and SchedulePage removed; ApprovalsPage loads with useLiveQuery
- tests: test_staff_v2.py (done-when on a paired screen), staff.test.mjs, e2e
manager.mjs (add, password, sign-in on a paired till, a shift and a clash)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
89 lines
3.0 KiB
Python
89 lines
3.0 KiB
Python
from pydantic import BaseModel, model_validator
|
|
from datetime import datetime
|
|
from typing import Optional, List
|
|
from schemas.base import UTCDatetime
|
|
|
|
|
|
class UserBase(BaseModel):
|
|
username: str
|
|
role: str
|
|
is_active: bool = True
|
|
full_name: Optional[str] = None
|
|
nickname: Optional[str] = None
|
|
mobile_phone: Optional[str] = None
|
|
note: Optional[str] = None
|
|
avatar_url: Optional[str] = None
|
|
email: Optional[str] = None
|
|
language: Optional[str] = None # NULL = inherit (device -> venue -> en)
|
|
# Phase 2B — payroll
|
|
hourly_rate: Optional[float] = None
|
|
|
|
|
|
class UserCreate(UserBase):
|
|
pin: str
|
|
password: Optional[str] = None # 6.11: for the password sign-in mode (6+ characters)
|
|
|
|
|
|
class UserUpdate(BaseModel):
|
|
username: Optional[str] = None
|
|
role: Optional[str] = None
|
|
is_active: Optional[bool] = None
|
|
full_name: Optional[str] = None
|
|
nickname: Optional[str] = None
|
|
mobile_phone: Optional[str] = None
|
|
email: Optional[str] = None
|
|
note: Optional[str] = None
|
|
language: Optional[str] = None # "" clears it (inherit)
|
|
# Phase 2B — payroll
|
|
hourly_rate: Optional[float] = None
|
|
|
|
|
|
class WaiterZoneOut(BaseModel):
|
|
id: int
|
|
waiter_id: int
|
|
group_id: Optional[int] = None # None = all zones
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class UserOut(UserBase):
|
|
id: int
|
|
created_at: UTCDatetime
|
|
zone_assignments: List[WaiterZoneOut] = []
|
|
waiter_settings: Optional[str] = None # JSON blob — per-waiter settings + favorites
|
|
permissions: List[str] = [] # permission keys (D-7); superadmin: [] = implicit all
|
|
has_password: bool = False # 6.11: can sign in by password (never the password itself)
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
@model_validator(mode="before")
|
|
@classmethod
|
|
def _from_user(cls, obj):
|
|
"""ORM user -> dict with its permission keys."""
|
|
if isinstance(obj, dict):
|
|
return obj
|
|
from core.access.check import user_keys
|
|
data = {name: getattr(obj, name, None) for name in cls.model_fields
|
|
if name != "permissions"}
|
|
data["zone_assignments"] = list(getattr(obj, "zone_assignments", None) or [])
|
|
data["permissions"] = sorted(user_keys(obj))
|
|
data["has_password"] = bool(getattr(obj, "password_hash", None))
|
|
return {k: v for k, v in data.items() if v is not None or k in ("full_name",)}
|
|
|
|
|
|
class SetZonesRequest(BaseModel):
|
|
"""Replace all zone assignments for a waiter in one call.
|
|
group_ids=[] means remove all (sees nothing).
|
|
group_ids=[null] or all_zones=True means the wildcard 'all zones' sentinel."""
|
|
group_ids: Optional[List[Optional[int]]] = None # list of group ids; None in list = all-zones sentinel
|
|
all_zones: bool = False # convenience flag: if True, set a single NULL-group_id row
|
|
|
|
|
|
class AssistantAssignmentOut(BaseModel):
|
|
id: int
|
|
primary_waiter_id: int
|
|
assistant_waiter_id: int
|
|
assigned_at: UTCDatetime
|
|
|
|
model_config = {"from_attributes": True}
|