Skip to content

fix(sync): never import sheet rows into a userless group (Refs #184) - #246

Merged
alex-mextner merged 1 commit into
mainfrom
fix-sync-import-user
Nov 7, 2026
Merged

alex-mextner merged 1 commit into
mainfrom
fix-sync-import-user

Conversation

@alex-mextner

@alex-mextner alex-mextner commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

Что было

importExpensesFromSheet (src/bot/commands/sync.ts:414) при импорте расходов из Google Sheet брал владельца строк как users[0]?.id ?? 1. Если у группы нет ни одного пользователя (users), фолбэк писал user_id: 1. Но users.id — глобальный счётчик, и FK на expenses.user_id не проверяет group_id: строки доставались пользователю другой группы.

Пути, куда это стреляло: годовое восстановление по крону (src/bot/cron.ts) и /reconnect (src/bot/commands/reconnect.ts).

Фикс

Симметрично уже исправленному /sync-пути (applyNewRow, sync.ts:220): фолбэк удалён — если у группы нет пользователя, импорт пропускается с logger.warn ([SYNC] Sheet import skipped: the group has no user to own the rows) и возвращается 0. Ни одна строка не пишется без same-group владельца.

Тест

sync-expenses.test.ts — «a userless group imports nothing, never rows owned by another group's user 1»: создаётся другая группа с пользователем id=1, импорт в группу без пользователей должен вернуть 0 и не записать ни одного расхода (red-verified на старом коде).

Gates: server-run -- bun run test — 253 файла / 6071 тест, 0 fail; type-check ✅; lint ✅. Машинное ревью: чисто.

Refs #184

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

🔁 PR closed. Stage bot switched back to main.

@alex-mextner alex-mextner changed the title fix(sync): never import sheet rows into a userless group (Fixes #184) fix(sync): never import sheet rows into a userless group (Refs #184) Nov 7, 2026
importExpensesFromSheet fell back to user_id 1 when the group had no users.
users.id is global and the FK does not check group_id, so cron year-recovery
and /reconnect could hand imported expenses to another group's user. Mirror of
the fixed /sync pattern: no fallback id; when the group has no user the rows
are skipped and the count returned (SheetImportResult) so /reconnect reports
«Таблица → БД: пропущено N строк — в группе нет ни одного участника» (never the
misleading «синхронизированы» alongside) and cron logs a warn.
@alex-mextner
alex-mextner merged commit 073908e into main Nov 7, 2026
16 checks passed
@alex-mextner
alex-mextner deleted the fix-sync-import-user branch November 7, 2026 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant