console: invites accept any address the person holds (social sign-in 1)
Use holdsAddressTx for invite previews and transactional acceptance. Create membership under the session person when the invitation names an alias. Audited admitMember and seat authorisation: no inv.Address membership or seat key required fixing; the existing person and invite-token keys remain. Cover email/keymail aliases, refused and removed methods, method removal after preview, email sign-in, paid seats, and existing-member acceptance. Validation: invite/admission/seat tests, 107 related regression tests, and go vet ./internal/console pass.
Co-Authored-By: GPT-6 Astra <noreply@openai.com>
internal/console/billingseats.go+2 −1internal/console/invite_held_address_test.go+214 −0internal/console/server.go+7 −8internal/console/store.go+21 −14
Intent
<task-notification> <task-id>bwsr0a5qj</task-id> <tool-use-id>toolu_01DY4g9dcDwGy6kKsGiE4kvL</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/1730ddc5-7bb6-4ebb-ab9b-85efe2e437e3/tasks/bwsr0a5qj.output</output-file> <status>completed</status> <summary>Background command "Run Astra on Task 3" completed (exit code 0)</summary> </task-notification>
<task-notification> <task-id>ad2003f3b101701e7</task-id> <tool-use-id>toolu_01K2Ei7RuwskUe82jv8Knffw</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/1730ddc5-7bb6-4ebb-ab9b-85efe2e437e3/tasks/ad2003f3b101701e7.output</output-file> <status>completed</status> <summary>Agent "Review Task 3 (spec + quality)" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>**Spec:** ✅ Compliant. **Quality:** Approved. **Critical/Important:** none. Two things the diff alone can't settle (⚠️): - **Other places that create a person record.** Spec §9 says "any path", but two store functions also add a person outside sign-in: `SetLastAccount` (`store.go:1565`, used for invited addresses) and `SetOperator` (`store.go:2594`). Neither is a sign-up path. The whole-branch review should confirm that §9 means sign-up paths only. - **The provider sign-in path.** It doesn't exist yet. The task that adds it must go through `finishSignin` or the same budget check. Four minor items, all in the review file: - The Keymail refusal test doesn't check that the page shows the approved refusal text (`newperson_test.go:389`, `:403`). - The code that drops hits older than an hour from the console-wide count is copied from the sign-in email limit (`emailsignin_limits.go:130-136` vs `:250-256`). A small shared helper would serve both. - One test sets the limiter's clock without taking its lock, unlike the other tests (`newperson_test.go:454`). - Behaviour note: a refused email sign-in has already used up its code or link, so the person has to start again. A budget slot is not given back if creating the person then fails. Both err on the side of refusing. Full review: `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/console-social-signin/.superpowers/sdd/2026-11-02-console-social-signin-1-methods/task-3-review.md`</result> <usage><subagent_tokens>66342</subagent_tokens><tool_uses>9</tool_uses><duration_ms>90538</duration_ms></usage> </task-notification>
Attributed to this commit: 13.3 g CO₂e (1,640,042 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-console-social-signin, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/internal/console/billingseats.go b/internal/console/billingseats.go| index 4deb7f2e8..7a6d9bfba 100644 |
| --- a/internal/console/billingseats.go |
| +++ b/internal/console/billingseats.go |
| @@ -199,7 +199,8 @@ var errAdmitRead = errors.New("console: accept: read failed") |
| // membership transition; a billing team's join is admitted under the billing |
| // hold (admitSeatLocked). The error accompanies the outcome: a refusal's |
| // reason (a billingRefusal or a planCapError) with admitRefused, otherwise |
| -// what to log. |
| +// what to log. addr is the session's person; membership and seat counts use |
| +// that person even when the invite names another address they hold. |
| func (s *Server) admitMember(ctx context.Context, acct *Account, token, addr string, now time.Time) (admitOutcome, error) { |
| defer s.lockMembers(acct.Sqid)() |
| inv, err := s.store.PendingInviteFor(token, addr, now) |
diff --git a/internal/console/invite_held_address_test.go b/internal/console/invite_held_address_test.go| new file mode 100644 |
| index 000000000..396ca6525 |
| --- /dev/null |
| +++ b/internal/console/invite_held_address_test.go |
| @@ -0,0 +1,214 @@ |
| +package console |
| + |
| +import ( |
| + "context" |
| + "net/http" |
| + "net/url" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/billing" |
| +) |
| + |
| +func addInviteHeldMethod(t *testing.T, st *Store, kind string, now time.Time) { |
| + t.Helper() |
| + if _, err := st.EnsureUser("person@example.test", now); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := st.db.Exec(`INSERT INTO sign_in_methods (kind, subject, address, added_at) |
| +VALUES (?, ?, ?, ?)`, kind, "alias@example.test", "person@example.test", now.Unix()); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +func wantInviteRole(t *testing.T, st *Store, accountID int64, address, want string) { |
| + t.Helper() |
| + if role, err := st.Role(accountID, address); err != nil || role != want { |
| + t.Fatalf("Role(%d, %q) = %q, %v; want %q", accountID, address, role, err, want) |
| + } |
| +} |
| + |
| +func TestInviteAcceptedByHeldAddress(t *testing.T) { |
| + for _, kind := range []string{MethodEmail, MethodKeymail} { |
| + t.Run(kind, func(t *testing.T) { |
| + st := openTestStore(t) |
| + now := time.Now() |
| + addInviteHeldMethod(t, st, kind, now) |
| + if err := st.CreateAccount(42, "cdef", "A", "owner@example.test", now); err != nil { |
| + t.Fatal(err) |
| + } |
| + token, err := st.CreateInvite(42, "alias@example.test", "owner@example.test", now) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if inv, err := st.PendingInviteFor(token, "person@example.test", now); err != nil || inv.AccountID != 42 || inv.Address != "alias@example.test" { |
| + t.Errorf("PendingInviteFor = %+v, %v", inv, err) |
| + } |
| + if id, err := st.AcceptInvite(token, "person@example.test", now); err != nil || id != 42 { |
| + t.Fatalf("AcceptInvite = %d, %v; want 42, nil", id, err) |
| + } |
| + wantInviteRole(t, st, 42, "person@example.test", RoleMember) |
| + wantInviteRole(t, st, 42, "alias@example.test", "") |
| + if _, err := st.PendingInviteFor(token, "person@example.test", now); err == nil { |
| + t.Error("accepted invite still available for confirmation") |
| + } |
| + if _, err := st.AcceptInvite(token, "person@example.test", now); err == nil { |
| + t.Error("accepted invite worked twice") |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func TestInviteRefusedForUnheldAddress(t *testing.T) { |
| + for _, tc := range []struct { |
| + name, kind, person string |
| + removed bool |
| + }{ |
| + {"stranger", MethodEmail, "stranger@example.test", false}, |
| + {"provider", "google", "person@example.test", false}, |
| + {"removed-email", MethodEmail, "person@example.test", true}, |
| + {"removed-keymail", MethodKeymail, "person@example.test", true}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + st := openTestStore(t) |
| + now := time.Now() |
| + addInviteHeldMethod(t, st, tc.kind, now) |
| + if tc.removed { |
| + if _, err := st.db.Exec(`UPDATE sign_in_methods SET removed_at = ?`, now.Unix()); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + if err := st.CreateAccount(42, "cdef", "A", "owner@example.test", now); err != nil { |
| + t.Fatal(err) |
| + } |
| + token, err := st.CreateInvite(42, "alias@example.test", "owner@example.test", now) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := st.PendingInviteFor(token, tc.person, now); err == nil || err.Error() != "console: that invite cannot be used by "+tc.person { |
| + t.Errorf("PendingInviteFor refusal = %v", err) |
| + } |
| + if _, err := st.AcceptInvite(token, tc.person, now); err == nil { |
| + t.Error("unheld address accepted") |
| + } |
| + wantInviteRole(t, st, 42, tc.person, "") |
| + wantInviteRole(t, st, 42, "alias@example.test", "") |
| + if _, ok := st.PendingInviteAddress(token, now); !ok { |
| + t.Error("refused invite was consumed") |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func TestInviteHeldAddressRecheckedAtAccept(t *testing.T) { |
| + st := openTestStore(t) |
| + now := time.Now() |
| + addInviteHeldMethod(t, st, MethodEmail, now) |
| + if err := st.CreateAccount(42, "cdef", "A", "owner@example.test", now); err != nil { |
| + t.Fatal(err) |
| + } |
| + token, err := st.CreateInvite(42, "alias@example.test", "owner@example.test", now) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := st.PendingInviteFor(token, "person@example.test", now); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := st.db.Exec(`UPDATE sign_in_methods SET removed_at = ?`, now.Unix()); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := st.AcceptInvite(token, "person@example.test", now); err == nil { |
| + t.Error("accept trusted the earlier address check") |
| + } |
| + wantInviteRole(t, st, 42, "person@example.test", "") |
| + wantInviteRole(t, st, 42, "alias@example.test", "") |
| + if _, ok := st.PendingInviteAddress(token, now); !ok { |
| + t.Error("refused invite was consumed") |
| + } |
| +} |
| + |
| +func TestInviteHeldAddressEndToEnd(t *testing.T) { |
| + fx, mail := newEmailFixture(t, true) |
| + now := time.Now() |
| + addInviteHeldMethod(t, fx.st, MethodEmail, now) |
| + accountID := testAccountID() |
| + if err := fx.st.CreateAccount(accountID, "cdef", "A", "owner@example.test", now); err != nil { |
| + t.Fatal(err) |
| + } |
| + token, err := fx.st.CreateInvite(accountID, "alias@example.test", "owner@example.test", now) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + next := "/invite/" + token |
| + c := newBrowser(t) |
| + if status, _, body := get(t, c, fx.ts.URL+next); status != http.StatusOK || !strings.Contains(body, `value="alias@example.test"`) { |
| + t.Fatalf("signed-out invite = %d, missing alias prefill", status) |
| + } |
| + lookupAnswers(fx, "alias@example.test", http.StatusNotFound) |
| + code, _ := askSignin(t, fx, mail, c, "alias@example.test", next) |
| + if status, loc, _ := postCode(t, fx, c, code); status != http.StatusSeeOther || loc != next { |
| + t.Fatalf("sign-in = %d -> %q; want 303 -> %q", status, loc, next) |
| + } |
| + raw := emailSession(t, fx, c, "person@example.test") |
| + if status, _, body := get(t, c, fx.ts.URL+next); status != http.StatusOK || !strings.Contains(body, `action="`+next+`"`) { |
| + t.Fatalf("invite page = %d, missing confirm form", status) |
| + } |
| + wantInviteRole(t, fx.st, accountID, "person@example.test", "") |
| + if status, _, _ := postForm(t, c, fx.ts.URL+next, url.Values{}); status != http.StatusForbidden { |
| + t.Fatalf("accept without CSRF = %d; want 403", status) |
| + } |
| + wantInviteRole(t, fx.st, accountID, "person@example.test", "") |
| + if status, loc, _ := postForm(t, c, fx.ts.URL+next, url.Values{"csrf": {raw}}); status != http.StatusSeeOther || loc != "/a/cdef/" { |
| + t.Fatalf("accept = %d -> %q; want 303 -> /a/cdef/", status, loc) |
| + } |
| + wantInviteRole(t, fx.st, accountID, "person@example.test", RoleMember) |
| + wantInviteRole(t, fx.st, accountID, "alias@example.test", "") |
| + if id, err := fx.st.LastAccount("person@example.test"); err != nil || id != accountID { |
| + t.Fatalf("LastAccount = %d, %v; want %d", id, err, accountID) |
| + } |
| + if status, _, _ := get(t, c, fx.ts.URL+"/a/cdef/"); status != http.StatusOK { |
| + t.Fatalf("joined account = %d; want 200", status) |
| + } |
| +} |
| + |
| +func TestInviteSeatPathHeldAddress(t *testing.T) { |
| + o := newSeatsFixture(t, 10, 10) |
| + now := time.Now() |
| + addInviteHeldMethod(t, o.st, MethodEmail, now) |
| + token := o.authorisedInvite(t, "alias@example.test") |
| + out, err := o.srv.admitMember(context.Background(), o.acct, token, "person@example.test", now) |
| + if err != nil || out != admitJoined { |
| + t.Fatalf("admitMember = %v, %v; want joined", out, err) |
| + } |
| + wantInviteRole(t, o.st, o.acct.ID, "person@example.test", RoleMember) |
| + wantInviteRole(t, o.st, o.acct.ID, "alias@example.test", "") |
| + if o.members(t) != 11 || o.seatQty(t) != 11 { |
| + t.Fatalf("members %d seats %d; want 11 and 11", o.members(t), o.seatQty(t)) |
| + } |
| + op := o.lastOp(t) |
| + if op.Kind != opSeat || op.State != opApplied || op.InviteToken != token || op.AuthorisedBy != token || |
| + op.StartQuantity == nil || *op.StartQuantity != 10 || changeBodyOf(t, op.Prepared).Proration != billing.ProrateNow { |
| + t.Fatalf("seat op = %+v", op) |
| + } |
| + if a := o.authorisation(t, token); a == nil || a.ConsumedAt.IsZero() { |
| + t.Fatalf("authorisation not consumed: %+v", a) |
| + } |
| + if b := o.billingRow(t); b.PaidSeats != 11 || b.Seats != 11 { |
| + t.Fatalf("billing row seats %d paid %d; want 11 and 11", b.Seats, b.PaidSeats) |
| + } |
| + if o.pendingInvite(t, token) { |
| + t.Fatal("joined invite still pending") |
| + } |
| + o.reset() |
| + second := o.authorisedInvite(t, "alias@example.test") |
| + if out, err := o.srv.admitMember(context.Background(), o.acct, second, "person@example.test", now); err != nil || out != admitJoined { |
| + t.Fatalf("existing member accept = %v, %v; want joined", out, err) |
| + } |
| + if o.members(t) != 11 || o.seatQty(t) != 11 || o.counts()["Send"] != 0 { |
| + t.Fatalf("existing member changed seats: members %d seats %d calls %v", o.members(t), o.seatQty(t), o.counts()) |
| + } |
| + if a := o.authorisation(t, second); a == nil || !a.ConsumedAt.IsZero() { |
| + t.Fatalf("existing member consumed a seat authorisation: %+v", a) |
| + } |
| +} |
diff --git a/internal/console/server.go b/internal/console/server.go| index 1883966c3..d656f6044 100644 |
| --- a/internal/console/server.go |
| +++ b/internal/console/server.go |
| @@ -3595,11 +3595,10 @@ func (s *Server) invitationGone(w http.ResponseWriter, r *http.Request) { |
| // top-level navigation (discussion #219, item 4). Links already sent keep |
| // working; they land on this page. |
| // |
| -// It requires a session as the invited address: the link reaches one |
| -// address and is worthless to anyone else. Signed out, it is the front page |
| -// with the invited address filled in and next set back to this link, so |
| -// either sign-in door returns here (spec 8). An unknown or spent token gets |
| -// the plain front page. |
| +// It requires a session for a person who holds the invited address. |
| +// Signed out, it is the front page with the invited address filled in and |
| +// next set back to this link, so either sign-in door returns here (spec 8). |
| +// An unknown or spent token gets the plain front page. |
| func (s *Server) handleInvitePage(w http.ResponseWriter, r *http.Request) { |
| token := r.PathValue("token") |
| addr, raw, ok := s.session(r) |
| @@ -3642,9 +3641,9 @@ func (s *Server) handleInvitePage(w http.ResponseWriter, r *http.Request) { |
| // handleAcceptInvite is the confirm page's button: it consumes the invite and |
| // makes the account the person's current one. Session, then CSRF, then the |
| -// invite's own gates (AcceptInvite: unused, addressed to this session, |
| -// unexpired), which play the owner check's part. No passkey step: joining |
| -// gives the joiner nothing over anybody else, and it is their own choice. |
| +// invite's own gates (AcceptInvite: unused, addressed to an address the person |
| +// holds, unexpired), which play the owner check's part. No passkey step: |
| +// joining gives the joiner nothing over anybody else, and it is their own choice. |
| func (s *Server) handleAcceptInvite(w http.ResponseWriter, r *http.Request) { |
| addr, raw, ok := s.session(r) |
| if !ok { |
diff --git a/internal/console/store.go b/internal/console/store.go| index 12cc689af..ef5b7328c 100644 |
| --- a/internal/console/store.go |
| +++ b/internal/console/store.go |
| @@ -1599,10 +1599,10 @@ VALUES (?, ?, ?, ?, ?, ?)`, |
| } |
| // PendingInviteFor reads an invite without consuming it, behind the same |
| -// three gates AcceptInvite applies: unaccepted, addressed to address, and |
| -// unexpired. Any failure is one error, so the confirm page that shows it can |
| -// answer every refusal the same way. |
| -func (s *Store) PendingInviteFor(token, address string, now time.Time) (*Invite, error) { |
| +// three gates AcceptInvite applies: unaccepted, addressed to an address the |
| +// person holds, and unexpired. Any refusal gets the same error, so the |
| +// confirm page can answer every refusal the same way. |
| +func (s *Store) PendingInviteFor(token, person string, now time.Time) (*Invite, error) { |
| var i Invite |
| var created, expires, accepted int64 |
| err := s.db.QueryRow(`SELECT token, account_id, address, invited_by, created_at, expires_at, accepted_at |
| @@ -1610,8 +1610,12 @@ FROM invites WHERE token = ?`, token).Scan(&i.Token, &i.AccountID, &i.Address, & |
| if err != nil { |
| return nil, err |
| } |
| - if accepted != 0 || i.Address != address || now.Unix() > expires { |
| - return nil, fmt.Errorf("console: that invite cannot be used by %s", address) |
| + holds, err := holdsAddressTx(s.db, person, i.Address) |
| + if err != nil { |
| + return nil, err |
| + } |
| + if accepted != 0 || !holds || now.Unix() > expires { |
| + return nil, fmt.Errorf("console: that invite cannot be used by %s", person) |
| } |
| i.CreatedAt = time.Unix(created, 0).UTC() |
| i.ExpiresAt = time.Unix(expires, 0).UTC() |
| @@ -1634,16 +1638,15 @@ func (s *Store) PendingInviteAddress(token string, now time.Time) (string, bool) |
| // AcceptInvite consumes an invite and creates the membership, in one |
| // transaction. Three gates, all inside it: the token must be unaccepted, the |
| -// address must be the one it was addressed to (an invite is not a bearer |
| -// token — the link lands in ONE keymail inbox and only that identity can use |
| -// it), and it must not have expired. |
| -func (s *Store) AcceptInvite(token, address string, now time.Time) (int64, error) { |
| +// person must hold the invited address, and it must not have expired. |
| +// The membership belongs to the person, even when the invite names an alias. |
| +func (s *Store) AcceptInvite(token, person string, now time.Time) (int64, error) { |
| tx, err := s.db.Begin() |
| if err != nil { |
| return 0, err |
| } |
| defer tx.Rollback() |
| - accountID, err := acceptInviteTx(tx, token, address, now) |
| + accountID, err := acceptInviteTx(tx, token, person, now) |
| if err != nil { |
| return 0, err |
| } |
| @@ -1655,7 +1658,7 @@ func (s *Store) AcceptInvite(token, address string, now time.Time) (int64, error |
| // acceptInviteTx is AcceptInvite inside the caller's transaction (a |
| // MembershipTransition write), with the same three gates. It never commits. |
| -func acceptInviteTx(tx *sql.Tx, token, address string, now time.Time) (int64, error) { |
| +func acceptInviteTx(tx *sql.Tx, token, person string, now time.Time) (int64, error) { |
| var accountID, expires, accepted int64 |
| var want string |
| err := tx.QueryRow(`SELECT account_id, address, expires_at, accepted_at FROM invites WHERE token = ?`, |
| @@ -1669,7 +1672,11 @@ func acceptInviteTx(tx *sql.Tx, token, address string, now time.Time) (int64, er |
| if accepted != 0 { |
| return 0, fmt.Errorf("console: that invite has already been used") |
| } |
| - if want != address { |
| + holds, err := holdsAddressTx(tx, person, want) |
| + if err != nil { |
| + return 0, err |
| + } |
| + if !holds { |
| return 0, fmt.Errorf("console: that invite was sent to a different address") |
| } |
| if now.Unix() > expires { |
| @@ -1681,7 +1688,7 @@ func acceptInviteTx(tx *sql.Tx, token, address string, now time.Time) (int64, er |
| // An invite always grants member; owners are promoted deliberately. |
| if _, err := tx.Exec(`INSERT INTO memberships (account_id, address, role, added_at) |
| VALUES (?, ?, ?, ?) ON CONFLICT(account_id, address) DO NOTHING`, |
| - accountID, address, RoleMember, now.Unix()); err != nil { |
| + accountID, person, RoleMember, now.Unix()); err != nil { |
| return 0, err |
| } |
| return accountID, nil |