- 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>
83 lines
5.2 KiB
Python
83 lines
5.2 KiB
Python
"""Staff on v2 (plan step 6.11): passwords set by a manager (KI-014), PINs in the body and
|
|
checked, deleting only people without history, the schedule's times and overlaps."""
|
|
from datetime import date
|
|
|
|
from tests.test_live import err, owner_h, pair # noqa: F401 (fixtures)
|
|
|
|
|
|
def _new(client, h, **extra):
|
|
body = {"username": extra.pop("username", "eleni"), "role": "waiter", "pin": "4321", "full_name": "Eleni K", "nickname": "Eleni", **extra}
|
|
r = client.post("/api/waiters/", headers=h, json=body)
|
|
return r
|
|
|
|
|
|
def test_a_waiter_given_a_password_signs_in_with_it_on_a_paired_screen(client, owner_h, pair):
|
|
w = _new(client, owner_h).json()
|
|
assert w["has_password"] is False
|
|
token, r = pair("pos_counter", "Till", login_mode="password")
|
|
assert r.status_code == 201, r.text
|
|
dev = {"X-Xenia-Device": token}
|
|
login = lambda pw: client.post("/api/auth/login", headers=dev, json={"client": "terminal", "username": "eleni", "password": pw}) # noqa: E731
|
|
assert err(login("whatever1")) == "auth.invalid_credentials" # no password yet (KI-014)
|
|
assert err(client.put(f"/api/waiters/{w['id']}/password", headers=owner_h, json={"password": "short"})) == "auth.password_too_short"
|
|
r = client.put(f"/api/waiters/{w['id']}/password", headers=owner_h, json={"password": "kalimera6"})
|
|
assert r.json() == {"ok": True, "has_password": True}
|
|
assert next(s for s in client.get("/api/waiters/", headers=owner_h).json() if s["id"] == w["id"])["has_password"] is True
|
|
signed = login("kalimera6")
|
|
assert signed.status_code == 200, signed.text
|
|
assert signed.json()["user"]["username"] == "eleni"
|
|
# taken away: PIN only again
|
|
client.put(f"/api/waiters/{w['id']}/password", headers=owner_h, json={"password": None})
|
|
assert err(login("kalimera6")) == "auth.invalid_credentials"
|
|
|
|
|
|
def test_pins_are_digits_and_go_in_the_body(client, owner_h):
|
|
assert err(_new(client, owner_h, pin="12")) == "staff.pin_invalid"
|
|
assert err(_new(client, owner_h, pin="12ab")) == "staff.pin_invalid"
|
|
w = _new(client, owner_h, password="welcome1").json()
|
|
assert w["has_password"] is True
|
|
assert err(client.put(f"/api/waiters/{w['id']}/pin", headers=owner_h, json={"pin": "1234567"})) == "staff.pin_invalid"
|
|
assert client.put(f"/api/waiters/{w['id']}/pin", headers=owner_h, json={"pin": "2468"}).json() == {"ok": True}
|
|
r = client.post("/api/auth/login", json={"client": "waiter", "username": "eleni", "pin": "2468"})
|
|
assert r.status_code == 200, r.text
|
|
assert client.put(f"/api/waiters/{w['id']}/reset-pin?pin=1111", headers=owner_h).status_code in (404, 405) # the old route is gone
|
|
|
|
|
|
def test_delete_only_without_history_and_never_yourself(client, db, owner_h, make_user):
|
|
from core.timeutil import utcnow
|
|
from models.order import Order
|
|
fresh = _new(client, owner_h, username="fresh").json()
|
|
worked = _new(client, owner_h, username="worked").json()
|
|
db.add(Order(opened_by=worked["id"], opened_at=utcnow(), status="closed"))
|
|
db.commit()
|
|
assert err(client.delete(f"/api/waiters/{worked['id']}", headers=owner_h)) == "staff.has_history"
|
|
assert client.delete(f"/api/waiters/{fresh['id']}", headers=owner_h).status_code == 204
|
|
me = client.get("/api/auth/me", headers=owner_h).json()
|
|
assert err(client.delete(f"/api/waiters/{me['id']}", headers=owner_h)) == "staff.delete_self"
|
|
assert err(client.put(f"/api/waiters/{me['id']}/password", headers=owner_h, json={"password": None})) == "staff.password_own"
|
|
|
|
|
|
def test_the_schedule_checks_times_and_overlaps_and_lists_the_kitchen(client, owner_h):
|
|
cook = _new(client, owner_h, username="cook", role="chef").json()
|
|
day = date(2026, 11, 23).isoformat()
|
|
add = lambda s, e: client.post("/api/schedule/", headers=owner_h, json={"user_id": cook["id"], "scheduled_date": day, "start_time": s, "end_time": e}) # noqa: E731
|
|
assert err(add("9:00", "17:00")) == "schedule.bad_time"
|
|
first = add("18:00", "02:00") # past midnight
|
|
assert first.status_code == 201, first.text
|
|
assert first.json()["duration_hours"] == 8.0
|
|
assert err(add("23:00", "23:30")) == "schedule.overlap"
|
|
assert add("10:00", "14:00").status_code == 201
|
|
second = client.get("/api/schedule/week", headers=owner_h, params={"week_start": day}).json()
|
|
assert any(w["id"] == cook["id"] and w["role"] == "chef" for w in second["waiters"])
|
|
lunch = next(s for s in second["scheduled"] if s["start_time"] == "10:00")
|
|
assert err(client.put(f"/api/schedule/{lunch['id']}", headers=owner_h, json={"end_time": "19:00"})) == "schedule.overlap"
|
|
assert client.put(f"/api/schedule/{lunch['id']}", headers=owner_h, json={"end_time": "16:00", "notes": " "}).json()["notes"] is None
|
|
|
|
|
|
def test_editing_clears_what_is_emptied_and_keeps_usernames_unique(client, owner_h):
|
|
a = _new(client, owner_h, mobile_phone="6900000000").json()
|
|
_new(client, owner_h, username="other")
|
|
r = client.put(f"/api/waiters/{a['id']}", headers=owner_h, json={"mobile_phone": None, "full_name": "Eleni K.", "language": ""})
|
|
assert r.status_code == 200 and r.json().get("mobile_phone") is None and r.json()["full_name"] == "Eleni K."
|
|
assert err(client.put(f"/api/waiters/{a['id']}", headers=owner_h, json={"username": "other"})) == "staff.username_taken"
|