Reconcile Calendar agent access with current Home and dashboard
22 files changed,
+740
−75
Makefile+1 −1go.mod+4 −3go.sum+8 −10internal/calendar/app.go+7 −0internal/calendar/chrome_calendar.go+4 −1internal/calendar/config.go+5 −0internal/calendar/credits_inventory_test.go+1 −1internal/calendar/dashboard.go+87 −0internal/calendar/dashboard_test.go+111 −0internal/calendar/handlers.go+5 −0internal/calendar/home.go+53 −2internal/calendar/home_connect_item_test.go+234 −0internal/calendar/home_consumer_test.go+47 −16internal/calendar/home_router_test.go+18 −6internal/calendar/migrations.go+2 −1internal/calendar/render.go+3 −0internal/calendar/routes.go+11 −2internal/calendar/static/chrome.css+39 −0internal/calendar/static/theme.css+5 −3internal/calendar/templates/layout.html+4 −5internal/calendartest/fontlink_test.go+0 −24internal/calendartest/nowebfont_test.go+91 −0
CI passed — run details
diff --git a/Makefile b/Makefile| index 38da1ec..34a5916 100644 |
| --- a/Makefile |
| +++ b/Makefile |
| @@ -160,6 +160,6 @@ credits: |
| go build -o "$$notices_tmp/notices" amadan.net/oficina/estilo.git/cmd/oficina-notices; \ |
| GOOS=linux GOARCH=arm64 CGO_ENABLED=0 "$$notices_tmp/notices" \ |
| -package ./cmd/calendar -lucide -onest \ |
| - -exclude amadan.net/oficina/agent-access.git,amadan.net/oficina/estilo.git,amadan.net/oficina/home/connect,amadan.net/oficina/home/handoff,amadan.net/rastrillo/native/server \ |
| + -exclude amadan.net/oficina/home/dashboard,amadan.net/oficina/agent-access.git,amadan.net/oficina/estilo.git,amadan.net/oficina/home/connect,amadan.net/oficina/home/handoff,amadan.net/rastrillo/native/server \ |
| > "$$notices_tmp/notices.json"; \ |
| mv "$$notices_tmp/notices.json" internal/calendar/credits/notices.json |
diff --git a/go.mod b/go.mod| index f5f194c..be2bce5 100644 |
| --- a/go.mod |
| +++ b/go.mod |
| @@ -5,8 +5,8 @@ go 1.25.0 |
| toolchain go1.26.5 |
| require ( |
| - amadan.net/oficina/home/connect v0.0.0-20261025004522-7430dd23a847 |
| - amadan.net/oficina/home/handoff v0.0.0-20260908102137-481d2d57f489 |
| + amadan.net/oficina/home/connect v0.0.0-20261030223040-6d99b0ccc542 |
| + amadan.net/oficina/home/handoff v0.0.0-20261024233715-ff16bf56bc4d |
| amadan.net/rastrillo/rastrillo v0.27.1-0.20261006204347-fb806a287060 |
| github.com/carlosframework/rastrillo v0.23.0 |
| github.com/chromedp/chromedp v0.14.2 |
| @@ -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-20261025200559-260f98c42e2d |
| require ( |
| github.com/BurntSushi/toml v1.6.0 // indirect |
| @@ -44,6 +44,7 @@ require ( |
| require ( |
| amadan.net/oficina/agent-access.git v0.0.0-20261025011012-4b94ff9e8a8d |
| + amadan.net/oficina/home/dashboard v0.0.0-20261024234842-3774eb68f816 |
| amadan.net/rastrillo/native/server v0.0.0-20260923173546-2a5d07b2c8d3 |
| ) |
diff --git a/go.sum b/go.sum| index 992ae10..653c34f 100644 |
| --- a/go.sum |
| +++ b/go.sum |
| @@ -1,15 +1,13 @@ |
| -amadan.net/oficina/agent-access.git v0.0.0-20261024232549-8ed8ba826000 h1:L07nc+dmLI7c1PBkSkbnrjOK5f8p6OBbA/yTxznxCAw= |
| -amadan.net/oficina/agent-access.git v0.0.0-20261024232549-8ed8ba826000/go.mod h1:Ph9PIa3VE1IEaUzZiQH6D+IQ6HThWWGfVr0ecMMgrFA= |
| amadan.net/oficina/agent-access.git v0.0.0-20261025011012-4b94ff9e8a8d h1:bSsf1NXVhXTfLLB9J7a5v9CqzdKj8CALHZ6W3H7A/4M= |
| amadan.net/oficina/agent-access.git v0.0.0-20261025011012-4b94ff9e8a8d/go.mod h1:Ph9PIa3VE1IEaUzZiQH6D+IQ6HThWWGfVr0ecMMgrFA= |
| -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/home/connect v0.0.0-20261025004522-7430dd23a847 h1:pJYp3kEWLUXXoi4UtRH8SIX+HyAyQUQOaFNE7XuY20Y= |
| -amadan.net/oficina/home/connect v0.0.0-20261025004522-7430dd23a847/go.mod h1:YroavXe43Wietec+po8mtSk4a9Bir2h31Q3iAf4MWxI= |
| -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/oficina/estilo.git v0.0.0-20261025200559-260f98c42e2d h1:p9+01xRdBD7s1viTINgQ6XoDD5ghOxYubD7FNcjhBTw= |
| +amadan.net/oficina/estilo.git v0.0.0-20261025200559-260f98c42e2d/go.mod h1:4u0jNBtIdMLOsJyrScfqoEuYDJF7BBM3qM9YWbzt6aw= |
| +amadan.net/oficina/home/connect v0.0.0-20261030223040-6d99b0ccc542 h1:b2JT0B0Y+5sTsCmVhX6cywCRdGd9s3lRP8wpqOytlbM= |
| +amadan.net/oficina/home/connect v0.0.0-20261030223040-6d99b0ccc542/go.mod h1:ix81eFV87yE9f2SXiRuxYCVM4lAgTRC5YoQMiH3+TDk= |
| +amadan.net/oficina/home/dashboard v0.0.0-20261024234842-3774eb68f816 h1:AFDuOio0MxNxN9ZWVc3lul1QHkNjNUCO56kXpe/Fw3I= |
| +amadan.net/oficina/home/dashboard v0.0.0-20261024234842-3774eb68f816/go.mod h1:+7xsX+QyVFrKy5gDAGh+FZ5+75z4CibWTL0wl9DWAw0= |
| +amadan.net/oficina/home/handoff v0.0.0-20261024233715-ff16bf56bc4d h1:8RTZkLQnyxvH2g0RMovhN/m2LN9D8qb+kBfqdBeqq+s= |
| +amadan.net/oficina/home/handoff v0.0.0-20261024233715-ff16bf56bc4d/go.mod h1:YISpzFJ+iMgrM0rUL032OSzsAQbP4/nozvXLCCOcn1k= |
| amadan.net/rastrillo/native/server v0.0.0-20260923173546-2a5d07b2c8d3 h1:5EFx7BLJj/+G/rt8bTmeyMWVfF5s5Sns7ajTvX4w/I8= |
| amadan.net/rastrillo/native/server v0.0.0-20260923173546-2a5d07b2c8d3/go.mod h1:ZaaxeE278dJltdrLwmwpxUjQ5wuKzqDAVSNRet+WupY= |
| amadan.net/rastrillo/rastrillo v0.27.1-0.20261006204347-fb806a287060 h1:K2PXcCKfm+AYrqgH1ea6cNsFs4sN7MKLvq+uBY11NZE= |
diff --git a/internal/calendar/app.go b/internal/calendar/app.go| index 6d8fab4..b01ef69 100644 |
| --- a/internal/calendar/app.go |
| +++ b/internal/calendar/app.go |
| @@ -30,6 +30,7 @@ import ( |
| // development mail recorder both hang off this struct, and every later |
| // test depends on them. |
| type App struct { |
| + dashboard http.Handler |
| agent http.Handler |
| agentIssuer, agentTeam string |
| native *nativeauth.Auth |
| @@ -181,8 +182,14 @@ func New(cfg Config) (*App, error) { |
| d.Close() |
| return nil, err |
| } |
| + if err = a.configureDashboard(homeSettings); err != nil { |
| + signinMail.close() |
| + d.Close() |
| + return nil, err |
| + } |
| 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/chrome_calendar.go b/internal/calendar/chrome_calendar.go| index b231000..22e0423 100644 |
| --- a/internal/calendar/chrome_calendar.go |
| +++ b/internal/calendar/chrome_calendar.go |
| @@ -34,8 +34,11 @@ func calendarChrome(r *http.Request, signedIn bool, address string, mode chrome. |
| bar.SignIn = &chrome.Link{Href: "/signin?return_to=" + template.URLQueryEscaper(r.URL.RequestURI()), Label: "Sign in"} |
| return bar |
| } |
| + // The app switcher, only with a hub directory configured: the suite's |
| + // six apps as tiles, each at its own host under the directory's |
| + // (estilo's chrome.SuiteApps), Calendar marked current, then "All apps". |
| if directory != "" { |
| - bar.Switcher = &chrome.Switcher{Label: "Oficina apps", AllApps: estilomenu.Item{Href: strings.TrimSuffix(directory, "/") + "/", Label: "All apps"}} |
| + bar.Switcher = &chrome.Switcher{Label: "Oficina apps", CurrentLabel: "(this app)", Apps: chrome.SuiteApps(directory, "calendar"), AllApps: estilomenu.Item{Href: strings.TrimSuffix(directory, "/") + "/", Label: "All apps"}} |
| } |
| // A live session whose person could not be resolved (a removed Home |
| // person on an error page) still gets the menu, to sign out from, but |
diff --git a/internal/calendar/config.go b/internal/calendar/config.go| index 9027ef1..f09487f 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" |
| ) |
| @@ -72,6 +73,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/credits_inventory_test.go b/internal/calendar/credits_inventory_test.go| index 55f0137..e61d187 100644 |
| --- a/internal/calendar/credits_inventory_test.go |
| +++ b/internal/calendar/credits_inventory_test.go |
| @@ -36,7 +36,7 @@ func TestCreditsMatchProductionDependencies(t *testing.T) { |
| if err != nil { |
| t.Fatalf("production dependency graph unavailable: %v\n%s", err, stderr.String()) |
| } |
| - inventory, err := catalog.Collect(bytes.NewReader(raw), map[string]bool{"amadan.net/oficina/agent-access.git": true, |
| + inventory, err := catalog.Collect(bytes.NewReader(raw), map[string]bool{"amadan.net/oficina/home/dashboard": true, "amadan.net/oficina/agent-access.git": true, |
| "amadan.net/oficina/estilo.git": true, "amadan.net/oficina/home/handoff": true, "amadan.net/oficina/home/connect": true, "amadan.net/rastrillo/native/server": true}) |
| if err != nil { |
| t.Fatal(err) |
diff --git a/internal/calendar/dashboard.go b/internal/calendar/dashboard.go| new file mode 100644 |
| index 0000000..8f75b5c |
| --- /dev/null |
| +++ b/internal/calendar/dashboard.go |
| @@ -0,0 +1,87 @@ |
| +package calendar |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "os" |
| + "sort" |
| + "strconv" |
| + "time" |
| + |
| + "amadan.net/oficina/home/connect" |
| + "amadan.net/oficina/home/connect/linkstore" |
| + "amadan.net/oficina/home/dashboard" |
| +) |
| + |
| +func (a *App) configureDashboard(c *connect.DecodedCredentials) error { |
| + team := os.Getenv("OFICINA_DASHBOARD_TEAM") |
| + if team == "" { |
| + return nil |
| + } |
| + h, e := dashboard.NewProvider(dashboard.ProviderConfig{DB: a.db.Writer(), Origin: a.cfg.Origin, Issuer: c.Issuer, Directory: c.Directory, Keys: c.Keys, Team: team, Kind: "events", Resolve: func(ctx context.Context, subject string) (int64, error) { |
| + p, e := a.home.bridge.Resolve(ctx, subject) |
| + if errors.Is(e, linkstore.ErrStorage) { |
| + return 0, dashboard.ErrUnavailable |
| + } |
| + return p.ID, e |
| + }, Read: a.dashboardEvents}) |
| + if e != nil { |
| + return e |
| + } |
| + a.dashboard = h |
| + return nil |
| +} |
| +func (a *App) dashboardEvents(ctx context.Context, id int64, _ string, now time.Time) (dashboard.Response, error) { |
| + var person Person |
| + if e := a.db.G.WithContext(ctx).First(&person, id).Error; e != nil { |
| + return dashboard.Response{}, e |
| + } |
| + zone := person.Zone |
| + if zone == "" { |
| + zone = "UTC" |
| + } |
| + loc, e := time.LoadLocation(zone) |
| + if e != nil { |
| + return dashboard.Response{}, e |
| + } |
| + local := now.In(loc) |
| + from := time.Date(local.Year(), local.Month(), local.Day(), 0, 0, 0, 0, loc) |
| + until := from.AddDate(0, 0, 8) |
| + rows, e := a.store.EventsInRangeStrict(ctx, id, from.AddDate(0, 0, -2).Unix(), until.AddDate(0, 0, 2).Unix()) |
| + if e != nil { |
| + return dashboard.Response{}, e |
| + } |
| + out := dashboard.Response{Timezone: zone} |
| + for _, event := range rows { |
| + if event.Status == "cancelled" || (!event.AllDay && (event.OccEndUTC <= now.Unix() || event.OccStartUTC >= until.Unix())) { |
| + continue |
| + } |
| + item := dashboard.Item{ID: strconv.FormatInt(event.ID, 10) + ":" + strconv.FormatInt(event.OccStartUTC, 10), Title: event.Title, URL: a.cfg.Origin + eventHref(event), Start: time.Unix(event.OccStartUTC, 0).UTC(), End: time.Unix(event.OccEndUTC, 0).UTC(), AllDay: event.AllDay, Calendar: event.CalendarName} |
| + if event.AllDay { |
| + item.StartDate = event.StartLocal |
| + if event.RRule != "" && event.SeriesID == nil && event.OccurrenceLocal != "" { |
| + item.StartDate = event.OccurrenceLocal |
| + } |
| + masterStart, e1 := time.Parse(LayoutDate, event.StartLocal) |
| + masterEnd, e2 := time.Parse(LayoutDate, event.EndLocal) |
| + occurrence, e3 := time.Parse(LayoutDate, item.StartDate) |
| + if e1 != nil || e2 != nil || e3 != nil { |
| + return dashboard.Response{}, dashboard.ErrUnavailable |
| + } |
| + item.EndDate = occurrence.Add(masterEnd.Sub(masterStart)).Format(LayoutDate) |
| + if item.EndDate <= from.Format(LayoutDate) || item.StartDate >= until.Format(LayoutDate) { |
| + continue |
| + } |
| + |
| + item.Start, _ = time.ParseInLocation(LayoutDate, item.StartDate, loc) |
| + item.End, _ = time.ParseInLocation(LayoutDate, item.EndDate, loc) |
| + } |
| + out.Items = append(out.Items, item) |
| + } |
| + sort.SliceStable(out.Items, func(i, j int) bool { return out.Items[i].Start.Before(out.Items[j].Start) }) |
| + if len(out.Items) > dashboard.MaxItems { |
| + out.Truncated = true |
| + out.Items = out.Items[:dashboard.MaxItems] |
| + } |
| + return out, nil |
| +} |
diff --git a/internal/calendar/dashboard_test.go b/internal/calendar/dashboard_test.go| new file mode 100644 |
| index 0000000..51d7f25 |
| --- /dev/null |
| +++ b/internal/calendar/dashboard_test.go |
| @@ -0,0 +1,111 @@ |
| +package calendar |
| + |
| +import ( |
| + "amadan.net/oficina/home/dashboard" |
| + "github.com/go-json-experiment/json" |
| + "net/http/httptest" |
| + "testing" |
| + "time" |
| +) |
| + |
| +func TestDashboardCalendarExistingLink(t *testing.T) { |
| + t.Setenv("OFICINA_DASHBOARD_TEAM", "blue") |
| + f := newHomeConsumerFixture(t, "https://oficina.example.test") |
| + f.local(t) |
| + if w := f.do("GET", "/day/2026-10-26", ""); w.Code != 200 { |
| + t.Fatal("local calendar", w.Code) |
| + } |
| + subject := "pr_abcdefghijklmnopqrstuvwxyz" |
| + start := homeRedirect(t, f.do("POST", "/account/home", "")) |
| + homeRedirect(t, f.exchange(t, start, subject)) |
| + homeRedirect(t, f.do("POST", "/account/home/confirm", "")) |
| + call := func(sub string) *httptest.ResponseRecorder { |
| + jti, _ := dashboard.ID() |
| + nonce, _ := dashboard.ID() |
| + now := time.Now().Unix() |
| + token, e := dashboard.Sign(f.key, dashboard.Claims{Version: 1, Issuer: homeTestIssuer, Audience: homeTestOrigin, Directory: "https://oficina.example.test", Subject: sub, Team: "blue", Purpose: "dashboard-read", KeyID: "key", ID: jti, Nonce: nonce, Issued: now, Expires: now + 120}) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + r := httptest.NewRequest("GET", homeTestOrigin+dashboard.Path, nil) |
| + r.Header.Set("Authorization", "Bearer "+token) |
| + w := httptest.NewRecorder() |
| + f.app.mux.ServeHTTP(w, r) |
| + return w |
| + } |
| + w := call(subject) |
| + var data dashboard.Response |
| + if w.Code != 200 || json.Unmarshal(w.Body.Bytes(), &data) != nil || data.Items == nil || data.Timezone == "" { |
| + t.Fatal("feed", w.Code, w.Body.String()) |
| + } |
| + if w := call("pr_bbbbbbbbbbbbbbbbbbbbbbbbbb"); w.Code != 403 { |
| + t.Fatal("unknown link", w.Code) |
| + } |
| + delete(f.app.home.admitted.addrs, "alice@example.test") |
| + if w := call(subject); w.Code != 403 { |
| + t.Fatal("offboarded viewer", w.Code) |
| + } |
| +} |
| +func TestDashboardCalendarCivilDatesRecurrenceAndScope(t *testing.T) { |
| + f := newHomeRouterFixture(t) |
| + f.local(t) |
| + if w := f.do("GET", "/day/2026-10-26", ""); w.Code != 200 { |
| + t.Fatal("local calendar", w.Code) |
| + } |
| + a := f.app |
| + ctx := t.Context() |
| + var p Person |
| + if e := a.db.G.Where("address=?", "alice@example.test").First(&p).Error; e != nil { |
| + t.Fatal(e) |
| + } |
| + if e := a.db.G.Model(&p).Update("zone", "America/Los_Angeles").Error; e != nil { |
| + t.Fatal(e) |
| + } |
| + cal, e := a.store.DefaultCalendarID(ctx, p.ID) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + makeEvent := func(in EventInput) { |
| + t.Helper() |
| + in.CalendarID = cal |
| + if _, e := a.store.CreateEvent(ctx, p.ID, in); e != nil { |
| + t.Fatal(e) |
| + } |
| + } |
| + makeEvent(EventInput{Title: "Yesterday", AllDay: true, StartLocal: "2026-10-25", EndLocal: "2026-10-26", TZ: "Pacific/Honolulu"}) |
| + makeEvent(EventInput{Title: "First day", AllDay: true, StartLocal: "2026-10-26", EndLocal: "2026-10-27", TZ: "Pacific/Kiritimati"}) |
| + makeEvent(EventInput{Title: "Tomorrow", AllDay: true, StartLocal: "2026-10-27", EndLocal: "2026-10-28", TZ: "Pacific/Kiritimati"}) |
| + makeEvent(EventInput{Title: "Last day", AllDay: true, StartLocal: "2026-11-02", EndLocal: "2026-11-03", TZ: "Pacific/Honolulu"}) |
| + makeEvent(EventInput{Title: "Outside", AllDay: true, StartLocal: "2026-11-03", EndLocal: "2026-11-04", TZ: "Pacific/Kiritimati"}) |
| + makeEvent(EventInput{Title: "Afternoon", StartLocal: "2026-10-26T15:00", EndLocal: "2026-10-26T16:00", TZ: "America/Los_Angeles"}) |
| + makeEvent(EventInput{Title: "Recurring", StartLocal: "2026-10-27T09:00", EndLocal: "2026-10-27T10:00", TZ: "America/Los_Angeles", RRule: "FREQ=DAILY;COUNT=2"}) |
| + other, e := a.store.EnsurePersonSetup(ctx, "other@example.test") |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + otherCal, e := a.store.DefaultCalendarID(ctx, other.ID) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + if _, e := a.store.CreateEvent(ctx, other.ID, EventInput{CalendarID: otherCal, Title: "Private", StartLocal: "2026-10-26T16:00", EndLocal: "2026-10-26T17:00", TZ: "America/Los_Angeles"}); e != nil { |
| + t.Fatal(e) |
| + } |
| + now := time.Date(2026, 10, 26, 12, 0, 0, 0, time.UTC) |
| + data, e := a.dashboardEvents(ctx, p.ID, "", now) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + counts := map[string]int{} |
| + for i, item := range data.Items { |
| + counts[item.Title]++ |
| + if i > 0 && item.Start.Before(data.Items[i-1].Start) { |
| + t.Fatal("agenda unordered") |
| + } |
| + } |
| + if counts["Yesterday"] != 0 || counts["Outside"] != 0 || counts["Private"] != 0 || counts["First day"] != 1 || counts["Last day"] != 1 || counts["Recurring"] != 2 { |
| + t.Fatal(counts) |
| + } |
| + if len(data.Items) < 3 || data.Items[0].Title != "First day" || data.Items[1].Title != "Afternoon" || data.Items[2].Title != "Tomorrow" { |
| + t.Fatal("civil order", data.Items) |
| + } |
| +} |
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..746da72 100644 |
| --- a/internal/calendar/home.go |
| +++ b/internal/calendar/home.go |
| @@ -6,6 +6,7 @@ import ( |
| "database/sql" |
| "errors" |
| "net/http" |
| + "time" |
| "amadan.net/oficina/home/connect" |
| "amadan.net/oficina/home/connect/linkstore" |
| @@ -57,7 +58,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 +75,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 +88,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 { |
| @@ -135,3 +160,29 @@ func (a *App) homeSignin(w http.ResponseWriter, r *http.Request) { |
| } |
| a.home.routes.Signin(w, r) |
| } |
| + |
| +// homeLocalComplete is GET /auth/local/complete with Home configured: where |
| +// a local sign-in lands. After an Oficina assertion Calendar had no link |
| +// for, connect resumes the link from here, and that needs the person's |
| +// people row. A first-ever local sign-in has none yet (requirePerson makes |
| +// it on the first page), so the resume fell to /account/home, which |
| +// answered 403 (Astra's review of #31). A fresh, admitted local session |
| +// gets its person here first, exactly as requirePerson would set it up; |
| +// any other request is passed on untouched. Never from a Home subject: |
| +// only the verified local address. Failing costs only the shortcut: the |
| +// sign-in itself has already succeeded. |
| +func (a *App) homeLocalComplete(w http.ResponseWriter, r *http.Request) { |
| + if s, ok := a.home.sessions.From(r); ok && (s.Method == "magiclink" || s.Method == "keymail") { |
| + now := time.Now |
| + if a.cfg.homeNow != nil { |
| + now = a.cfg.homeNow |
| + } |
| + address := normalizeAddress(s.Subject) |
| + if _, fresh := connect.FreshLocal(connect.Session{Subject: s.Subject, Method: s.Method, AuthTime: s.AuthTime, At: s.At}, now()); fresh && address != "" && a.home.admitted.allows(address) { |
| + if _, err := a.store.EnsurePersonSetup(r.Context(), address); err != nil { |
| + a.logger.Error("calendar: ensure person before resuming a Home link", "err", err) |
| + } |
| + } |
| + } |
| + a.home.routes.LocalComplete(w, r) |
| +} |
diff --git a/internal/calendar/home_connect_item_test.go b/internal/calendar/home_connect_item_test.go| new file mode 100644 |
| index 0000000..85e85fd |
| --- /dev/null |
| +++ b/internal/calendar/home_connect_item_test.go |
| @@ -0,0 +1,234 @@ |
| +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. |
| +// "first sign-in" starts with no people row at all (Astra's review of #31): |
| +// the local sign-in must create the person before connect resumes, or the |
| +// resume falls to /account/home and that page answers 403. |
| +func TestUnknownOficinaSigninResumesAfterLocalSignin(t *testing.T) { |
| + for _, seeded := range []bool{true, false} { |
| + name := "existing person" |
| + if !seeded { |
| + name = "first sign-in" |
| + } |
| + t.Run(name, func(t *testing.T) { |
| + f := newHomeRouterFixture(t) |
| + if seeded { |
| + if _, err := f.app.store.EnsurePersonSetup(t.Context(), "alice@example.test"); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + unknownThenResume(t, f) |
| + }) |
| + } |
| +} |
| + |
| +func unknownThenResume(t *testing.T, f *homeRouterFixture) { |
| + t.Helper() |
| + 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..7253e06 100644 |
| --- a/internal/calendar/home_consumer_test.go |
| +++ b/internal/calendar/home_consumer_test.go |
| @@ -7,8 +7,8 @@ import ( |
| "io" |
| "log/slog" |
| "net/http" |
| + "net/http/httptest" |
| "path/filepath" |
| - "regexp" |
| "strings" |
| "testing" |
| @@ -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 |
| @@ -70,23 +70,54 @@ func TestHomeSigninWhenSignedInReturnsToPage(t *testing.T) { |
| } |
| } |
| -// "All apps" is the estilo switcher's item (shared-chrome spec §6), linking |
| -// to the hub directory's root: HOME_DIRECTORY_ORIGIN (an origin, which |
| -// connect refuses with a path or a trailing slash) plus "/". No directory, |
| -// no switcher. |
| -func TestAllAppsLinksToDirectory(t *testing.T) { |
| - item := regexp.MustCompile(`<details estilo-switcher[\s\S]*?<a estilo-menu-item href="([^"]*)"><span estilo-menu-label>All apps</span></a>`) |
| - for _, configured := range []string{homeTestDirectory} { |
| - f := newHomeConsumerFixture(t, configured) |
| - f.local(t) |
| - m := item.FindStringSubmatch(f.do("GET", "/day/2026-09-10", "").Body.String()) |
| - if m == nil { |
| - t.Fatalf("HOME_DIRECTORY_ORIGIN=%s: no All apps item in the estilo switcher", configured) |
| +// The switcher (shared-chrome spec §6) appears only with a hub directory |
| +// configured. It shows the suite's six apps as tiles, each at its own host |
| +// under the directory's, Calendar marked current, then below a divider |
| +// "All apps", linking to the directory's root: HOME_DIRECTORY_ORIGIN (an |
| +// origin, which connect refuses with a path or a trailing slash) plus "/". |
| +// The tiles' icons are served sessionless. |
| +func TestTheSwitcherShowsTheSuite(t *testing.T) { |
| + f := newHomeConsumerFixture(t, homeTestDirectory) |
| + f.local(t) |
| + body := f.do("GET", "/day/2026-09-10", "").Body.String() |
| + start := strings.Index(body, `<details estilo-switcher`) |
| + if start < 0 { |
| + t.Fatal("no switcher with a directory configured", body) |
| + } |
| + panel := body[start:] |
| + panel = panel[:strings.Index(panel, "</details>")] |
| + grid, allApps, ok := strings.Cut(panel, "<hr>") |
| + if !ok || !strings.Contains(allApps, `<a estilo-menu-item href="`+homeTestDirectory+`/"><span estilo-menu-label>All apps</span></a>`) { |
| + t.Error("the switcher does not offer All apps, at the directory's root, below the tiles", panel) |
| + } |
| + var tiles []string |
| + for _, tile := range strings.Split(grid, "<a estilo-switcher-app ")[1:] { |
| + tiles = append(tiles, tile[:strings.Index(tile, "</a>")]) |
| + } |
| + slugs := []string{"docs", "sheets", "slides", "calendar", "memoria", "calls"} |
| + names := []string{"Docs", "Sheets", "Slides", "Calendar", "Memoria", "Calls"} |
| + if len(tiles) != len(slugs) { |
| + t.Fatalf("%d tiles, want %d: %s", len(tiles), len(slugs), grid) |
| + } |
| + for i, slug := range slugs { |
| + head := `href="https://` + slug + `.directory.example.test/"` |
| + if slug == "calendar" { |
| + head += ` aria-current="true"` |
| } |
| - if m[1] != homeTestDirectory+"/" { |
| - t.Errorf("HOME_DIRECTORY_ORIGIN=%s: All apps links to %q, want %q", configured, m[1], homeTestDirectory+"/") |
| + head += `><img src="/static/estilo/brand/` + slug + `.svg" alt="" width="32" height="32"><span>` + names[i] |
| + if !strings.HasPrefix(tiles[i], head) { |
| + t.Errorf("tile %d = %s, want it to start %s", i, tiles[i], head) |
| } |
| } |
| + if strings.Count(grid, "aria-current") != 1 || !strings.Contains(tiles[3], "<span estilo-visually-hidden> (this app)</span>") { |
| + t.Error("Calendar is not the one current tile", grid) |
| + } |
| + |
| + icon := httptest.NewRecorder() |
| + f.app.mux.ServeHTTP(icon, httptest.NewRequest("GET", homeTestOrigin+"/static/estilo/brand/calls.svg", nil)) |
| + if icon.Code != http.StatusOK || !strings.Contains(icon.Body.String(), "<svg") { |
| + t.Errorf("a tile's icon, with no session, is %d", icon.Code) |
| + } |
| bare := newHomeConsumerFixture(t, "") |
| bare.local(t) |
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/migrations.go b/internal/calendar/migrations.go| index a72e45d..8e9050d 100644 |
| --- a/internal/calendar/migrations.go |
| +++ b/internal/calendar/migrations.go |
| @@ -1,6 +1,7 @@ |
| package calendar |
| import ( |
| + "amadan.net/oficina/home/dashboard" |
| "embed" |
| "amadan.net/rastrillo/rastrillo/migrate" |
| @@ -36,4 +37,4 @@ var Schema = migrate.MustFromFS(migrationFS, "calendar") |
| // sessions table, so sessions.Schema must apply first. Get this line |
| // wrong and boot either skips a subsystem's tables or fails on a |
| // migration that references one that does not exist yet. |
| -var BootSchema = migrate.Merge(sessions.Schema, authSchema, Schema) |
| +var BootSchema = migrate.Merge(migrate.MustFromFS(dashboard.Migrations, "oficina_dashboard"), sessions.Schema, authSchema, Schema) |
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/routes.go b/internal/calendar/routes.go| index 3e982fa..f3e8d5c 100644 |
| --- a/internal/calendar/routes.go |
| +++ b/internal/calendar/routes.go |
| @@ -1,6 +1,7 @@ |
| package calendar |
| import ( |
| + "amadan.net/oficina/estilo.git/brand" |
| "amadan.net/oficina/estilo.git/sky" |
| "amadan.net/oficina/estilo.git/theme" |
| "amadan.net/oficina/home/connect" |
| @@ -37,6 +38,9 @@ func (a *App) routes(h *handlers, authPlugin *rauth.Auth, list allowlist, origin |
| } |
| r.Handle("/native/*", a.native) |
| + if a.dashboard != nil { |
| + r.Handle("/api/oficina/dashboard", a.dashboard) |
| + } |
| r.Get("/help/open-source", h.credits) |
| r.NotFound(h.notFound) |
| @@ -45,7 +49,7 @@ func (a *App) routes(h *handlers, authPlugin *rauth.Auth, list allowlist, origin |
| r.Get("/signin", a.homeSignin) |
| r.Get("/signin/local", h.signin) |
| r.Get("/signed-out", a.home.routes.SignedOut) |
| - r.Get(connect.LocalCompletePath, a.home.routes.LocalComplete) |
| + r.Get(connect.LocalCompletePath, a.homeLocalComplete) |
| r.Get(handoff.StartPath, a.home.bridge.Start) |
| r.Post(handoff.CallbackPath, a.home.bridge.Callback) |
| r.Get(handoff.FinishPath, a.home.bridge.Finish) |
| @@ -175,12 +179,17 @@ func (a *App) routes(h *handlers, authPlugin *rauth.Auth, list allowlist, origin |
| mux := http.NewServeMux() |
| // The app serves its own static files — the framework never does. |
| mux.Handle("GET /static/", assets.Handler()) |
| - // Onest, Calma's typeface, served by estilo under its versioned prefix. |
| + // estilo's retired v1 Onest files, kept answering so a page cached |
| + // before the chrome moved to the system face (estilo AGENTS.md row 9) |
| + // still resolves its stylesheet. No page links them. |
| mux.Handle("GET "+theme.FontPrefix, theme.FontHandler()) |
| // The sign-in door's sky: a closed set of drawings, sessionless and |
| // reachable signed out. More specific than "GET /static/", so the |
| // app's own asset handler never sees these paths. |
| mux.Handle("GET "+sky.Prefix, sky.Handler()) |
| + // The app switcher's tile icons, the suite's own marks: sessionless |
| + // for the same reason, and likewise more specific than "GET /static/". |
| + mux.Handle("GET "+brand.Prefix, brand.Handler()) |
| mux.HandleFunc("GET /static/credits.css", serveCreditsCSS) |
| a.mountTick(mux, h) |
| if a.agent != nil { |
diff --git a/internal/calendar/static/chrome.css b/internal/calendar/static/chrome.css| index 74bd3d7..d16395d 100644 |
| --- a/internal/calendar/static/chrome.css |
| +++ b/internal/calendar/static/chrome.css |
| @@ -184,6 +184,15 @@ |
| [estilo-switcher-app]:focus-visible { background: var(--rst-accent-soft); } |
| [estilo-switcher-app][aria-current] { background: var(--rst-accent-soft); font-weight: 600; } |
| [estilo-switcher-app] img { border-radius: 21%; } |
| +/* Three 5.5rem tiles hung from the trigger overflow a phone's inline start |
| + (at 320px, and sooner when the corner is the wider "Sign in" link), so |
| + below 30rem the panel spans the bar instead, as menubar panels do, and |
| + the three columns share its width. */ |
| +@media (max-width: 30rem) { |
| + [estilo-switcher] { position: static; } |
| + [estilo-switcher-panel] { inset-inline: 0.5rem; inline-size: auto; min-inline-size: 0; max-inline-size: none; } |
| + [estilo-switcher-grid] { grid-template-columns: repeat(3, minmax(0, 1fr)); } |
| +} |
| /* The account menu. The account is always the last thing at the inline |
| end of the bar: the "same corner" rule. */ |
| @@ -208,6 +217,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; } |
diff --git a/internal/calendar/static/theme.css b/internal/calendar/static/theme.css| index 656dafb..512ea71 100644 |
| --- a/internal/calendar/static/theme.css |
| +++ b/internal/calendar/static/theme.css |
| @@ -36,9 +36,11 @@ |
| :root { |
| color-scheme: light dark; |
| - /* Type: the family only. Sizes and spacing stay in tokens.css. Onest |
| - where it is served (fonts.go), the system face where it is not. */ |
| - --rst-font: "Onest", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; |
| + /* Type: the family only. Sizes and spacing stay in tokens.css. The |
| + system UI face, nothing downloaded: Paul, 2026-10-25 (AGENTS.md row |
| + 9). A webfont cannot render in WebKit without a frame of invisible |
| + text, and the chrome never flashes. TestChromeFontIsSystemUI. */ |
| + --rst-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; |
| /* Shape: soft and exact. */ |
| --rst-radius: 12px; |
diff --git a/internal/calendar/templates/layout.html b/internal/calendar/templates/layout.html| index 883fe49..d97894c 100644 |
| --- a/internal/calendar/templates/layout.html |
| +++ b/internal/calendar/templates/layout.html |
| @@ -7,11 +7,10 @@ |
| <link rel="icon" type="image/png" sizes="32x32" href="{{asset "static/brand/icon-32.png"}}"> |
| <link rel="icon" type="image/svg+xml" href="{{asset "static/brand/icon.svg"}}"> |
| <link rel="apple-touch-icon" sizes="180x180" href="{{asset "static/brand/apple-touch-icon.png"}}"> |
| -{{/* Onest, Calma's typeface, served by estilo (routes.go). Then the |
| - spec's order: tokens, theme, brand, estilo base, menu, chrome, and the |
| - app's own CSS last. busy.css is the 650ms busy rule; sky.css is the |
| - sign-in door's sky. */}} |
| -<link rel="stylesheet" href="/static/estilo/fonts/v1/fonts.css"> |
| +{{/* The spec's order: tokens, theme, brand, estilo base, menu, chrome, |
| + and the app's own CSS last. busy.css is the 650ms busy rule; sky.css |
| + is the sign-in door's sky. No webfont: the chrome is the system UI |
| + face, so it never flashes (estilo AGENTS.md row 9). */}} |
| <link rel="stylesheet" href="{{asset "static/tokens.css"}}"> |
| <link rel="stylesheet" href="{{asset "static/busy.css"}}"> |
| <link rel="stylesheet" href="{{asset "static/theme.css"}}"> |
diff --git a/internal/calendartest/fontlink_test.go b/internal/calendartest/fontlink_test.go| deleted file mode 100644 |
| index 32496b1..0000000 |
| --- a/internal/calendartest/fontlink_test.go |
| +++ /dev/null |
| @@ -1,24 +0,0 @@ |
| -package calendartest |
| - |
| -import ( |
| - "bytes" |
| - "os" |
| - "path/filepath" |
| - "testing" |
| - |
| - "amadan.net/oficina/estilo.git/theme" |
| -) |
| - |
| -// The layout names Onest's stylesheet by a literal path; this keeps that |
| -// literal equal to estilo's versioned prefix, so an estilo font move |
| -// fails here rather than every page quietly falling back to the system |
| -// face. |
| -func TestLayoutLinksEstilosFonts(t *testing.T) { |
| - layout, err := os.ReadFile(filepath.Join("..", "calendar", "templates", "layout.html")) |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| - if want := `href="` + theme.FontPrefix + `fonts.css"`; !bytes.Contains(layout, []byte(want)) { |
| - t.Errorf("layout.html does not link %s", want) |
| - } |
| -} |
diff --git a/internal/calendartest/nowebfont_test.go b/internal/calendartest/nowebfont_test.go| new file mode 100644 |
| index 0000000..41052d4 |
| --- /dev/null |
| +++ b/internal/calendartest/nowebfont_test.go |
| @@ -0,0 +1,91 @@ |
| +package calendartest |
| + |
| +import ( |
| + "io/fs" |
| + "net/http" |
| + "os" |
| + "path" |
| + "path/filepath" |
| + "regexp" |
| + "strings" |
| + "testing" |
| + |
| + "amadan.net/oficina/estilo.git/theme" |
| +) |
| + |
| +// The chrome is set in the system UI face and downloads no font, so it |
| +// can never flash (Paul, 2026-10-25: "There should never be a flash of |
| +// unstyled text. Ever." estilo AGENTS.md row 9). No page links or |
| +// preloads a webfont: not estilo's retired Onest, and no font file at |
| +// all. estilo's v1 files stay mounted (routes.go) so a page cached before |
| +// this still resolves its stylesheet; nothing may name them. |
| +// |
| +// This replaces TestLayoutLinksEstilosFonts, which required the link. |
| +func TestNoPageLinksOrPreloadsAChromeWebfont(t *testing.T) { |
| + // Every template, as source: whichever route renders a page, it is |
| + // made of these. |
| + pages := 0 |
| + root := filepath.Join("..", "calendar", "templates") |
| + err := filepath.WalkDir(root, func(p string, d fs.DirEntry, err error) error { |
| + if err != nil || d.IsDir() || filepath.Ext(p) != ".html" { |
| + return err |
| + } |
| + b, err := os.ReadFile(p) |
| + if err != nil { |
| + return err |
| + } |
| + pages++ |
| + for _, why := range chromeWebfonts(string(b)) { |
| + t.Errorf("%s %s", p, why) |
| + } |
| + return nil |
| + }) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if pages < 10 { |
| + t.Fatalf("read only %d templates under %s; the scan would pass vacuously", pages, root) |
| + } |
| + |
| + // And as served, on the page every visitor meets first. |
| + h := newApp(t).Handler() |
| + rec := get(t, h, "/signin") |
| + if rec.Code != http.StatusOK { |
| + t.Fatalf("GET /signin = %d", rec.Code) |
| + } |
| + for _, why := range chromeWebfonts(rec.Body.String()) { |
| + t.Errorf("GET /signin %s", why) |
| + } |
| + |
| + // The retired files still answer, for pages cached before the change. |
| + for _, name := range []string{"fonts.css", "onest-latin.woff2"} { |
| + if rec := get(t, h, theme.FontPrefix+name); rec.Code != http.StatusOK { |
| + t.Errorf("GET %s%s = %d; keep estilo's font handler mounted for old pages", theme.FontPrefix, name, rec.Code) |
| + } |
| + } |
| +} |
| + |
| +var ( |
| + linkTag = regexp.MustCompile(`(?is)<link\b[^>]*>`) |
| + asFont = regexp.MustCompile(`(?i)\bas\s*=\s*["']?font\b`) |
| + fontFile = regexp.MustCompile(`(?i)\.(woff2?|ttf|otf|eot)\b`) |
| +) |
| + |
| +// chromeWebfonts names each way html would download a font for the |
| +// chrome: estilo's font path at any version, a <link> that preloads a |
| +// font or names a font file, or a face declared inline. |
| +func chromeWebfonts(html string) []string { |
| + var found []string |
| + if dir := path.Dir(strings.TrimSuffix(theme.FontPrefix, "/")) + "/"; strings.Contains(html, dir) { |
| + found = append(found, "names estilo's webfont path "+dir) |
| + } |
| + for _, tag := range linkTag.FindAllString(html, -1) { |
| + if asFont.MatchString(tag) || fontFile.MatchString(tag) { |
| + found = append(found, "links or preloads a font: "+tag) |
| + } |
| + } |
| + if strings.Contains(strings.ToLower(html), "@font-face") { |
| + found = append(found, "declares a font face inline") |
| + } |
| + return found |
| +} |