Offer "Connect your Oficina account" only to an unlinked local person
The account menu lost its Home item when Calendar adopted the shared chrome, so /account/home could only be reached by typing it. It is back, decided by the stored link rather than the session method: offered with Home configured, to a person signed in with an emailed link or Keymail, while Bridge.Linked says (false, nil). A linked person who signs in locally is not offered it; a Home session never is; an error offers nothing. The person is requirePerson's, already on the request, so the cost is one lookup on the UNIQUE (issuer, person_id) index per menu render. Bumps home/connect to 08bbcf3 (estilo comes up to 0b375d5; chrome.css re-written by writeestilo). Through it: an unknown Oficina assertion is remembered for ten minutes, and the next fresh local sign-in begins the link itself, landing on the confirm page; the confirm POST leads to "Accounts connected", whose button goes back to where the link began (connect.PageFor); the connection pages' buttons sit in one rst-form-foot row, primary first. Tests in home_connect_item_test.go, each seen red with its part of the fix reverted. The Home router fixture gains a lagging Home clock (Config.homeNow, unexported) to age the navigation marker.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
11 files changed,
+311
−15
go.mod+2 −2go.sum+4 −4internal/calendar/app.go+1 −0internal/calendar/config.go+5 −0internal/calendar/handlers.go+5 −0internal/calendar/home.go+26 −2internal/calendar/home_connect_item_test.go+216 −0internal/calendar/home_consumer_test.go+1 −1internal/calendar/home_router_test.go+18 −6internal/calendar/render.go+3 −0internal/calendar/static/chrome.css+30 −0
CI failed — run details
diff --git a/go.mod b/go.mod| index 7cca2e8..72fe228 100644 |
| --- a/go.mod |
| +++ b/go.mod |
| @@ -5,7 +5,7 @@ go 1.25.0 |
| toolchain go1.26.5 |
| require ( |
| - amadan.net/oficina/home/connect v0.0.0-20261001093757-2bec942ddd0c |
| + amadan.net/oficina/home/connect v0.0.0-20261024220045-08bbcf31e483 |
| amadan.net/oficina/home/handoff v0.0.0-20260908102137-481d2d57f489 |
| amadan.net/rastrillo/rastrillo v0.27.1-0.20261006204347-fb806a287060 |
| github.com/carlosframework/rastrillo v0.23.0 |
| @@ -14,7 +14,7 @@ require ( |
| gorm.io/gorm v1.31.2 |
| ) |
| -require amadan.net/oficina/estilo.git v0.0.0-20261001093750-530cb932e768 |
| +require amadan.net/oficina/estilo.git v0.0.0-20261024215431-0b375d59ca32 |
| require ( |
| github.com/BurntSushi/toml v1.6.0 // indirect |
diff --git a/go.sum b/go.sum| index 5322bf1..b585c19 100644 |
| --- a/go.sum |
| +++ b/go.sum |
| @@ -1,7 +1,7 @@ |
| -amadan.net/oficina/estilo.git v0.0.0-20261001093750-530cb932e768 h1:bVscoa9fH5LdLDjlyecZhrX7JzWPT0blb57MH0FIm2U= |
| -amadan.net/oficina/estilo.git v0.0.0-20261001093750-530cb932e768/go.mod h1:4u0jNBtIdMLOsJyrScfqoEuYDJF7BBM3qM9YWbzt6aw= |
| -amadan.net/oficina/home/connect v0.0.0-20261001093757-2bec942ddd0c h1:3yxO2D8BxDLMGfFV2o6Sp9Z91yLnjDCIuRKHVWORa8A= |
| -amadan.net/oficina/home/connect v0.0.0-20261001093757-2bec942ddd0c/go.mod h1:YroavXe43Wietec+po8mtSk4a9Bir2h31Q3iAf4MWxI= |
| +amadan.net/oficina/estilo.git v0.0.0-20261024215431-0b375d59ca32 h1:YJhvKpW6eTejjvXRbb+CHrgmF6Pms7N2q2/73dbm3iA= |
| +amadan.net/oficina/estilo.git v0.0.0-20261024215431-0b375d59ca32/go.mod h1:4u0jNBtIdMLOsJyrScfqoEuYDJF7BBM3qM9YWbzt6aw= |
| +amadan.net/oficina/home/connect v0.0.0-20261024220045-08bbcf31e483 h1:AX1ATw/weILU5pjHHo1XD01gz9EJAp/9xq3J4OftR3E= |
| +amadan.net/oficina/home/connect v0.0.0-20261024220045-08bbcf31e483/go.mod h1:MWe3bFg0xGr1btEom2snMLhEZeRIfw0Iv6vKUyOsu18= |
| amadan.net/oficina/home/handoff v0.0.0-20260908102137-481d2d57f489 h1:RPKtyry/71i06o8L+gjAaUyexbmG56kO1YPs601URAM= |
| amadan.net/oficina/home/handoff v0.0.0-20260908102137-481d2d57f489/go.mod h1:YISpzFJ+iMgrM0rUL032OSzsAQbP4/nozvXLCCOcn1k= |
| amadan.net/rastrillo/native/server v0.0.0-20260923173546-2a5d07b2c8d3 h1:5EFx7BLJj/+G/rt8bTmeyMWVfF5s5Sns7ajTvX4w/I8= |
diff --git a/internal/calendar/app.go b/internal/calendar/app.go| index 0a5d5a1..12bccda 100644 |
| --- a/internal/calendar/app.go |
| +++ b/internal/calendar/app.go |
| @@ -178,6 +178,7 @@ func New(cfg Config) (*App, error) { |
| } |
| h.homeEnabled = true |
| h.directory = homeSettings.Directory |
| + h.homeLinked = a.home.bridge.Linked |
| h.viewerFrom = func(r *http.Request) (rauth.Identity, bool) { |
| // requirePerson has already resolved the person on every page |
| // behind it; resolve again only where it has not run (public |
diff --git a/internal/calendar/config.go b/internal/calendar/config.go| index 76333cf..a124a26 100644 |
| --- a/internal/calendar/config.go |
| +++ b/internal/calendar/config.go |
| @@ -7,6 +7,7 @@ import ( |
| "log/slog" |
| "net/url" |
| "strings" |
| + "time" |
| "amadan.net/rastrillo/rastrillo/mail" |
| ) |
| @@ -71,6 +72,10 @@ type Config struct { |
| AllowedAddresses string |
| Logger *slog.Logger |
| + |
| + // homeNow is the Home bridge's clock; nil is time.Now. Unexported: |
| + // only this package's tests set it, to age a navigation marker. |
| + homeNow func() time.Time |
| } |
| // resolveOrigin applies Config.Origin's fail-closed rule: a valid |
diff --git a/internal/calendar/handlers.go b/internal/calendar/handlers.go| index 31602b0..f29f383 100644 |
| --- a/internal/calendar/handlers.go |
| +++ b/internal/calendar/handlers.go |
| @@ -1,6 +1,7 @@ |
| package calendar |
| import ( |
| + "context" |
| "log/slog" |
| "net/http" |
| @@ -29,6 +30,10 @@ type handlers struct { |
| // passes through. One per app; memory only. |
| gate *gate |
| viewerFrom func(*http.Request) (rauth.Identity, bool) |
| + |
| + // homeLinked is Bridge.Linked with Home configured, nil without it: |
| + // whether a person already has a stored link (offerHomeConnect). |
| + homeLinked func(context.Context, int64) (bool, error) |
| } |
| // index serves GET / — the calendar itself. |
diff --git a/internal/calendar/home.go b/internal/calendar/home.go| index 32d72cf..6897343 100644 |
| --- a/internal/calendar/home.go |
| +++ b/internal/calendar/home.go |
| @@ -57,7 +57,7 @@ func (a *App) newHome(settings *connect.DecodedCredentials, list allowlist) (*ho |
| return p, nil |
| } |
| page := func(w http.ResponseWriter, r *http.Request, state, label string, status int) { |
| - data := connect.Page(state, label) |
| + data := connect.PageFor(r, state, label) |
| // Where sign-out lands is the Oficina door, in the door's words. |
| tree, title, view := pages["home"], data.Title, any(data) |
| if state == "signedout" { |
| @@ -74,7 +74,7 @@ func (a *App) newHome(settings *connect.DecodedCredentials, list allowlist) (*ho |
| w.WriteHeader(status) |
| _, _ = buf.WriteTo(w) |
| } |
| - b, err := connect.New(connect.Config{DB: writer, Origin: a.cfg.Origin, Issuer: settings.Issuer, ConsumerID: settings.ConsumerID, Keys: settings.Keys, DEK: settings.DEK, Namespace: "oficina/calendar", SessionCookie: sess.CookieName(), ReadSession: read, LookupLocalSession: local, LookupPerson: lookup, Render: page, MintHomeSession: func(w http.ResponseWriter, r *http.Request, s connect.Session) error { |
| + b, err := connect.New(connect.Config{DB: writer, Origin: a.cfg.Origin, Issuer: settings.Issuer, ConsumerID: settings.ConsumerID, Keys: settings.Keys, DEK: settings.DEK, Namespace: "oficina/calendar", SessionCookie: sess.CookieName(), ReadSession: read, LookupLocalSession: local, LookupPerson: lookup, Render: page, Now: a.cfg.homeNow, MintHomeSession: func(w http.ResponseWriter, r *http.Request, s connect.Session) error { |
| return sess.SignIn(w, r, sessions.Session{Subject: s.Subject, Method: s.Method, AuthTime: s.AuthTime}) |
| }}) |
| if err != nil { |
| @@ -87,6 +87,30 @@ func (a *App) newHome(settings *connect.DecodedCredentials, list allowlist) (*ho |
| return &homeConnection{bridge: b, routes: routes, sessions: sess, admitted: list}, nil |
| } |
| +// offerHomeConnect decides the account menu's "Connect your Oficina |
| +// account". Only with Home configured, only to a person signed in locally |
| +// (a Home session is linked already), and only while that person has no |
| +// stored link. The stored link decides, never how this session signed in: |
| +// a linked person who signed in with an emailed link has nothing to |
| +// connect, and was offered it anyway (Paul, in Docs, 2026-10-24). The |
| +// person is requirePerson's, already on the request, so this costs one |
| +// lookup on the UNIQUE (issuer, person_id) index per menu render. An error |
| +// means "unknown", and offers nothing. |
| +func (h *handlers) offerHomeConnect(r *http.Request) bool { |
| + if h.homeLinked == nil { |
| + return false |
| + } |
| + if s, ok := sessions.Current(r); !ok || (s.Method != "magiclink" && s.Method != "keymail") { |
| + return false |
| + } |
| + p, ok := CurrentPerson(r) |
| + if !ok || p.ID <= 0 { |
| + return false |
| + } |
| + linked, err := h.homeLinked(r.Context(), p.ID) |
| + return err == nil && !linked |
| +} |
| + |
| func (a *App) homePerson(r *http.Request) (Person, error) { |
| p, err := a.home.bridge.ResolveSession(r) |
| if err != nil { |
diff --git a/internal/calendar/home_connect_item_test.go b/internal/calendar/home_connect_item_test.go| new file mode 100644 |
| index 0000000..a6d018c |
| --- /dev/null |
| +++ b/internal/calendar/home_connect_item_test.go |
| @@ -0,0 +1,216 @@ |
| +package calendar |
| + |
| +import ( |
| + "net/http" |
| + "net/url" |
| + "regexp" |
| + "strings" |
| + "testing" |
| + "time" |
| +) |
| + |
| +// connectItem is the account menu's "Connect your Oficina account" row, as |
| +// estilo's menu draws it. |
| +const connectItem = `<a estilo-menu-item href="/account/home"><span estilo-menu-label>Connect your Oficina account</span></a>` |
| + |
| +const freshHomeStart = "/auth/start?return_to=%2Faccount%2Fhome%2Fconfirm" |
| + |
| +func (f *homeRouterFixture) offersConnect(t *testing.T) bool { |
| + t.Helper() |
| + w := f.do("GET", "/day/2026-09-10", "") |
| + if w.Code != 200 { |
| + t.Fatalf("GET /day: %d", w.Code) |
| + } |
| + if !strings.Contains(w.Body.String(), "estilo-account") { |
| + t.Fatal("GET /day drew no account menu") |
| + } |
| + return strings.Contains(w.Body.String(), connectItem) |
| +} |
| + |
| +// linkCount is how many stored links the person has: the table itself, |
| +// not the bridge's answer about it. |
| +func (f *homeRouterFixture) linkCount(t *testing.T, address string) int64 { |
| + t.Helper() |
| + var n int64 |
| + if err := f.app.db.Writer().QueryRowContext(t.Context(), `SELECT COUNT(*) FROM home_identity_links l JOIN people p ON p.id = l.person_id WHERE p.address = ?`, address).Scan(&n); err != nil { |
| + t.Fatal(err) |
| + } |
| + return n |
| +} |
| + |
| +// connectFromMenu runs the menu's link flow for a locally signed-in alice, |
| +// through the confirm POST, and returns where the POST sent her. |
| +func (f *homeRouterFixture) connectFromMenu(t *testing.T, subject string) string { |
| + t.Helper() |
| + // A signed-in page first: requirePerson creates the person the |
| + // connection pages look up (TestHomeConnectStartPageNeverNamesHome). |
| + if w := f.do("GET", "/day/2026-09-10", ""); w.Code != 200 { |
| + t.Fatal("local calendar", w.Code) |
| + } |
| + if w := f.do("GET", "/account/home", ""); w.Code != 200 { |
| + t.Fatal("start page", w.Code, w.Body.String()) |
| + } |
| + start := homeRedirect(t, f.do("POST", "/account/home", "")) |
| + if got := homeRedirect(t, f.exchange(t, start, subject)); got != "/account/home/confirm" { |
| + t.Fatal("fresh assertion landed on", got) |
| + } |
| + if w := f.do("GET", "/account/home/confirm", ""); w.Code != 200 || !strings.Contains(w.Body.String(), "Connect these two accounts?") { |
| + t.Fatalf("confirm page: %d\n%s", w.Code, w.Body.String()) |
| + } |
| + return homeRedirect(t, f.do("POST", "/account/home/confirm", "")) |
| +} |
| + |
| +// A person signed in with an emailed link, with no stored link, is offered |
| +// the connection in the account menu. |
| +func TestConnectItemOfferedToALocalUnlinkedPerson(t *testing.T) { |
| + f := newHomeRouterFixture(t) |
| + f.local(t) |
| + if !f.offersConnect(t) { |
| + t.Fatal("a locally signed-in, unlinked person is not offered Connect your Oficina account") |
| + } |
| +} |
| + |
| +// Once linked, the item is gone however the session signed in: here a |
| +// fresh emailed-link sign-in, in a new browser, after the link was stored |
| +// (Paul's Docs report, 2026-10-24: the item was offered by session method). |
| +func TestConnectItemNotOfferedToALinkedPersonSignedInLocally(t *testing.T) { |
| + f := newHomeRouterFixture(t) |
| + f.local(t) |
| + f.connectFromMenu(t, "opaque-home-alice") |
| + if f.linkCount(t, "alice@example.test") != 1 { |
| + t.Fatal("the link flow stored no link") |
| + } |
| + f.cookies = map[string]*http.Cookie{} |
| + f.local(t) |
| + if f.offersConnect(t) { |
| + t.Fatal("a linked person signed in with an emailed link is still offered Connect your Oficina account") |
| + } |
| +} |
| + |
| +func TestConnectItemNotOfferedToAHomeSession(t *testing.T) { |
| + f := newHomeRouterFixture(t) |
| + f.local(t) |
| + f.connectFromMenu(t, "opaque-home-alice") |
| + f.cookies = map[string]*http.Cookie{} |
| + start := homeRedirect(t, f.do("GET", "/signin", "")) |
| + if got := homeRedirect(t, f.exchange(t, start, "opaque-home-alice")); got != "/" { |
| + t.Fatal("Home sign-in landed on", got) |
| + } |
| + if f.offersConnect(t) { |
| + t.Fatal("a Home session is offered Connect your Oficina account") |
| + } |
| +} |
| + |
| +// Right after the confirm POST, in the same (local) session: "Accounts |
| +// connected", a stored row, and no item on the next page. |
| +func TestConfirmLeadsToAccountsConnectedAndRetiresTheItem(t *testing.T) { |
| + f := newHomeRouterFixture(t) |
| + f.local(t) |
| + if !f.offersConnect(t) { |
| + t.Fatal("not offered before linking") |
| + } |
| + next := f.connectFromMenu(t, "opaque-home-alice") |
| + u, err := url.Parse(next) |
| + if err != nil || u.Path != "/account/home/confirm" || u.Query().Get("connected") != "1" { |
| + t.Fatal("confirm POST sent the browser to", next) |
| + } |
| + w := f.do("GET", next, "") |
| + if w.Code != 200 || !strings.Contains(w.Body.String(), "Accounts connected") { |
| + t.Fatalf("after confirm: %d, want Accounts connected\n%s", w.Code, w.Body.String()) |
| + } |
| + if n := f.linkCount(t, "alice@example.test"); n != 1 { |
| + t.Fatalf("home_identity_links holds %d rows for alice, want 1", n) |
| + } |
| + if f.offersConnect(t) { |
| + t.Fatal("the next page still offers Connect your Oficina account to a now-linked person") |
| + } |
| +} |
| + |
| +// The success page's way back is the page the link began from |
| +// (connect.PageFor), not "/". |
| +func TestAccountsConnectedReturnsToWhereTheLinkBegan(t *testing.T) { |
| + f := newHomeRouterFixture(t) |
| + f.local(t) |
| + f.connectFromMenu(t, "opaque-home-alice") |
| + w := f.do("GET", "/account/home/confirm?connected=1&return_to=%2Fday%2F2026-09-10", "") |
| + if w.Code != 200 || !strings.Contains(w.Body.String(), "Accounts connected") { |
| + t.Fatalf("success page: %d\n%s", w.Code, w.Body.String()) |
| + } |
| + if !strings.Contains(w.Body.String(), `<a rst-btn="primary" href="/day/2026-09-10">`) { |
| + t.Fatalf("Accounts connected does not lead back to /day/2026-09-10:\n%s", w.Body.String()) |
| + } |
| +} |
| + |
| +// An Oficina sign-in with an unlinked subject shows the unknown page; a |
| +// local sign-in in the same browser then begins the link itself, through |
| +// the fresh Home assertion, to the confirm page, and the confirm stores it. |
| +func TestUnknownOficinaSigninResumesAfterLocalSignin(t *testing.T) { |
| + f := newHomeRouterFixture(t) |
| + if _, err := f.app.store.EnsurePersonSetup(t.Context(), "alice@example.test"); err != nil { |
| + t.Fatal(err) |
| + } |
| + start := homeRedirect(t, f.do("GET", "/signin", "")) |
| + unknown := f.exchange(t, start, "opaque-home-alice") |
| + if unknown.Code != 403 || !strings.Contains(unknown.Body.String(), "Oficina account not connected") || !strings.Contains(unknown.Body.String(), `<a rst-btn="primary" href="/signin/local">`) { |
| + t.Fatalf("unknown assertion: %d, want the unknown page leading to /signin/local\n%s", unknown.Code, unknown.Body.String()) |
| + } |
| + if got := f.local(t); got != freshHomeStart { |
| + t.Fatalf("local sign-in after an unknown assertion landed on %q, want %q", got, freshHomeStart) |
| + } |
| + if f.cookies["__Host-oficina-home-init"] == nil { |
| + t.Fatal("the resumed link set no __Host-oficina-home-init") |
| + } |
| + if got := homeRedirect(t, f.exchange(t, freshHomeStart, "opaque-home-alice")); got != "/account/home/confirm" { |
| + t.Fatal("fresh assertion landed on", got) |
| + } |
| + if w := f.do("GET", "/account/home/confirm", ""); w.Code != 200 || !strings.Contains(w.Body.String(), "Connect these two accounts?") { |
| + t.Fatalf("confirm page: %d\n%s", w.Code, w.Body.String()) |
| + } |
| + if f.linkCount(t, "alice@example.test") != 0 { |
| + t.Fatal("linked before the confirm click") |
| + } |
| + homeRedirect(t, f.do("POST", "/account/home/confirm", "")) |
| + if n := f.linkCount(t, "alice@example.test"); n != 1 { |
| + t.Fatalf("home_identity_links holds %d rows for alice after confirm, want 1", n) |
| + } |
| + resolved, err := f.app.home.bridge.Resolve(t.Context(), "opaque-home-alice") |
| + if err != nil || resolved.Label != "alice@example.test" { |
| + t.Fatal("the stored link does not resolve to alice", resolved, err) |
| + } |
| +} |
| + |
| +// The remembered unknown assertion lasts ten minutes. Older, and the local |
| +// sign-in lands as any other does. |
| +func TestUnknownOficinaSigninExpiresAfterTenMinutes(t *testing.T) { |
| + f := newHomeRouterFixture(t, 11*time.Minute) |
| + if _, err := f.app.store.EnsurePersonSetup(t.Context(), "alice@example.test"); err != nil { |
| + t.Fatal(err) |
| + } |
| + start := homeRedirect(t, f.do("GET", "/signin", "")) |
| + if w := f.exchange(t, start, "opaque-home-alice"); w.Code != 403 { |
| + t.Fatal("unknown assertion", w.Code) |
| + } |
| + if f.cookies["__Host-oficina-local-link-navigation"] == nil { |
| + t.Fatal("the unknown assertion left no marker, so this test would prove nothing") |
| + } |
| + f.behind = 0 |
| + if got := f.local(t); got != "/" { |
| + t.Fatalf("local sign-in after an expired marker landed on %q, want /", got) |
| + } |
| +} |
| + |
| +// The connection pages put their buttons in one rst-form-foot row, primary |
| +// first (estilo's homeconnect). |
| +func TestConnectPageButtonsShareOneFormFootRow(t *testing.T) { |
| + f := newHomeRouterFixture(t) |
| + f.local(t) |
| + f.do("GET", "/day/2026-09-10", "") |
| + w := f.do("GET", "/account/home", "") |
| + if w.Code != 200 { |
| + t.Fatal(w.Code) |
| + } |
| + row := regexp.MustCompile(`<div rst-form-foot>\s*<form method="post" action="/account/home"><button rst-btn="primary" type="submit">Connect</button></form>\s*<a rst-btn="ghost" href="/">Back</a>\s*</div>`) |
| + if !row.MatchString(w.Body.String()) { |
| + t.Fatalf("the start page's buttons are not one rst-form-foot row, primary first:\n%s", w.Body.String()) |
| + } |
| +} |
diff --git a/internal/calendar/home_consumer_test.go b/internal/calendar/home_consumer_test.go| index ced5f50..a371f12 100644 |
| --- a/internal/calendar/home_consumer_test.go |
| +++ b/internal/calendar/home_consumer_test.go |
| @@ -38,7 +38,7 @@ func newHomeConsumerFixture(t *testing.T, directory string) *homeRouterFixture { |
| t.Fatal(err) |
| } |
| t.Cleanup(func() { a.Close() }) |
| - return &homeRouterFixture{a, key, map[string]*http.Cookie{}} |
| + return &homeRouterFixture{app: a, key: key, cookies: map[string]*http.Cookie{}} |
| } |
| // Sign out in Calendar ends the id.* session too: the app session ends and |
diff --git a/internal/calendar/home_router_test.go b/internal/calendar/home_router_test.go| index da36341..e8243ed 100644 |
| --- a/internal/calendar/home_router_test.go |
| +++ b/internal/calendar/home_router_test.go |
| @@ -27,21 +27,31 @@ type homeRouterFixture struct { |
| app *App |
| key *assertioncrypto.Keypair |
| cookies map[string]*http.Cookie |
| + behind time.Duration // the Home clock's (and signed assertions') lag |
| } |
| -func newHomeRouterFixture(t *testing.T) *homeRouterFixture { |
| +func (f *homeRouterFixture) now() time.Time { return time.Now().Add(-f.behind) } |
| + |
| +// newHomeRouterFixture can start the Home clock behind, from the first |
| +// request: the hand-off store's clock fence refuses to move backwards. |
| +func newHomeRouterFixture(t *testing.T, behind ...time.Duration) *homeRouterFixture { |
| t.Helper() |
| key, err := assertioncrypto.Generate() |
| if err != nil { |
| t.Fatal(err) |
| } |
| + f := &homeRouterFixture{key: key, cookies: map[string]*http.Cookie{}} |
| + if len(behind) == 1 { |
| + f.behind = behind[0] |
| + } |
| manifest, _ := json.Marshal(map[string]string{"key": base64.StdEncoding.EncodeToString(key.SignPub())}) |
| - a, err := New(Config{DBPath: filepath.Join(t.TempDir(), "calendar.db"), Env: "development", Origin: homeTestOrigin, AllowedAddresses: "alice@example.test,replacement@example.test", Logger: slog.New(slog.NewTextHandler(io.Discard, nil)), Home: &connect.Credentials{Issuer: homeTestIssuer, ConsumerID: "calendar-test", KeysBase64: base64.StdEncoding.EncodeToString(manifest), DEKBase64: base64.StdEncoding.EncodeToString(bytes.Repeat([]byte{7}, 32))}}) |
| + a, err := New(Config{DBPath: filepath.Join(t.TempDir(), "calendar.db"), Env: "development", Origin: homeTestOrigin, AllowedAddresses: "alice@example.test,replacement@example.test", Logger: slog.New(slog.NewTextHandler(io.Discard, nil)), Home: &connect.Credentials{Issuer: homeTestIssuer, ConsumerID: "calendar-test", KeysBase64: base64.StdEncoding.EncodeToString(manifest), DEKBase64: base64.StdEncoding.EncodeToString(bytes.Repeat([]byte{7}, 32))}, homeNow: f.now}) |
| if err != nil { |
| t.Fatal(err) |
| } |
| t.Cleanup(func() { a.Close() }) |
| - return &homeRouterFixture{a, key, map[string]*http.Cookie{}} |
| + f.app = a |
| + return f |
| } |
| func (f *homeRouterFixture) do(method, path, body string) *httptest.ResponseRecorder { |
| r := httptest.NewRequest(method, homeTestOrigin+path, strings.NewReader(body)) |
| @@ -73,7 +83,9 @@ func homeRedirect(t *testing.T, w *httptest.ResponseRecorder) string { |
| } |
| return w.Header().Get("Location") |
| } |
| -func (f *homeRouterFixture) local(t *testing.T) { |
| + |
| +// local signs alice in with an emailed link; it returns her landing. |
| +func (f *homeRouterFixture) local(t *testing.T) string { |
| t.Helper() |
| homeRedirect(t, f.do("POST", "/signin", "address=alice%40example.test&force=1")) |
| f.app.signinMail.wait() |
| @@ -94,7 +106,7 @@ func (f *homeRouterFixture) local(t *testing.T) { |
| if landing != "/auth/local/complete" { |
| t.Fatal("wrong local landing", landing) |
| } |
| - homeRedirect(t, f.do("GET", landing, "")) |
| + return homeRedirect(t, f.do("GET", landing, "")) |
| } |
| func (f *homeRouterFixture) exchange(t *testing.T, start, subject string) *httptest.ResponseRecorder { |
| t.Helper() |
| @@ -104,7 +116,7 @@ func (f *homeRouterFixture) exchange(t *testing.T, start, subject string) *httpt |
| t.Fatal("bad issuer redirect") |
| } |
| nonce := u.Query().Get("nonce") |
| - now := time.Now().Unix() |
| + now := f.now().Unix() |
| jti, err := assertion.RandomID() |
| if err != nil { |
| t.Fatal(err) |
diff --git a/internal/calendar/render.go b/internal/calendar/render.go| index fe4d4d2..5e2c580 100644 |
| --- a/internal/calendar/render.go |
| +++ b/internal/calendar/render.go |
| @@ -159,6 +159,9 @@ func (h *handlers) page(r *http.Request, title string, data any) PageData { |
| pd.Address = id.Address |
| } |
| pd.Chrome = calendarChrome(r, pd.SignedIn, pd.Address, mode, title, h.directory) |
| + if pd.Chrome.Account != nil && h.offerHomeConnect(r) { |
| + pd.Chrome.Account.Items = append(pd.Chrome.Account.Items, menu.Item{Href: "/account/home", Label: connect.English["menu_action"]}) |
| + } |
| // Every door — the form, its notices, the confirm step an emailed |
| // link opens on, and the refusal auth answers /auth/* with — shows |
| // the brand alone: no account menu, no Sign in. |
diff --git a/internal/calendar/static/chrome.css b/internal/calendar/static/chrome.css| index 74bd3d7..71c0490 100644 |
| --- a/internal/calendar/static/chrome.css |
| +++ b/internal/calendar/static/chrome.css |
| @@ -208,6 +208,36 @@ |
| [estilo-menu-identity-name] + [estilo-menu-identity-address] { font-size: var(--rst-fs-xs); } |
| [estilo-bar-signin] { flex: none; } |
| +/* The account at a sidebar rail's foot (Account.Rail), for an app whose |
| + chrome is a rail rather than the bar. The trigger is a row the rail's |
| + width: the avatar, then who is signed in, cut short with an ellipsis. |
| + It stays in the page flow, so its highlight stays square. The panel is |
| + the foot's own width, edge to edge with the trigger: hung from the |
| + inline end of a foot narrower than the bar's 15rem panel it ran off |
| + the window's start edge, and from the inline start it ran past the |
| + rail, whose overflow-y: auto clips it (Fichas' first screenshot). */ |
| +[estilo-account~="rail"] > [estilo-bar-trigger] { |
| + justify-content: flex-start; |
| + gap: var(--rst-sp-2); |
| + inline-size: 100%; |
| + block-size: auto; |
| + min-block-size: 2.5rem; |
| + color: var(--rst-text); |
| +} |
| +[estilo-account-who] { min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } |
| +[estilo-account~="rail"] > [estilo-account-panel] { inset-inline: 0; inline-size: auto; min-inline-size: 0; max-inline-size: none; } |
| +/* A drop-up where the rail is the viewport's height (rastrillo's shell |
| + breakpoint): below the foot there is only the window's edge. Below |
| + 800px the rail is a disclosure at the top of the page, with the page |
| + under it and too little above, so the panel opens downward there. */ |
| +@media (min-width: 800px) { |
| + [estilo-account~="rail"] > [estilo-account-panel] { |
| + inset-block-start: auto; |
| + inset-block-end: calc(100% + 4px); |
| + max-block-size: max(calc(100dvh - 5rem), 8rem); |
| + } |
| +} |
| + |
| /* Visually hidden, still announced. */ |
| [estilo-visually-hidden] { position: absolute; clip-path: inset(50%); inline-size: 1px; block-size: 1px; overflow: hidden; white-space: nowrap; } |