wyby sync: skip PIN collisions with foreign manual codes
Glutz codes are globally unique; a PIN already owned by another user (e.g. manually set temporary code) is skipped with a clear WARNING instead of failing the whole run. 41 tests green.
This commit is contained in:
@@ -31,10 +31,31 @@ den Buchungsbeginn ab.
|
|||||||
| Datei | Zweck |
|
| Datei | Zweck |
|
||||||
|---|---|
|
|---|---|
|
||||||
| `glutz_api.py` | JSON-RPC-Client (vendored aus `../glutz-eaccess-api`) |
|
| `glutz_api.py` | JSON-RPC-Client (vendored aus `../glutz-eaccess-api`) |
|
||||||
| `extend_pins.py` | Das eigentliche Script (Dry-Run ist Standard) |
|
| `wyby_client.py` | Headless-Client für das wyby-Vermieterportal (nur lesen) |
|
||||||
| `deploy/` | systemd Service + Timer + `deploy.sh` |
|
| `wyby_sync.py` | Proaktives PIN-Setzen aus wyby-Buchungen (Dry-Run ist Standard) |
|
||||||
|
| `extend_pins.py` | Sicherheitsnetz: erweitert wyby-gesetzte Codes stündlich |
|
||||||
|
| `deploy/` | systemd Services + Timer + `deploy.sh` |
|
||||||
| `.env` | Zugangsdaten (nicht im Repo, siehe `.env.example`) |
|
| `.env` | Zugangsdaten (nicht im Repo, siehe `.env.example`) |
|
||||||
|
|
||||||
|
## wyby-Sync (proaktiv, alle 15 Min.)
|
||||||
|
|
||||||
|
Die wyby-Schnittstelle legt Benutzer/PINs erst kurz vor Buchungsbeginn an
|
||||||
|
(«irgendwann davor»). Der wyby-Sync schliesst diese Lücke: Er meldet sich
|
||||||
|
headless am Vermieterportal an (`WYBY_USER/WYBY_PASS`, OIDC-Codeflow mit
|
||||||
|
PKCE), liest die kommenden Buchungen (Scheduler-API `GetWallpaperData`) und
|
||||||
|
sorgt pro Buchung in Glutz für Benutzer («<Name> <Vorname> <PIN>»),
|
||||||
|
Gruppenzuordnung und PIN mit tageweiser Gültigkeit (Startdatum 00:00 –
|
||||||
|
Enddatum 23:59). PIN = letzte 6 Ziffern der Transaktionsnummer.
|
||||||
|
|
||||||
|
- Idempotent und selbstheilend: übernimmt wybys eigene späte Läufe
|
||||||
|
(Resets auf ±15 min) beim nächsten Lauf wieder auf ganze Tage.
|
||||||
|
- PIN-Kollisionen mit manuellen Codes (Code ist in Glutz global unique)
|
||||||
|
werden übersprungen und als WARNING geloggt (Fehlerfilter im Journal).
|
||||||
|
- Timer: alle 15 Minuten, rund um die Uhr (Buchungen können jederzeit
|
||||||
|
erfasst werden).
|
||||||
|
|
||||||
|
## extend_pins (Sicherheitsnetz, stündlich 05:40–23:40)
|
||||||
|
|
||||||
## Manuell
|
## Manuell
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
@@ -140,3 +140,28 @@ class TestRun:
|
|||||||
monkeypatch.setattr(glutz_api, "rpc", lambda m, p: {"id": "9"})
|
monkeypatch.setattr(glutz_api, "rpc", lambda m, p: {"id": "9"})
|
||||||
sync.planned = [("ctx", "Codes", {"id": "1", "code": "1"})]
|
sync.planned = [("ctx", "Codes", {"id": "1", "code": "1"})]
|
||||||
assert sync.run() is True
|
assert sync.run() is True
|
||||||
|
|
||||||
|
|
||||||
|
class TestPinCollision:
|
||||||
|
def test_pin_owned_by_foreign_user_is_skipped_with_warning(self, sync):
|
||||||
|
sync.relations = [{"parentId": "12", "childId": "55"}]
|
||||||
|
sync.codes = [
|
||||||
|
code_row(id=66, userId=6, code="237251", description="Bajo Temporär")
|
||||||
|
]
|
||||||
|
sync.plan_booking(booking(), "12", date.today())
|
||||||
|
assert not sync.planned
|
||||||
|
assert any("resolve manually" in s for s in sync.skipped)
|
||||||
|
|
||||||
|
def test_own_code_still_updates(self, sync):
|
||||||
|
sync.relations = [{"parentId": "12", "childId": "55"}]
|
||||||
|
sync.codes = [
|
||||||
|
code_row(
|
||||||
|
id=99,
|
||||||
|
userId=55,
|
||||||
|
code="237251",
|
||||||
|
validFrom=f"{FUTURE}-12-27T12:45:00.000",
|
||||||
|
validTo=f"{FUTURE}-12-27T17:15:00.000",
|
||||||
|
)
|
||||||
|
]
|
||||||
|
sync.plan_booking(booking(), "12", date.today())
|
||||||
|
assert len(sync.planned) == 1
|
||||||
|
|||||||
@@ -119,6 +119,13 @@ class Sync:
|
|||||||
return c
|
return c
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def _pin_owner(self, pin):
|
||||||
|
"""Any code row with this PIN value (codes are globally unique in Glutz)."""
|
||||||
|
for c in self.codes:
|
||||||
|
if str(c.get("code")) == str(pin):
|
||||||
|
return c
|
||||||
|
return None
|
||||||
|
|
||||||
# --- planning -------------------------------------------------------
|
# --- planning -------------------------------------------------------
|
||||||
|
|
||||||
def plan_booking(self, b, group_id, today):
|
def plan_booking(self, b, group_id, today):
|
||||||
@@ -143,6 +150,14 @@ class Sync:
|
|||||||
desired_to = datetime.combine(b.end_date, time(23, 59, 59))
|
desired_to = datetime.combine(b.end_date, time(23, 59, 59))
|
||||||
row = self._code_row(uid, b.pin)
|
row = self._code_row(uid, b.pin)
|
||||||
if row is None:
|
if row is None:
|
||||||
|
other = self._pin_owner(b.pin)
|
||||||
|
if other is not None:
|
||||||
|
self.skipped.append(
|
||||||
|
f"{ctx} - PIN {b.pin} already exists for Glutz user id "
|
||||||
|
f"{other['userId']} ({other.get('description') or 'no description'}) "
|
||||||
|
"-> resolve manually, not touching foreign code"
|
||||||
|
)
|
||||||
|
return
|
||||||
self.planned.append(
|
self.planned.append(
|
||||||
(
|
(
|
||||||
ctx,
|
ctx,
|
||||||
|
|||||||
Reference in New Issue
Block a user