From a79354bbf31e8a2b385e7e85245dd70919b51395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 23 Sep 2026 01:53:27 +0300 Subject: [PATCH] fix(report): drop ReportSchool.slug; school identity is the uuid The backend no longer sends slug on the report-school payload. A stray slug key is ignored, and docs plus ZEKA_SCHOOLS examples name the hyphenated school uuid. --- README.md | 4 ++-- deploy/hezarfen_zeka.env.example | 2 +- service/.env.example | 2 +- service/README.md | 4 ++-- service/docs/BACKEND-GEREKSINIMLERI.md | 6 +++--- service/docs/KOPRU-KANITI.md | 2 +- service/src/capabilities.py | 4 ++-- service/src/cli.py | 4 ++-- service/src/handlers.py | 15 ++++----------- service/src/protocol.py | 2 +- service/src/scheduler.py | 4 ++-- service/src/store.py | 4 ++-- service/tests/test_report_capability.py | 15 ++++++++------- 13 files changed, 31 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 3a276b7..a811bc7 100644 --- a/README.md +++ b/README.md @@ -103,13 +103,13 @@ bir modele o veriyi vermek, erişim kontrolünü modelin içinden dolanmak olurd `hab/2` üzerinde taze bir istemci-başlatımlı akış açar ve çerçeveyi yazar: ``` -{ "id": "", "capability": "insight.", "school": "", "payload": {...} } +{ "id": "", "capability": "insight.", "school": "", "payload": {...} } { "status": "ok", "id": ..., "school": ..., "payload": {...} } { "status": "err", "id": ..., "school": ..., "code": ..., "message": ... } ``` -Okul **çerçevededir**, payload'da değil: backend slug'ı çözer ve her ifadeyi o +Okul **çerçevededir**, payload'da değil: `school` tireli okul uuid'sidir; backend onu çözer ve her ifadeyi o okulun kendi veritabanında koşturur. Reddin kodu tiplidir (`unknown_school`, `not_permitted`, `invalid_payload`, `too_many_rows`, `unavailable`, …) ve `CapabilityRefused` olarak yükselir; `status: "err"` asla başarı sayılmaz. diff --git a/deploy/hezarfen_zeka.env.example b/deploy/hezarfen_zeka.env.example index 3ffe335..7772c67 100644 --- a/deploy/hezarfen_zeka.env.example +++ b/deploy/hezarfen_zeka.env.example @@ -100,7 +100,7 @@ AI_RECONNECT_MAX_SECS=120 # Okul KUTUGU backend'dedir: hangi okullarin var oldugu `insight.schools.list` # yetenek cagrisiyla backend'den okunur. ZEKA_SCHOOLS yalnizca bir FILTREdir; # BOS BIRAKILIRSA butun aktif okullar islenir -- donem ortasi kayit olan -# ogrenci gorunmez, ayrilan silinmez. Ornek filtre: hezarfen-demo +# ogrenci gorunmez, ayrilan silinmez. Ornek filtre (tireli okul uuid): 01a0b0a5-ffb5-7682-8726-7e4ef1a5c68d ZEKA_SCHOOLS= # Ogrenci listesi hala BURADAN verilir: backend'de kullanici LISTELEME yolu diff --git a/service/.env.example b/service/.env.example index bc3a0d4..e76bd8d 100644 --- a/service/.env.example +++ b/service/.env.example @@ -64,7 +64,7 @@ AI_RECONNECT_MAX_SECS=120 # # Okul KUTUGU backend'dedir: hangi okullarin var oldugu `insight.schools.list` # yetenek cagrisiyla backend'den okunur. ZEKA_SCHOOLS yalnizca bir FILTREdir; -# BOS BIRAKILIRSA butun aktif okullar islenir. Ornek filtre: hezarfen-demo +# BOS BIRAKILIRSA butun aktif okullar islenir. Ornek filtre (tireli okul uuid): 01a0b0a5-ffb5-7682-8726-7e4ef1a5c68d ZEKA_SCHOOLS= # Ogrenci listesi hala buradan verilir: backend'de kullanici LISTELEME yolu diff --git a/service/README.md b/service/README.md index 5e9d394..d8c900d 100644 --- a/service/README.md +++ b/service/README.md @@ -39,13 +39,13 @@ Aynı köprüye, **yetenek çağrısıyla**. Servis taze bir istemci-başlatıml şu çerçeveyi yazar: ``` -{ "id": "", "capability": "insight.", "school": "", "payload": {...} } +{ "id": "", "capability": "insight.", "school": "", "payload": {...} } { "status": "ok", "id": ..., "school": ..., "payload": {...} } { "status": "err", "id": ..., "school": ..., "code": ..., "message": ... } ``` -Okul çerçevededir; backend slug'ı çözer ve her ifadeyi o okulun kendi +Okul çerçevededir; `school` tireli okul uuid'sidir. Backend onu çözer ve her ifadeyi o okulun kendi veritabanında koşturur. Dokuz `zeka_*` tablosu orada durur ve DDL'i backend deposundadır (`migrations/school/20260917000002_zeka.sql`) — servis ne şema uygular ne de bir veritabanı kullanıcısı ister. diff --git a/service/docs/BACKEND-GEREKSINIMLERI.md b/service/docs/BACKEND-GEREKSINIMLERI.md index 17b6ef4..6d52891 100644 --- a/service/docs/BACKEND-GEREKSINIMLERI.md +++ b/service/docs/BACKEND-GEREKSINIMLERI.md @@ -53,7 +53,7 @@ Iki yon birden. Ikisi de ayni cerceve bicimini kullanir cercevededir**, payload'da degil: ``` -{ "id": "", "capability": "insight.", "school": "", "payload": {...} } +{ "id": "", "capability": "insight.", "school": "", "payload": {...} } { "status": "ok", "id": ..., "school": ..., "payload": {...} } { "status": "err", "id": ..., "school": ..., "code": ..., "message": ... } @@ -168,7 +168,7 @@ Backend, okulun `zeka_*` satirlarini **kendi okur** ve tek bir cercevesinde **HTML metni olarak** dondurur. Blob yuklemesi yok, depo yok: belge, servisin hicbir okuma yapmadigi tek `insight.*` isleyicisidir. -**Istek payload'i.** Cercevedeki `school` = okul slug'i. Satirlar ZEKA'nin +**Istek payload'i.** Cercevedeki `school` = tireli okul uuid'si. Satirlar ZEKA'nin depo yoluyla yazdigi bicimdir -- backend'in kendi yapilari (`db/insight.rs` `SummaryRow` / `RecommendationRow` / `ProfileRow` / `RunRow`), yani ikinci bir esleme yok: @@ -178,7 +178,7 @@ esleme yok: | `kind` | str | Zorunlu; sunulan tek deger `okul` | | `run_day` | str | `YYYY-MM-DD` (TR gunu); yoksa en yeni kosu satirindan turetilir | | `requested_by` | str | Belgeyi isteyen mudur; okuma yapilmadigi icin yalniz log'a yazilir | -| `school` | nesne | `{id, slug, name}`; `name` belge BASLIGIDIR, `slug` cerceveyle ayni olmali | +| `school` | nesne | `{id, name}`; `name` belge BASLIGIDIR, `id` cercevedeki uuid ile aynidir. `slug` yok | | `classes` | liste | `[{id, name}]`: okulun butun subeleri, ad sirasinda. Satirlardaki `marks.classes` KIMLIK tasir; tabloya yazilan GORUNEN ad bu haritadan gelir. Kabul edilen ikinci bicim `class_names: {: ""}` (`classes` varsa o kazanir) | | `summaries` | liste | `zeka_student_summary` satirlari (`attention` listesi dahil) | | `recommendations` | liste | `zeka_recommendation` satirlari | diff --git a/service/docs/KOPRU-KANITI.md b/service/docs/KOPRU-KANITI.md index 1c39624..e4a56af 100644 --- a/service/docs/KOPRU-KANITI.md +++ b/service/docs/KOPRU-KANITI.md @@ -278,7 +278,7 @@ dogrulamaz. ### 5.3 Backend'in kendi mantigi -- **Okul slug dogrulama kurallari.** Backend `Slug::try_new` kullanir; sahte +- **Okul uuid dogrulama kurallari.** Backend tireli uuid parse eder (`SchoolId::try_parse`); sahte sunucu kaba bir denetim yapar. `malformed` kodu gercek kurallarla uretilmedi. - **Kullanici cozumleme.** `on_behalf_of`'un `user:` onekiyle ya da onsuz okunmasi, silinmis/rutbesi dusurulmus kullanici, `unknown_user` kodu. diff --git a/service/src/capabilities.py b/service/src/capabilities.py index bbeea7b..2d86b0d 100644 --- a/service/src/capabilities.py +++ b/service/src/capabilities.py @@ -193,7 +193,7 @@ class ReportRequest(TypedDict, total=False): yazdigi bicimin aynisi, yani ikinci bir esleme yok. Satirlarda `school` YOKTUR -- ZEKA onu hic yazmaz; cercevede gelir ve isleyici her satira damgalar (tek kimlik kaynagi). Payload'daki `school` yalniz GORUNUM icin - (`name` baslikta); `slug` cerceveyle celisirse istek reddedilir. + (`name` baslikta, `id` okul uuid'si). Backend `slug` gondermez. """ kind: str @@ -203,7 +203,7 @@ class ReportRequest(TypedDict, total=False): requested_by: str """Belgeyi isteyen mudur. Okuma yapilmadigi icin yalniz log'a yazilir.""" school: dict[str, Any] - """`{"id": ..., "slug": ..., "name": ...}` -- `name` belge basligidir.""" + """`{"id": ..., "name": ...}` -- `id` okul uuid'si, `name` belge basligidir.""" classes: list[dict[str, Any]] """`[{"id": ..., "name": ...}]` -- okulun butun subeleri (kimlik -> GORUNEN ad). Satirlardaki `marks.classes` KIMLIK tasir; tabloya yazilan ad bu diff --git a/service/src/cli.py b/service/src/cli.py index e77919d..05514ab 100644 --- a/service/src/cli.py +++ b/service/src/cli.py @@ -342,7 +342,7 @@ def build_parser() -> argparse.ArgumentParser: run.set_defaults(func=_cmd_run, is_async=True) sweep = sub.add_parser("sweep", help="saklama süresi süpürmesini koştur (köprüden)") - sweep.add_argument("--school", required=True, help="okul slug'ı") + sweep.add_argument("--school", required=True, help="okul uuid'si") sweep.add_argument("--now", type=int, help="unix ms; yalnız çıktı içindir") sweep.set_defaults(func=_cmd_sweep, is_async=True) @@ -351,7 +351,7 @@ def build_parser() -> argparse.ArgumentParser: ) schedule.add_argument( "--schools", - help="virgülle ayrılmış slug listesi — backend'in verdiği listenin " + help="virgülle ayrılmış uuid listesi — backend'in verdiği listenin " "FİLTRESİ. Verilmezse bütün aktif okullar koşar.", ) schedule.add_argument("--fixtures", required=True) diff --git a/service/src/handlers.py b/service/src/handlers.py index 960165d..7ab3e7e 100644 --- a/service/src/handlers.py +++ b/service/src/handlers.py @@ -102,7 +102,7 @@ _UNAVAILABLE = { "term": "no term directory; `term` must be an ISO-8601 date", } -#: School slug -> lock. One compute per school at a time: a dispatched refresh +#: School uuid -> lock. One compute per school at a time: a dispatched refresh #: and the night scheduler can overlap, and two `run_school` sweeps on one #: school would interleave the day's run-ledger row (the row is keyed by #: `run_day`) and race the per-student upserts. In-process only, which is @@ -568,22 +568,15 @@ def _report_school(frame_school: str, payload: dict[str, Any]) -> str: """The value every row is stamped with -- and the document's own school. The frame's `school` is the tenant identity; `payload.school.name` is the - DISPLAY name the report title carries. A payload whose `school.slug` - disagrees with the frame is refused: two identity sources is how another - school's rows reach a document. + DISPLAY name the report title carries. `payload.school` is `{id, name}` + (school uuid + title). The backend does not send `slug`; a stray `slug` + key is ignored. Identity is the frame alone. """ info = payload.get("school") if info is None: return frame_school if not isinstance(info, dict): raise CapabilityError("bad_request", "'school' bir nesne olmali") - slug = info.get("slug") - if isinstance(slug, str) and slug.strip() and slug.strip() != frame_school: - raise CapabilityError( - "bad_request", - f"payload'daki school.slug ({slug!r}) cercevedeki okulla " - f"({frame_school!r}) ayni degil", - ) name = info.get("name") if isinstance(name, str) and name.strip(): return name.strip() diff --git a/service/src/protocol.py b/service/src/protocol.py index ef0bc08..3cd4145 100644 --- a/service/src/protocol.py +++ b/service/src/protocol.py @@ -26,7 +26,7 @@ Uc istemci baslatimli sekil, zorunlu alaniyla ayirt edilir: `ApiRequest`'te okur; ucuncusu backend'in bir operasyonunu kosturur -- ZEKA'nin veritabani erisimi olmadigi icin yazma yolu YALNIZCA budur. -Okul kapsami (`protocol.rs:36-47`): her istek cercevesi okulunu slug ile +Okul kapsami (`protocol.rs:36-47`): her istek cercevesi okulunu tireli uuid ile adlandirir, her cevap onu yankilar. `Hello` KASITLI olarak okul tasimaz -- filo tum okullar icin paylasilir. Varsayilan ya da geri dusme yoktur. diff --git a/service/src/scheduler.py b/service/src/scheduler.py index 051535e..d7a9340 100644 --- a/service/src/scheduler.py +++ b/service/src/scheduler.py @@ -31,7 +31,7 @@ Tasarım kararları (`MODULLER.md` §2.12) * **Okul listesi her tikte dizinden okunur**: hangi okulların var olduğunu kontrol veritabanı bilir (`tenants.py`), yapılandırma değil. `ZEKA_SCHOOLS` artık yalnızca bir filtredir; boşsa bütün aktif okullar işlenir. -* **Her okul KENDİ veritabanına yazar**: depo, okulun slug'ından çözülür. +* **Her okul KENDİ veritabanına yazar**: depo, çerçevedeki okul uuid'sinden çözülür. Tek bir `store` nesnesi paylaşılmaz — paylaşılsaydı bütün okulların satırı ilk okulun veritabanına düşerdi. * **Günde bir kez.** Bir okul için o TR gününde koşu yapıldıysa tekrar @@ -185,7 +185,7 @@ class Scheduler: if self._last_run_day.get(school) == day: continue # Her okul KENDI deposundan yazar: okulun veritabani, - # cercevedeki slug'dan cozulur (`tenants.py`). Deposu + # cercevedeki uuid'den cozulur (`tenants.py`). Deposu # acilamayan okul dusen okuldur -- tur devam eder, `internal` # diye bir seye donusmez. try: diff --git a/service/src/store.py b/service/src/store.py index 8c21523..674397d 100644 --- a/service/src/store.py +++ b/service/src/store.py @@ -24,7 +24,7 @@ TEL (kablo) SÖZLEŞMESİ istemci-başlatımlı akışta gider (tıpkı `ApiRequest` gibi): { "id": "", "capability": "insight.[.]", - "school": "", "payload": { ... } } + "school": "", "payload": { ... } } { "status": "ok", "id": ..., "school": ..., "payload": { ... } } { "status": "err", "id": ..., "school": ..., "code": ..., "message": ... } @@ -34,7 +34,7 @@ istemci-başlatımlı akışta gider (tıpkı `ApiRequest` gibi): `not_permitted`, `invalid_payload`, `unavailable`, `timed_out`, `internal`, `too_many_rows`) ve `CapabilityRefused` olarak yükselir. -Okul **çerçevededir**, payload'da değil: backend slug'ı çözer ve her ifadeyi +Okul **çerçevededir**, payload'da değil: `school` tireli okul uuid'sidir; backend onu çözer ve her ifadeyi o okulun kendi veritabanında koşturur. Tek istisna `insight.schools.list` (deployment ölçekli): çerçevede `school: ""` gider. diff --git a/service/tests/test_report_capability.py b/service/tests/test_report_capability.py index 92f938f..75034f4 100644 --- a/service/tests/test_report_capability.py +++ b/service/tests/test_report_capability.py @@ -251,7 +251,7 @@ def payload(**over: Any) -> dict[str, Any]: "kind": "okul", "run_day": RUN_DAY, "requested_by": "mudur-1", - "school": {"id": "01990000-0000-7000-8000-000000000001", "slug": SCHOOL, "name": DISPLAY}, + "school": {"id": "01990000-0000-7000-8000-000000000001", "name": DISPLAY}, # Sibling key, read whole from the school's own class table: the rows # carry class IDS, and the document must print NAMES. "classes": [ @@ -426,12 +426,13 @@ class RefusalTests(ReportCase): self.assertEqual(caught.exception.code, "bad_request") self.assertIn("baska-okul", str(caught.exception)) - async def test_a_school_slug_disagreeing_with_the_frame_is_refused(self) -> None: - with self.assertRaises(CapabilityError) as caught: - await self.dispatch( - payload(school={"id": "x", "slug": "baska-okul", "name": "Başka"}) - ) - self.assertEqual(caught.exception.code, "bad_request") + async def test_a_stray_school_slug_is_ignored(self) -> None: + # Backend dropped ReportSchool.slug. A leftover key must not refuse + # and must not become a second identity. + answer = await self.dispatch( + payload(school={"id": "x", "slug": "baska-okul", "name": "Başka"}) + ) + self.assertIn("Başka", answer["html"]) async def test_a_malformed_row_list_is_refused(self) -> None: with self.assertRaises(CapabilityError) as caught: