feat(backend): permission keys replace the 13 perm_* columns
Platform v2 step 1.5 (APPS_PLATFORM D-7, D-17, §3, §6.1).
- user_permissions(user_id, key); revision 0005 copies existing v1 flags into
keys (frozen mapping) and drops the perm_* columns; can_cancel_orders gone
- core/access: check() = module effective + key held (superadmin implicit,
override keys wired for 1.9); holds()/can(); markers require/require_any/
public/require_device; role templates from manifests; queries.holders_filter
replaces User.perm_x == True; legacy.py projects/accepts the v1 booleans
for the current manager/waiter UIs only (§3.3, temporary)
- routers.deps: require_manager/... are now aliases of require("<key>");
history endpoints use history.view; superadmin-only = core.system.admin;
get_current_user carries the "signed_in" marker
- every inline perm_* read in routers/services converted to holds()
- staff API: permission catalogue by module with role templates, get/set a
user's keys, reset to role template; legacy flag toggles still work; a
non-superadmin can only grant keys they hold (access.cannot_grant)
- setup wizard creates the first account as owner (v1: store_manager, who
couldn't change settings); demo/seed manager is owner
- roles.py keeps only the role list and labels
- guards: every route has an access marker (19 open routes marked public()
on purpose; /waiters/roles now needs sign-in), no perm_* attribute reads
- tests: check matrix, templates, projection, staff permission API, grant
guard, 0005 data copy; pack rule CS-14
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, model_validator
|
||||
from datetime import datetime
|
||||
from typing import Optional, List
|
||||
from schemas.base import UTCDatetime
|
||||
@@ -17,7 +17,7 @@ class UserBase(BaseModel):
|
||||
language: Optional[str] = None # NULL = inherit (device -> venue -> en)
|
||||
# Phase 2B — payroll
|
||||
hourly_rate: Optional[float] = None
|
||||
# Access permissions
|
||||
# v1 permission booleans: OUTPUT ONLY, computed from keys (core/access/legacy.py, §3.3)
|
||||
perm_access_dashboard: bool = False
|
||||
perm_access_waiter_app: bool = True
|
||||
perm_access_kds: bool = False
|
||||
@@ -82,9 +82,26 @@ class UserOut(UserBase):
|
||||
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
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def _from_user(cls, obj):
|
||||
"""ORM user -> dict with the v1 perm_* booleans computed from its keys
|
||||
(core/access/legacy.py, temporary) and the keys themselves."""
|
||||
if isinstance(obj, dict):
|
||||
return obj
|
||||
from core.access.check import user_keys
|
||||
from core.access.legacy import project
|
||||
data = {name: getattr(obj, name, None) for name in cls.model_fields
|
||||
if name not in ("permissions",) and not name.startswith("perm_")}
|
||||
data["zone_assignments"] = list(getattr(obj, "zone_assignments", None) or [])
|
||||
data.update(project(obj))
|
||||
data["permissions"] = sorted(user_keys(obj))
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user