From 841e2e53d4619e01d2c6bff1f86d577db844ba00 Mon Sep 17 00:00:00 2001 From: Markus Graf Date: Thu, 12 Nov 2026 11:56:24 +0100 Subject: [PATCH] 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. --- README.md | 25 +++++++++++++++++++++++-- tests/test_wyby_sync.py | 25 +++++++++++++++++++++++++ wyby_sync.py | 15 +++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8584a8b..662efd4 100644 --- a/README.md +++ b/README.md @@ -31,10 +31,31 @@ den Buchungsbeginn ab. | Datei | Zweck | |---|---| | `glutz_api.py` | JSON-RPC-Client (vendored aus `../glutz-eaccess-api`) | -| `extend_pins.py` | Das eigentliche Script (Dry-Run ist Standard) | -| `deploy/` | systemd Service + Timer + `deploy.sh` | +| `wyby_client.py` | Headless-Client für das wyby-Vermieterportal (nur lesen) | +| `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`) | +## 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 (« »), +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 ```bash diff --git a/tests/test_wyby_sync.py b/tests/test_wyby_sync.py index e7948ea..9516881 100644 --- a/tests/test_wyby_sync.py +++ b/tests/test_wyby_sync.py @@ -140,3 +140,28 @@ class TestRun: monkeypatch.setattr(glutz_api, "rpc", lambda m, p: {"id": "9"}) sync.planned = [("ctx", "Codes", {"id": "1", "code": "1"})] 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 diff --git a/wyby_sync.py b/wyby_sync.py index f6821f8..f204acc 100755 --- a/wyby_sync.py +++ b/wyby_sync.py @@ -119,6 +119,13 @@ class Sync: return c 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 ------------------------------------------------------- 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)) row = self._code_row(uid, b.pin) 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( ( ctx,