Skip to content

«📒 Мой дневник» keeps reading the «Сетевой город» region a class was rebound away from #145

Closed

Description

@lumenpearson

What is broken.
_session_for in the bot's diary handler is supposed to drop a session opened against a diary the class no longer uses. Its docstring says the stale row should become «войдите снова» "rather than a screen that silently talks to the diary the class left". It only matches on the provider, though, not on the region. For «Сетевой город», one provider covers many regional servers, and a session's credential names its own region. Rebinding a class from one region to another in «⚙️ Класс» expires no session: neither the unbind step nor the new binding touches diary_sessions. So a family's old session is still found and still read from the old region's server, under a class that is now bound somewhere else. A Petersburg ↔ «Сетевой город» rebind is filtered correctly. A region ↔ region rebind is not.

The failure scenario.

  1. Class «9А» is bound in «⚙️ Класс» → «📒 Электронный дневник» to «Сетевой город», region A, school X. A parent presses «🔐 Войти» and signs in on /diary/signin. diary_web stores a DiarySession with provider='netschool', region='A' and class_id=9А, and the sealed credential's JSON names region A and school X.
  2. The admin presses the diary button on the class card. class_diary_bind unbinds «Дневник отвязан» by clearing the four class columns only. The admin then binds «Сетевой город» → region B → school Y through class_diary_region and class_diary_school. Neither step expires the parent's row.
  3. The parent presses «📒 Мой дневник». _bound is true because binding B is valid. _session_for filters on DiarySession.provider == 'netschool' with no region term, so it returns the region-A row, and upstream_of unseals it without complaint.
  4. DiaryService calls NetSchoolProvider.open, which reads the region from the credential and builds a NetSchoolConnection against region A's origin. _show then fetches the students and the day from region A and draws the old school's diary on the screen of a class now bound to region B, school Y. The parent should have been sent to «войдите снова», the same as after a Petersburg → «Сетевой город» rebind.
  5. The stale row does not age out. The cron keep-alive pings every live netschool session without looking at the class's binding, so the region-A session stays alive until the parent presses «Выйти». It dies on its own only if region A is removed from the allow-list, because then open returns a dead connection.

Where.

  • server/app/bot/handlers/diary.py:86-99. The query's only binding filter is provider_clause (line 91). b.region from line 83 is never compared with DiarySession.region. The intent is stated at lines 76-80.
  • server/app/bot/handlers/manage.py:2389-2395 (unbind), 2426-2429 (bind Petersburg), 2582-2585 (bind «Сетевой город»). None of these expires a session. Keeping sessions on a plain unbind is deliberate (docstring at 2378-2382), so the region check has to happen at lookup.
  • server/app/api/diary_web.py:323-330 stores the session's region.
  • server/app/providers/netschool/provider.py:204-215 opens the connection at the credential's own region.
  • server/app/services/diary_keepalive.py:102-109 keeps every live netschool row alive regardless of binding.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status
      Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions