Sheets team mode: Fable's round-1 blockers and Paul's orphan ruling
Blocker 1: the revoke notice names a Home-only member by Label, not a blank address. Blocker 2: tests for identity()'s Home-only fallback (chrome and /signin), the dashboard feed in team mode (members, removed, Unknown — its Unknown guard is now one check after listing), the foreign-issuer census, and a known Home-only member arriving over another local session. Paul's ruling (2026-10-28): a roster owner holds owner on any sheet with no live owner grant (team_owner.go, lastowner.go note, spec §8.2 and §14). Home-only members show "Oficina account …<ref>"; roster is a direct dependency; grantsOn and stillReaches take the request's context.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
14 files changed,
+385
−28
docs/superpowers/specs/2026-08-30-sheets-design.md+9 −0go.mod+1 −1internal/sheets/dashboard.go+4 −7internal/sheets/grants.go+14 −2internal/sheets/grants_orphan_test.go+2 −2internal/sheets/handlers_history.go+6 −0internal/sheets/handlers_share.go+5 −4internal/sheets/lastowner.go+8 −0internal/sheets/sharenotice.go+7 −4internal/sheets/team_access_test.go+2 −2internal/sheets/team_answers.go+46 −5internal/sheets/team_fixture_test.go+8 −1internal/sheets/team_owner.go+48 −0internal/sheets/team_review_test.go+225 −0
CI passed — run details
Intent
diff --git a/docs/superpowers/specs/2026-08-30-sheets-design.md b/docs/superpowers/specs/2026-08-30-sheets-design.md| index 2db5cec..1220b06 100644 |
| --- a/docs/superpowers/specs/2026-08-30-sheets-design.md |
| +++ b/docs/superpowers/specs/2026-08-30-sheets-design.md |
| @@ -466,6 +466,14 @@ a grant they gave themselves; in team mode that grant is the team rung's and |
| counts only while the roster says Member, as Docs' `owner_id` does — grants |
| somebody else gave are shares and keep working. A database once activated in |
| team mode refuses to boot without the same team binding. |
| +**Team owners can share orphaned sheets** (RULED by Paul, 2026-10-28, #52): |
| +a roster *owner* holds `owner` on any sheet with no live owner grant — live |
| +meaning given by somebody else, or held by a current roster Member (or one |
| +whose standing cannot be read). Nothing is written; it stops applying once |
| +the sheet has a live owner again (`team_owner.go`). A Home-only member has no |
| +address, so nothing can be shared *to* one: once removed, nothing can be |
| +re-shared to them either. Home-only members are shown as "Oficina account" |
| +and the last four characters of their person ref, as Home's Team page does. |
| **Per-sheet roles stay here.** The doctrine deliberately does not unify |
| them: a shared role vocabulary designed from three specs at once would fit |
| none of them, and it may move to the contract module when two apps have |
| @@ -1129,6 +1137,7 @@ it is a fallback rather than a scramble. |
| | Moving the provisioning queue out of the home (§9.4) | The home spec rules on it | |
| | **Destructive sort — physically reordering rows** | calc's dependency graph is keyed on POSITION (`store/handle.go`'s `cellKey` builds `CellKey{rowPos+1, colPos+1}`), so moving a row changes what every existing formula points at, silently. Plan 1's review flagged this as "valid only until rows move". Trigger: **calc's key space rebuilt on stable ids**, which is a subsystem and not a feature. Sort and filter ship non-destructively meanwhile — they reorder what is displayed and never what is stored, which is correct rather than a stopgap. | |
| | **Importing a workbook's second and later worksheets** | `xlsx.Import` reads `GetSheetList()[0]` and stops, so a three-worksheet file becomes a one-tab sheet. Stated in the import form's own hint rather than discovered afterwards (§11), because a workbook that arrives looking whole is the quiet kind of wrong PRODUCT.md's first principle forbids. Trigger: **a second tab is reachable in the UI**. Sheets already has a `Tab` table and `SheetSummary.TabID` already means "the first tab", but nothing creates, names, lists or switches tabs — so importing into tabs today would write rows no screen can open, which is worse than importing one worksheet honestly. | |
| +| ~~Sharing a sheet whose sole owner left the team~~ | **Ruled and built 2026-10-28** (Paul, oficina/sheets #52). Team mode made it routine: a removed creator's own grant stops counting, so the team could edit the sheet and nobody could share it. A roster owner now holds `owner` on any sheet with no live owner grant (§8.2, `team_owner.go`). Still not built: an explicit, auditable "Take ownership" verb that writes a grant — trigger: **a team asks who rescued a sheet**, or the rule needs to outlive a roster owner's own removal. | |
| | Pivot tables | Asked for twice | |
| | Rich presence beyond who's-here | Teams above ~5 concurrent editors | |
| | Offline editing | — | |
diff --git a/go.mod b/go.mod| index ae3e87a..3a08496 100644 |
| --- a/go.mod |
| +++ b/go.mod |
| @@ -7,6 +7,7 @@ require ( |
| amadan.net/oficina/home/connect v0.0.0-20261024233715-ff16bf56bc4d |
| amadan.net/oficina/home/dashboard v0.0.0-20261024234842-3774eb68f816 |
| amadan.net/oficina/home/handoff v0.0.0-20261024233715-ff16bf56bc4d |
| + amadan.net/oficina/home/roster v0.0.0-20260908123429-74dda570e0cf |
| amadan.net/rastrillo/rastrillo v0.27.1-0.20261006204347-fb806a287060 |
| github.com/carlosframework/rastrillo v0.23.0 |
| github.com/chromedp/cdproto v0.0.0-20250724212937-08a3db8b4327 |
| @@ -18,7 +19,6 @@ require ( |
| ) |
| require ( |
| - amadan.net/oficina/home/roster v0.0.0-20260908123429-74dda570e0cf // indirect |
| amadan.net/rastrillo/rastrillo/money v0.1.0 // indirect |
| github.com/BurntSushi/toml v1.6.0 // indirect |
| github.com/chromedp/sysutil v1.1.0 // indirect |
diff --git a/internal/sheets/dashboard.go b/internal/sheets/dashboard.go| index 0b23688..469239d 100644 |
| --- a/internal/sheets/dashboard.go |
| +++ b/internal/sheets/dashboard.go |
| @@ -51,18 +51,15 @@ func (a *App) dashboardDocuments(ctx context.Context, id int64, subject string, |
| } |
| if a.team != nil { |
| // The roster's standing for the subject that asked, never the |
| - // stored team_role (team_access.go). Unknown is unavailable, not |
| - // a short list. |
| - t := &teamAccess{member: viewer, subject: subject, decision: a.team.check(ctx, subject)} |
| - if t.state() == roster.Unknown { |
| - return dashboard.Response{}, dashboard.ErrUnavailable |
| - } |
| - viewer = t.actor() |
| + // stored team_role (team_access.go). |
| + viewer = (&teamAccess{member: viewer, subject: subject, decision: a.team.check(ctx, subject)}).actor() |
| } |
| rows, e := a.visibleSheetsLimited(ctx, viewer, dashboard.MaxItems+1) |
| if e != nil { |
| return dashboard.Response{}, e |
| } |
| + // Unknown standing is unavailable, not a short list. Asked after |
| + // listing, as the sheet list does, because a lease can lapse during it. |
| if a.team != nil && viewer.team.state() == roster.Unknown { |
| return dashboard.Response{}, dashboard.ErrUnavailable |
| } |
diff --git a/internal/sheets/grants.go b/internal/sheets/grants.go| index 45690da..63c0ab8 100644 |
| --- a/internal/sheets/grants.go |
| +++ b/internal/sheets/grants.go |
| @@ -34,6 +34,18 @@ var errNoAccess = errors.New("sheets: no grant") |
| // A guest gets NOTHING from step 2. That is the whole distinction in |
| // §8.2: a guest sees exactly the sheets granted to them. |
| func (a *App) roleFor(sheetID uint64, m Member) (SheetRole, bool) { |
| + role, ok := a.grantOrTeamRole(sheetID, m) |
| + if ok && role != SheetOwner && a.orphanedForRosterOwner(sheetID, m) { |
| + // Team mode: a roster owner holds every sheet nobody live owns |
| + // (team_owner.go; Paul, 2026-10-28). |
| + return SheetOwner, true |
| + } |
| + return role, ok |
| +} |
| + |
| +// grantOrTeamRole is roleFor's two sources, before team mode's |
| +// roster-owner rule. |
| +func (a *App) grantOrTeamRole(sheetID uint64, m Member) (SheetRole, bool) { |
| if a.db == nil { |
| return "", false |
| } |
| @@ -117,7 +129,7 @@ type sharedWith struct { |
| Role SheetRole |
| } |
| -func (a *App) grantsOn(sheetID uint64) ([]sharedWith, error) { |
| +func (a *App) grantsOn(ctx context.Context, sheetID uint64) ([]sharedWith, error) { |
| if a.db == nil { |
| return nil, errNoDB |
| } |
| @@ -131,7 +143,7 @@ func (a *App) grantsOn(sheetID uint64) ([]sharedWith, error) { |
| if err := a.db.Where("id = ?", g.MemberID).First(&m).Error; err != nil { |
| continue // a grant whose member vanished names nobody |
| } |
| - out = append(out, sharedWith{Member: a.withStanding(context.Background(), m), Role: SheetRole(g.Role)}) |
| + out = append(out, sharedWith{Member: a.withStanding(ctx, m), Role: SheetRole(g.Role)}) |
| } |
| return out, nil |
| } |
diff --git a/internal/sheets/grants_orphan_test.go b/internal/sheets/grants_orphan_test.go| index 747ea6a..9f309c4 100644 |
| --- a/internal/sheets/grants_orphan_test.go |
| +++ b/internal/sheets/grants_orphan_test.go |
| @@ -40,7 +40,7 @@ func TestAnOwnerCannotDemoteThemselvesToNobody(t *testing.T) { |
| } |
| // Whatever the screen says, the sheet must still have an owner. |
| - people, err := app.grantsOn(s.ID) |
| + people, err := app.grantsOn(t.Context(), s.ID) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -81,7 +81,7 @@ func TestOneOfTwoOwnersCanBeDemoted(t *testing.T) { |
| t.Fatalf("share POST = %d, want 303", rec.Code) |
| } |
| - people, err := app.grantsOn(s.ID) |
| + people, err := app.grantsOn(t.Context(), s.ID) |
| if err != nil { |
| t.Fatal(err) |
| } |
diff --git a/internal/sheets/handlers_history.go b/internal/sheets/handlers_history.go| index a52ae0f..7ba28df 100644 |
| --- a/internal/sheets/handlers_history.go |
| +++ b/internal/sheets/handlers_history.go |
| @@ -1,6 +1,7 @@ |
| package sheets |
| import ( |
| + "context" |
| "net/http" |
| "strconv" |
| "time" |
| @@ -115,7 +116,12 @@ func (a *App) memberNames() map[uint64]string { |
| if err := a.db.Find(&members).Error; err != nil { |
| return out |
| } |
| + refs := a.homeOnlyRefs(context.Background()) |
| for _, m := range members { |
| + if subject, ok := refs[m.ID]; ok && m.Address == "" { |
| + out[m.ID] = homeOnlyLabel(subject) |
| + continue |
| + } |
| out[m.ID] = m.Label() |
| } |
| return out |
diff --git a/internal/sheets/handlers_share.go b/internal/sheets/handlers_share.go| index f59a0fb..3bcf432 100644 |
| --- a/internal/sheets/handlers_share.go |
| +++ b/internal/sheets/handlers_share.go |
| @@ -1,6 +1,7 @@ |
| package sheets |
| import ( |
| + "context" |
| "errors" |
| "net/http" |
| "strconv" |
| @@ -67,7 +68,7 @@ func (a *App) handleShare(w http.ResponseWriter, r *http.Request) { |
| // handler that just minted it, in the same process, on the same |
| // goroutine. Nothing that crossed a URL can reach this parameter. |
| func (a *App) renderShare(w http.ResponseWriter, r *http.Request, s SheetSummary, _ Member, notice, newLink string) { |
| - people, err := a.grantsOn(s.ID) |
| + people, err := a.grantsOn(r.Context(), s.ID) |
| if err != nil { |
| a.fail(w, r, err) |
| return |
| @@ -193,7 +194,7 @@ func (a *App) handleShareRevoke(w http.ResponseWriter, r *http.Request) { |
| a.fail(w, r, err) |
| return |
| } |
| - if a.stillReaches(s.ID, memberID) { |
| + if a.stillReaches(r.Context(), s.ID, memberID) { |
| a.shareRedirectAbout(w, r, s, noticeRevokedTeam, memberID) |
| return |
| } |
| @@ -202,8 +203,8 @@ func (a *App) handleShareRevoke(w http.ResponseWriter, r *http.Request) { |
| // wouldOrphan reports whether removing this grant would leave the sheet |
| // with no owner at all. |
| -func (a *App) wouldOrphan(sheetID, memberID uint64) bool { |
| - people, err := a.grantsOn(sheetID) |
| +func (a *App) wouldOrphan(ctx context.Context, sheetID, memberID uint64) bool { |
| + people, err := a.grantsOn(ctx, sheetID) |
| if err != nil { |
| return true // cannot tell means do not risk it |
| } |
diff --git a/internal/sheets/lastowner.go b/internal/sheets/lastowner.go| index 5ee9ca1..38d4ca3 100644 |
| --- a/internal/sheets/lastowner.go |
| +++ b/internal/sheets/lastowner.go |
| @@ -31,6 +31,14 @@ var errLastOwner = errors.New("sheets: a sheet needs an owner") |
| // owners demoting each other concurrently both counted two, both passed, |
| // and both wrote. SQLite serialises the writes; it does not serialise a |
| // read against someone else's later write. |
| +// |
| +// It counts owner grant ROWS, not live owners. In team mode a departed |
| +// creator's own grant is dead (ownGrantIgnored) yet still counts here, and |
| +// a roster owner's SheetOwner over an orphaned sheet (team_owner.go) holds |
| +// no row and does not. So a roster owner rescuing an orphaned sheet gives |
| +// somebody an owner grant first; only then can the dead one be revoked. |
| +// Counting live owners instead would need the roster inside this |
| +// transaction, which the writer must never wait on. |
| func lastOwnerGoing(tx *gorm.DB, sheetID, memberID uint64, newRole SheetRole) (bool, error) { |
| if newRole == SheetOwner { |
| return false, nil // not going anywhere |
diff --git a/internal/sheets/sharenotice.go b/internal/sheets/sharenotice.go| index 4026769..cefba2d 100644 |
| --- a/internal/sheets/sharenotice.go |
| +++ b/internal/sheets/sharenotice.go |
| @@ -35,14 +35,14 @@ const revokedTeamText = "The explicit permission is removed, but since they are |
| // Asked AFTER the revoke, and asked of roleFor rather than reasoned |
| // about separately, so the notice reports what the gate actually says |
| // instead of holding a second opinion that can drift from it. |
| -func (a *App) stillReaches(sheetID, memberID uint64) bool { |
| +func (a *App) stillReaches(ctx context.Context, sheetID, memberID uint64) bool { |
| m, ok := a.memberByID(memberID) |
| if !ok { |
| // The grant is gone and we cannot tell what is left. The plain |
| // sentence is the one that claims less. |
| return false |
| } |
| - _, still := a.roleFor(sheetID, a.withStanding(context.Background(), m)) |
| + _, still := a.roleFor(sheetID, a.withStanding(ctx, m)) |
| return still |
| } |
| @@ -66,10 +66,13 @@ func (a *App) revokedTeamNotice(r *http.Request, sheetID uint64) string { |
| return revokedTeamText |
| } |
| m, ok := a.memberByID(id) |
| - if !ok || !a.stillReaches(sheetID, m.ID) { |
| + if ok { |
| + m = a.withStanding(r.Context(), m) // for Label's Home-only ref |
| + } |
| + if !ok || !a.stillReaches(r.Context(), sheetID, m.ID) { |
| return revokedTeamText |
| } |
| - return "The explicit permission is removed, but since " + m.Address + |
| + return "The explicit permission is removed, but since " + m.Label() + |
| " is on the team, they still have access." |
| } |
diff --git a/internal/sheets/team_access_test.go b/internal/sheets/team_access_test.go| index 6f026cb..17e98f7 100644 |
| --- a/internal/sheets/team_access_test.go |
| +++ b/internal/sheets/team_access_test.go |
| @@ -121,7 +121,7 @@ func TestTeamStandingIsTheRostersNeverTheStoredRole(t *testing.T) { |
| t.Fatalf("linked roster owner by Home session = %d, want 200", rec.Code) |
| } |
| paul := f.viewer(t) |
| - if !f.app.stillReaches(plan.ID, paul.ID) { |
| + if !f.app.stillReaches(t.Context(), plan.ID, paul.ID) { |
| t.Error("the share screen says a roster owner cannot reach a team sheet") |
| } |
| if m := f.viewer(t); m.TeamRole != string(TeamOwner) { |
| @@ -161,7 +161,7 @@ func TestTeamStandingIsTheRostersNeverTheStoredRole(t *testing.T) { |
| if rec := f.get(t, sheetPath(plan.ID)); rec.Code != http.StatusNotFound { |
| t.Errorf("removed linked member = %d, want 404", rec.Code) |
| } |
| - if f.app.stillReaches(plan.ID, paul.ID) { |
| + if f.app.stillReaches(t.Context(), plan.ID, paul.ID) { |
| t.Error("the share screen says a removed member still reaches a team sheet") |
| } |
| if rec := f.get(t, sheetPath(shared.ID)); rec.Code != http.StatusOK { |
diff --git a/internal/sheets/team_answers.go b/internal/sheets/team_answers.go| index a35b076..33f5a15 100644 |
| --- a/internal/sheets/team_answers.go |
| +++ b/internal/sheets/team_answers.go |
| @@ -5,6 +5,7 @@ package sheets |
| // addressless member is shown by. Each is a no-op outside team mode. |
| import ( |
| + "context" |
| "net/http" |
| "strconv" |
| "strings" |
| @@ -84,12 +85,52 @@ func (a *App) streamAccess(r *http.Request, sheetID uint64) (bool, time.Duration |
| // address would be: a share list row, a history author. |
| const teamLabel = "Oficina account" |
| -// Label is the address, or teamLabel for a member who has none. Only a |
| -// team-mode Home-only member can lack one: memberFor refuses to mint an |
| -// addressless member, so outside team mode this is always Address. |
| +// Label is the address, or for a member who has none — only a team-mode |
| +// Home-only member can lack one, since memberFor refuses to mint an |
| +// addressless member — teamLabel and the last four characters of their |
| +// person ref when the roster lookup supplied it ("Oficina account …k7qz", |
| +// as Home's Team page shows a ref). Outside team mode this is always |
| +// Address. |
| func (m Member) Label() string { |
| - if strings.TrimSpace(m.Address) == "" { |
| + if strings.TrimSpace(m.Address) != "" { |
| + return m.Address |
| + } |
| + if m.team != nil { |
| + return homeOnlyLabel(m.team.subject) |
| + } |
| + return teamLabel |
| +} |
| + |
| +func homeOnlyLabel(subject string) string { |
| + if len(subject) <= 4 { |
| return teamLabel |
| } |
| - return m.Address |
| + return teamLabel + " …" + subject[len(subject)-4:] |
| +} |
| + |
| +// homeOnlyRefs maps each Home-only member to its subject, for labels on |
| +// pages that list members without asking the roster (history). Nil |
| +// outside team mode or on a read failure, which only costs the suffix. |
| +func (a *App) homeOnlyRefs(ctx context.Context) map[uint64]string { |
| + if a.team == nil { |
| + return nil |
| + } |
| + rows, err := a.team.db.QueryContext(ctx, "SELECT member_id, subject FROM sheets_team_home_members WHERE issuer=?", a.team.bindings.Issuer) |
| + if err != nil { |
| + return nil |
| + } |
| + defer rows.Close() |
| + out := map[uint64]string{} |
| + for rows.Next() { |
| + var id uint64 |
| + var subject string |
| + if rows.Scan(&id, &subject) != nil { |
| + return nil |
| + } |
| + out[id] = subject |
| + } |
| + if rows.Err() != nil { |
| + return nil |
| + } |
| + return out |
| } |
diff --git a/internal/sheets/team_fixture_test.go b/internal/sheets/team_fixture_test.go| index c579e6c..46bb550 100644 |
| --- a/internal/sheets/team_fixture_test.go |
| +++ b/internal/sheets/team_fixture_test.go |
| @@ -142,9 +142,16 @@ type teamFixture struct { |
| // newTeamFixture is a team-mode instance. owners is SHEETS_OWNERS, which |
| // in team mode only admits local sign-in; pass none for Alta's shape. |
| func newTeamFixture(t *testing.T, owners ...string) *teamFixture { |
| + t.Helper() |
| + return newTeamFixtureWith(t, "", owners...) |
| +} |
| + |
| +// newTeamFixtureWith sets HOME_DIRECTORY_ORIGIN too, which the dashboard |
| +// feed needs. |
| +func newTeamFixtureWith(t *testing.T, directory string, owners ...string) *teamFixture { |
| t.Helper() |
| app, _ := appWithSchema(t, testOrigin, TeamBootSchema, owners...) |
| - f := homeOn(t, app, "") |
| + f := homeOn(t, app, directory) |
| cfg, dir := teamConfigFor(t, teamTestBindings()) |
| clock := &teamTestClock{base: time.Now()} |
| cfg.clock = clock |
diff --git a/internal/sheets/team_owner.go b/internal/sheets/team_owner.go| new file mode 100644 |
| index 0000000..55143de |
| --- /dev/null |
| +++ b/internal/sheets/team_owner.go |
| @@ -0,0 +1,48 @@ |
| +package sheets |
| + |
| +// Team mode's roster-owner rule — RULED by Paul, 2026-10-28, on |
| +// oficina/sheets #52: team owners can share orphaned sheets. |
| +// |
| +// A sheet's ownership is its owner grants. In team mode the creator's own |
| +// grant counts only while the roster says Member (ownGrantIgnored), so |
| +// removing a sheet's sole owner from the team leaves a sheet the team can |
| +// still edit and nobody can share. A roster owner therefore holds |
| +// SheetOwner on any sheet with no live owner grant, where live means |
| +// given by somebody else (a share), or held by somebody the roster says |
| +// is a Member — or whose standing cannot be read right now, which is not |
| +// "gone". Nothing is written: the moment the roster owner gives somebody |
| +// an owner grant, or the departed owner is re-added, the sheet has a live |
| +// owner again and this rule stops applying. |
| + |
| +import ( |
| + "context" |
| + |
| + "amadan.net/oficina/home/roster" |
| +) |
| + |
| +// orphanedForRosterOwner reports whether m is a roster owner and the sheet |
| +// has no live owner grant. Outside team mode it is always false. It asks |
| +// the roster about each owner grant holder, never under the SQLite writer: |
| +// roleFor is not called inside a transaction. |
| +func (a *App) orphanedForRosterOwner(sheetID uint64, m Member) bool { |
| + if a.team == nil || a.teamRole(m) != TeamOwner { |
| + return false |
| + } |
| + var owners []Grant |
| + if err := a.db.Where("sheet_id = ? AND role = ?", sheetID, string(SheetOwner)).Find(&owners).Error; err != nil { |
| + return false // cannot tell is not orphaned |
| + } |
| + for _, g := range owners { |
| + if g.GrantedBy != g.MemberID { |
| + return false // a share: live whatever the roster says |
| + } |
| + holder, ok := a.memberByID(g.MemberID) |
| + if !ok { |
| + return false |
| + } |
| + if a.withStanding(context.Background(), holder).team.state() != roster.NotMember { |
| + return false // a current Member, or standing unknown |
| + } |
| + } |
| + return true |
| +} |
diff --git a/internal/sheets/team_review_test.go b/internal/sheets/team_review_test.go| new file mode 100644 |
| index 0000000..eb36c3b |
| --- /dev/null |
| +++ b/internal/sheets/team_review_test.go |
| @@ -0,0 +1,225 @@ |
| +package sheets |
| + |
| +import ( |
| + "errors" |
| + "net/http" |
| + "net/http/httptest" |
| + "net/url" |
| + "strconv" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/home/dashboard" |
| + "github.com/go-json-experiment/json" |
| + |
| + "amadan.net/oficina/sheets/internal/sheets/teamstate" |
| +) |
| + |
| +// Tests added for Fable's review of #52: each kills a mutant that had |
| +// survived the first round. |
| + |
| +func (f *teamFixture) getHTML(t *testing.T, path string) *httptest.ResponseRecorder { |
| + t.Helper() |
| + r := httptest.NewRequest("GET", testOrigin+path, nil) |
| + r.Header.Set("Accept", "text/html") |
| + for _, c := range f.jar { |
| + r.AddCookie(c) |
| + } |
| + w := httptest.NewRecorder() |
| + f.app.Router().ServeHTTP(w, r) |
| + return w |
| +} |
| + |
| +// A Home-only member is signed in as far as the chrome is concerned: the |
| +// account menu and its Sign out render, and /signin sends them on. |
| +func TestTeamHomeOnlyMemberGetsSignedInChrome(t *testing.T) { |
| + f := newTeamFixture(t) |
| + f.dir.set(teamSubject('a'), "member") |
| + f.signInHome(t, teamSubject('a')) |
| + page := f.getHTML(t, "/sheets") |
| + if page.Code != http.StatusOK || !strings.Contains(page.Body.String(), `action="/signout"`) { |
| + t.Fatalf("Home-only member's list = %d without the account menu's sign out", page.Code) |
| + } |
| + if strings.Contains(page.Body.String(), `href="/signin`) { |
| + t.Error("a signed-in Home-only member was offered Sign in") |
| + } |
| + if rec := f.get(t, "/signin"); rec.Code != http.StatusSeeOther { |
| + t.Errorf("/signin for a signed-in Home-only member = %d, want 303", rec.Code) |
| + } |
| +} |
| + |
| +// The dashboard feed asks the roster: team sheets while a member, shares |
| +// only once removed, unavailable — not short — under Unknown. |
| +func TestTeamDashboardFeedFollowsTheRoster(t *testing.T) { |
| + t.Setenv("OFICINA_DASHBOARD_TEAM", "blue") |
| + f := newTeamFixtureWith(t, "https://oficina.example.test") |
| + a := teamSubject('a') |
| + f.dir.set(a, "member") |
| + f.signInHome(t, a) |
| + teamSheet(t, f, "Team plan") |
| + shared := teamSheet(t, f, "Shared") |
| + id, err := teamstate.HomeMember(t.Context(), f.app.team.db, homeTestIssuer, a) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + colleague, _ := f.app.memberFor("colleague@example.com") |
| + if err := f.app.db.Create(&Grant{SheetID: shared.ID, MemberID: uint64(id), Role: string(SheetViewer), GrantedBy: colleague.ID}).Error; err != nil { |
| + t.Fatal(err) |
| + } |
| + feed := func() (int, []string) { |
| + jti, _ := dashboard.ID() |
| + nonce, _ := dashboard.ID() |
| + now := time.Now().Unix() |
| + token, err := dashboard.Sign(f.key, dashboard.Claims{Version: 1, Issuer: homeTestIssuer, Audience: testOrigin, Directory: "https://oficina.example.test", Subject: a, Team: "blue", Purpose: "dashboard-read", KeyID: "key", ID: jti, Nonce: nonce, Issued: now, Expires: now + 120}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + r := httptest.NewRequest("GET", testOrigin+dashboard.Path, nil) |
| + r.Header.Set("Authorization", "Bearer "+token) |
| + w := httptest.NewRecorder() |
| + f.app.Router().ServeHTTP(w, r) |
| + var data dashboard.Response |
| + var titles []string |
| + if w.Code == http.StatusOK && json.Unmarshal(w.Body.Bytes(), &data) == nil { |
| + for _, it := range data.Items { |
| + titles = append(titles, it.Title) |
| + } |
| + } |
| + return w.Code, titles |
| + } |
| + if code, titles := feed(); code != http.StatusOK || len(titles) != 2 { |
| + t.Fatalf("member's feed = %d %v, want both sheets", code, titles) |
| + } |
| + f.dir.set(a, "") |
| + f.refreshed(t) |
| + if code, titles := feed(); code != http.StatusOK || len(titles) != 1 || titles[0] != "Shared" { |
| + t.Fatalf("removed member's feed = %d %v, want the share only", code, titles) |
| + } |
| + f.dir.set(a, "member") |
| + f.refreshed(t) |
| + f.expired(t) |
| + if code, titles := feed(); code == http.StatusOK || len(titles) != 0 { |
| + t.Fatalf("feed under Unknown = %d %v, want unavailable", code, titles) |
| + } |
| +} |
| + |
| +// A link stored under another issuer refuses activation, and leaves no |
| +// marker behind. |
| +func TestTeamCensusRefusesAForeignIssuer(t *testing.T) { |
| + app, _ := appWithSchema(t, testOrigin, TeamBootSchema, signedInAddress) |
| + homeOn(t, app, "") |
| + m, err := app.memberFor("linked@example.com") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := app.db.Exec("INSERT INTO home_identity_links(issuer,subject,person_id) VALUES(?,?,?)", "https://id.other.example", teamSubject('f'), m.ID).Error; err != nil { |
| + t.Fatal(err) |
| + } |
| + cfg, _ := teamConfigFor(t, teamTestBindings()) |
| + if err := app.ConfigureTeam(cfg); !errors.Is(err, errTeamConfig) { |
| + t.Fatalf("ConfigureTeam over a foreign issuer's link = %v, want refusal", err) |
| + } |
| + d, _ := app.db.DB() |
| + if _, activated, err := teamstate.Required(t.Context(), d); err != nil || activated { |
| + t.Fatal("a refused activation left a marker") |
| + } |
| +} |
| + |
| +// connect's same-person rule: a known Home-only member arriving over |
| +// somebody else's live local session is refused, and that session stays. |
| +func TestTeamKnownArrivalOverAnotherSessionIsRefused(t *testing.T) { |
| + f := newTeamFixture(t) |
| + a := teamSubject('a') |
| + f.dir.set(a, "member") |
| + f.signInHome(t, a) |
| + f.jar = map[string]*http.Cookie{} |
| + f.local(t, "x@example.com") |
| + local := f.jar[f.app.homeSessions.CookieName()] |
| + start := f.request(t, "GET", "/auth/start?return_to=%2Fsheets", nil, false) |
| + if fin := f.exchange(t, start, a); fin.Code != http.StatusForbidden { |
| + t.Fatalf("known member over another local session = %d, want 403", fin.Code) |
| + } |
| + if got := f.jar[f.app.homeSessions.CookieName()]; got == nil || got.Value != local.Value { |
| + t.Fatal("the local session did not survive the refused arrival") |
| + } |
| + if m := f.viewer(t); m.Address != "x@example.com" { |
| + t.Fatalf("the session now acts as %q", m.Label()) |
| + } |
| +} |
| + |
| +// Paul, 2026-10-28: team owners can share orphaned sheets. A roster owner |
| +// holds SheetOwner on a sheet with no live owner grant; a roster member |
| +// does not; a sheet with a live owner is untouched; and the rule stops |
| +// applying the moment the sheet has a live owner again. Home-only members |
| +// are labelled with their ref. |
| +func TestTeamRosterOwnerSharesOrphanedSheets(t *testing.T) { |
| + f := newTeamFixture(t) |
| + o, a, m := teamSubject('o'), teamSubject('a'), teamSubject('m') |
| + f.dir.set(o, "owner") |
| + f.dir.set(a, "member") |
| + f.dir.set(m, "member") |
| + create := func(subject, title string) string { |
| + f.signInHome(t, subject) |
| + rec := f.request(t, "POST", "/sheets", url.Values{"title": {title}}, false) |
| + if rec.Code != http.StatusSeeOther { |
| + t.Fatalf("%s create = %d", title, rec.Code) |
| + } |
| + return rec.Header().Get("Location") |
| + } |
| + orphan := create(a, "Orphan") |
| + live := create(m, "Live") |
| + f.dir.set(a, "") |
| + f.refreshed(t) |
| + |
| + f.signInHome(t, m) |
| + if rec := f.get(t, orphan+"/share"); rec.Code != http.StatusNotFound { |
| + t.Errorf("roster member on an orphaned sheet's sharing = %d, want 404", rec.Code) |
| + } |
| + f.signInHome(t, o) |
| + if rec := f.get(t, live+"/share"); rec.Code != http.StatusNotFound { |
| + t.Errorf("roster owner on a live-owned sheet's sharing = %d, want 404", rec.Code) |
| + } |
| + page := f.getHTML(t, orphan+"/share") |
| + if page.Code != http.StatusOK { |
| + t.Fatalf("roster owner on an orphaned sheet's sharing = %d, want 200", page.Code) |
| + } |
| + if !strings.Contains(page.Body.String(), teamLabel+" …"+a[len(a)-4:]) { |
| + t.Error("the departed Home-only owner is not labelled with their ref") |
| + } |
| + if rec := f.request(t, "POST", orphan+"/share", url.Values{"address": {"new@example.com"}, "role": {"owner"}}, false); rec.Code != http.StatusSeeOther { |
| + t.Fatalf("roster owner sharing an orphaned sheet = %d", rec.Code) |
| + } |
| + if rec := f.get(t, orphan+"/share"); rec.Code != http.StatusNotFound { |
| + t.Errorf("after giving it a live owner, the roster owner's sharing = %d, want 404", rec.Code) |
| + } |
| +} |
| + |
| +// Revoking a current Home-only member's grant names them in the notice by |
| +// label and ref, never by an address they do not have. |
| +func TestTeamRevokeNoticeNamesAHomeOnlyMember(t *testing.T) { |
| + f := newTeamFixture(t) |
| + a := teamSubject('a') |
| + f.dir.set(a, "member") |
| + f.signInHome(t, a) |
| + rec := f.request(t, "POST", "/sheets", url.Values{"title": {"Mine"}}, false) |
| + sheet := rec.Header().Get("Location") |
| + if rec := f.request(t, "POST", sheet+"/share", url.Values{"address": {"new@example.com"}, "role": {"owner"}}, false); rec.Code != http.StatusSeeOther { |
| + t.Fatalf("share = %d", rec.Code) |
| + } |
| + id, err := teamstate.HomeMember(t.Context(), f.app.team.db, homeTestIssuer, a) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + f.jar = map[string]*http.Cookie{} |
| + f.local(t, "new@example.com") |
| + revoke := f.request(t, "POST", sheet+"/share/revoke", url.Values{"member": {strconv.FormatInt(id, 10)}}, false) |
| + if revoke.Code != http.StatusSeeOther { |
| + t.Fatalf("revoke = %d", revoke.Code) |
| + } |
| + page := f.getHTML(t, revoke.Header().Get("Location")) |
| + want := "since " + teamLabel + " …" + a[len(a)-4:] + " is on the team" |
| + if !strings.Contains(page.Body.String(), want) { |
| + t.Fatalf("revoke notice does not name the Home-only member as %q", want) |
| + } |
| +} |