Repository navigation
chore(auth): share one users column list with scanUser; drop the never-called SendWelcomeEmail - #1560
Conversation
…RTs and scanUser The four user SELECTs (GetUserByID, GetUserByEmail, ListUsers, GetUserByResetToken) each carried a hand-aligned copy of the 20-column list that scanUser reads positionally, and CreateUser and CreateAdminIfNone each carried their own 18-column INSERT list and argument list. Swapping two same-typed neighbors (mfa_secret and mfa_pending_secret, say) in one copy kept every existing test green. All four SELECTs now read userSelectColumns, both INSERTs write userInsertColumns with values from userInsertArgs, and the select list is the insert list plus deactivated_at and password_version. New tests key every value by column name (pgxmock) and round-trip every column through a real migrated Postgres with SQL that names its own columns. Refs LeanerCloud#313 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rying templates Nothing calls SendWelcomeEmail: invited users get SendUserInviteEmail. It still carried a role parameter from the removed role model. Remove it from email.SenderInterface, Sender, SMTPSender, NopSender, the mocks.MockEmailSender and EmailSenderAPI, and the per-package test stubs, together with the welcome templates, WelcomeUserData and the two renderers that only it used. Comments that called the invite email the welcome email now say invite. Refs LeanerCloud#313 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 59 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
govulncheck in the Docker image build now fails on these two advisories, both fixed in x/net v0.62.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Independent review (IAmJSD's agent, fresh context, given only the diff, the issue and the PR text): VERDICT: APPROVE Blocking:
Non-blocking:
Attacked:
Body-stale: the body doesn't mention the x/net bump commit (non-blocking). Reviewer: rG4. Bar while the maintainers are away (set by IAmJSD as acting owner): one approving independent review on the head, two for money, auth and security paths. |
|
Independent review (IAmJSD's agent, fresh context, given only the diff, the issue and the PR text): VERDICT: APPROVE Blocking:
Non-blocking:
Attacked:
Body-stale: none Reviewer: rH2. Bar while the maintainers are away (set by IAmJSD as acting owner): one approving independent review on the head, two for money, auth and security paths. |
|
Local verification at |
|
Merged by IAmJSD's agent at IAmJSD's request (IAmJSD is acting owner while the maintainers are away), under the bar IAmJSD set: 2 approving independent review(s) on |
Conflict in internal/auth/service_user.go (validateCreateUserRequest): kept this branch's normalizeAccountEmail and returned email, with main's "invite email link" wording now that SendWelcomeEmail is gone (LeanerCloud#1560). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Two leftovers from #313. Other parts of that issue stay open.
1. One users column list for every SELECT, INSERT and scanUser
Root cause.
GetUserByID,GetUserByEmail,ListUsersandGetUserByResetTokeneach had their own hand-aligned copy of the 20-column list thatscanUserreads by position.CreateUserandCreateAdminIfNoneeach had their own 18-column INSERT list plus a hand-ordered argument list. Several neighboring columns share a Go type (mfa_secret/mfa_pending_secret, the three[]stringcolumns, the seven timestamps). Swapping two of them in one copy produces no error and keeps every existing test green. I checked this on main: swappingmfa_secretandmfa_pending_secretinGetUserByIDalone leavesgo test ./internal/auth/passing.Fix (
internal/auth/store_postgres.go,internal/auth/store_postgres_admin.go):userInsertColumnsis the single INSERT column list, anduserInsertArgs(user, groupIDs)returns its values in the same order. BothCreateUserandCreateAdminIfNoneuse them.CreateAdminIfNonestill forces the Administrators group in and appends$19for theNOT EXISTSguard. The nil-to-{}substitution for recovery codes moved into the helper unchanged.userSelectColumns = userInsertColumns + ", deactivated_at, password_version"is the single list that all four SELECTs embed and thatscanUserreads.Tests:
internal/auth/store_postgres_user_columns_test.go(unit, pgxmock). Every column gets a value that no other same-typed column holds, keyed by column name, and is placed in row or argument position by looking each name in the shared list up in that map. The tests cover:Userfield;CreateUserandCreateAdminIfNonebinding every argument from the right field;internal/auth/store_postgres_user_columns_db_test.go(integration, real migrated Postgres). Rows are written and read back with SQL that names its own columns in an unrelated order, so these tests don't rely on the constants they check:User;CreateUserandCreateAdminIfNone, then a raw SELECT by name, must return the identical row.2. Remove the never-called
SendWelcomeEmailBefore removing it I confirmed there is no non-test caller:
git grep SendWelcomeEmailshows only definitions, mocks, stubs and tests. Invited users getSendUserInviteEmail. The method still carried theroleparameter from the removed role model. I removed:email.SenderInterface(internal/email/interfaces.go) and fromSender(templates.go),SMTPSender(smtp_sender.go) andNopSender(nop_sender.go);mocks.MockEmailSenderand from theEmailSenderAPIinterface (internal/mocks/email.go);internal/{api,auth,purchase,scheduler,server};welcomeUserTemplate,welcomeUserHTMLTemplate,WelcomeUserData,RenderWelcomeEmailandRenderWelcomeEmailHTML, which only that method used, plus the tests that pinned them.I also changed four comments that called the invite email the "welcome email" (
internal/auth/service.go,service_user.go,service_user_test.go,internal/email/sender.go/templates.go).Refs #313
Verification
All evidence below is unit, mock or fixture evidence. Item 1 also has local integration evidence on a real migrated Postgres (testcontainers).
Fail-before on main (7b86e38). I copied the integration test and its fixture into a main worktree. On clean main,
TestIntegration_UserColumns_*passes. Then I swappedmfa_secretandmfa_pending_secretinGetUserByID's hand-written list:go test ./internal/auth/stays green (this is the gap the issue describes);TestIntegration_UserColumns_ScanUserRoundTripsEveryColumnfails:MFASecret: "mfa-secret-pending"vs"mfa-secret-enrolled".Mutation probes on this branch (each applied alone, then reverted):
mfa_secret/mfa_pending_secretin the shared constant&mfaSecret/&mfaPendingSecretinscanUserMFASecret/MFAPendingSecretinuserInsertArgs&lastLoginAt/&deactivatedAtinscanUserCombined-tree verification. This branch was tested together with the other queued branches on a local, never-pushed tree:
queue/platform@400d256b= origin/main7b86e386plus these heads, merged in this order:Linux, Go 1.26.9,
AWS_CONFIG_FILE=/dev/null AWS_SHARED_CREDENTIALS_FILE=/dev/null AWS_EC2_METADATA_DISABLED=true; Docker Postgres via testcontainers. The full suite ran onf7c48020, which differs from this tree only by test-only commits on fix/issue-30, fix/issue-713 and fix/issue-263 that replace placeholder account-number literals with named constants:go build ./...,go vet ./...,go vet -tags integration ./...and the fullgo test -race -short -count=1 ./....--build-tags integration.gocyclo -over 10is silent on the changed non-test files.-tags integration -count=1):internal/analytics,internal/api,internal/auth,internal/config,internal/database/postgres/migrations,internal/purchase,internal/schedulerandinternal/serverall pass. Migrations 000149, 000150 and 000151 apply in order on this tree.approval-details,settings-accounts,api) pass (221 tests).accountkey); fixed with named constants. Re-run on this tree: git-secrets, using the repo'sscripts/setup-git-secrets.shpatterns in a fresh repo with an isolated HOME, found nothing in the changed files, and a planted fake key was flagged.scripts/test-git-secrets-allowlist.sh: 183 PASS, 0 FAIL..tftest.hclfiles were not run locally (CI runs them). Nothing was applied to any cloud.Out of scope (deliberately left for later)
users.salt. This has to wait until chore(auth): drop the unused User.Salt field and stop reading or writing users.salt #1514 is deployed everywhere; see the issue thread.redactEmailcopies. That is an owner decision.Labels
Maintainer: please mirror the issue's triage labels onto this PR:
impact/internal,type/chore,triaged,priority/p3,severity/low,urgency/eventually,effort/m.🤖 Generated with Claude Code