feat(manager): staff permission editor, signed-in sessions, approvals log (platform-v2 2.6e)

- Staff: the 13 perm_* tick columns become one Permissions column (count,
  "changed from role") opening an editor grouped by module, from
  /api/waiters/permission-catalog: switches labelled per key, keys you don't
  hold are disabled with the reason, reset to role defaults (names what it
  can't give), save the whole set; access.cannot_grant explained by label.
- "Signed in now" (/management/sessions): who, where (app or device), since,
  last active, your own session marked; end session; show ended + reason.
- "Manager approvals" (/management/approvals): the override audit with
  action label, asked by, approved by, device, used/not used, order link.
- Backend: sessions list adds device_name/device_app/current/expires_at;
  overrides list adds device_name/expires_at.
- Permission labels for every key in modules.json (en/el), guarded by
  test_module_texts; manager unit tests for the editor logic; e2e 66 checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 08:10:57 +02:00
co-authored by Claude Opus 5.5
parent cc00ec39c7
commit 92bc1b0113
20 changed files with 1135 additions and 189 deletions
+11 -5
View File
@@ -279,24 +279,30 @@ def support_verify(body: SupportVerifyRequest, request: Request, db: Session = D
# ── Sessions (D-9): who is logged in where ─────────────────────────────────
def _session_out(s, users: dict) -> dict:
def _session_out(s, users: dict, devices: dict, current_sid) -> dict:
u = users.get(s.user_id)
d = devices.get(s.device_id)
return {"id": s.id, "user_id": s.user_id, "username": u.username if u else ("support" if s.client == "support" else None),
"full_name": u.full_name if u else None, "client": s.client, "device_id": s.device_id,
"created_at": iso_z(s.created_at), "last_seen_at": iso_z(s.last_seen_at),
"device_name": d.name if d else None, "device_app": d.app_key if d else None,
"current": s.id == current_sid,
"created_at": iso_z(s.created_at), "last_seen_at": iso_z(s.last_seen_at), "expires_at": iso_z(s.expires_at),
"ended_at": iso_z(s.ended_at), "end_reason": s.end_reason, "ip": s.ip, "user_agent": s.user_agent}
@router.get("/sessions")
def list_sessions(include_ended: bool = False, db: Session = Depends(get_db),
def list_sessions(request: Request, include_ended: bool = False, db: Session = Depends(get_db),
user: User = Depends(require("core.staff.manage"))):
"""Active sessions (optionally the last 200 ended ones too), newest first."""
"""Active sessions (optionally the last 200 ended ones too), newest first. `current`
marks the caller's own session; `device_name`/`device_app` name a terminal's device."""
from models.device import Device
q = db.query(LoginSession)
if not include_ended:
q = q.filter(LoginSession.ended_at.is_(None))
rows = q.order_by(LoginSession.created_at.desc()).limit(200).all()
users = {u.id: u for u in db.query(User).filter(User.id.in_({r.user_id for r in rows if r.user_id})).all()}
return [_session_out(r, users) for r in rows]
devices = {d.id: d for d in db.query(Device).filter(Device.id.in_({r.device_id for r in rows if r.device_id})).all()}
return [_session_out(r, users, devices, getattr(request.state, "xenia_sid", None)) for r in rows]
@router.post("/sessions/{sid}/end")