oliver-zehentleitner / maity

clean-up: Mail and notifications: module boundaries (routes import, mail-text helpers, preferences split) and the bell head query

Sign in to report

tsk-xx108ajy287x Done An agent

From the clean-up audit tsk-hgnbapyw7hnh, area 12 (Mail and notifications). Read at 80647565; all line numbers are from that commit. Finding numbers are the audit's (seq 125453). (Code names are written without backticks: the inline body cannot carry them.)

Order: do item 12's move of defang/quoted after tsk-e2m6krwdk5rg, which uses them in notifications/mailer.py. Do item 16 last. It moves code that the other clean-up cards of this area edit (preferences.py: tsk-y5hkg2ztvwq9, tsk-8vdegd61y70v).

12. design: notifications/ reaches into routes/, and other modules reach into the notification mailer for the mail-text helpers

  • notifications/listing.py:23 imports from maity_hub.routes.me import open_requests (routes/me.py:241), so a domain module depends on a route module.
  • defang and quoted (notifications/mailer.py:64-100) are the hub's mail-text rules (§18.5), but they live in the notification-mail planner.
  • invitation_mail.py:69 and registration_accounts.py:410 import them function-locally (an import-cycle workaround).
  • auth/second_factor_reset.py:32 imports the whole mailer for mailer.quoted (used at 122).
  • Proposal: move open_requests to a domain module (inbox.py or the requests module) and import it from both places. Move defang, quoted and _schemes to mail/ (e.g. mail/text.py beside headers.py) and drop the local imports.
  • Effort: S. Risk: low (pure moves; watch for import cycles).

15. debt (slow path on a hot route): listing.head makes one query per membership on every GET /me/notifications

  • Files: notifications/listing.py:272-290 (a loop of max(event.seq) per membership), called at routes/notifications.py:292. The grouped form already exists in held_stamp (listing.py:176-194: one GROUP BY project_id).
  • Proposal: one select(project_id, max(seq)) ... group_by(project_id), with zeros for projects without events.
  • Effort: S. Risk: low. Keep tests/test_notifications_load.py's statement count.

16. design: notifications/preferences.py (905 lines) has grown past the notification settings into the address lifecycle and the hub-wide text language

  • Files: preferences.py:514-905 sits beside the settings proper (1-512) and holds:
  • the address change and held approval (517-572, 786-839);
  • verification and claim (575-783);
  • the old-address notice (842-877);
  • the password-side voiding (880-905).
  • text_language (preferences.py:179-184), the language of what the hub composes for a human, is used by auth/mail_factor.py:166 and 258, auth/second_factor_reset.py:112 and 172, routes/email_sign_in.py:186 and 318, routes/password_reset.py:153, reports.py:472 and subagents.py:32. It is also copied into migrations/versions/20261104150000_report_request.py:147.
  • What's wrong: account identity (the verified address is a sign-in factor, §2.6.3) lives in a notifications module, and every mail-sending module imports notifications.preferences for the human's language.
  • Proposal: split into account_address.py (or auth/address.py) for the lifecycle, and move text_language beside languages.py. preferences.py keeps the settings, the merge and the unsubscribe.
  • Effort: M. Risk: low to medium (many imports, no behaviour change).

Left out as duplicates: none. Searched: notifications/listing.py, notifications/preferences.py, text_language, defang.