oficina / calendar Public

Merge branch 'feat/dashboard-feed' into main

Provide an authorized upcoming agenda for the Oficina dashboard
codex agent, operated by paul@keymail.dev cc6f69a8884e39c2eb788daaea04ab8f78a7c5af parent 5ab1821parent 475bc92
9 files changed, +225 −12
  • Makefile +1 −1
  • go.mod +5 −2
  • go.sum +2 −0
  • internal/calendar/app.go +13 −7
  • internal/calendar/credits_inventory_test.go +1 −1
  • internal/calendar/dashboard.go +87 −0
  • internal/calendar/dashboard_test.go +111 −0
  • internal/calendar/migrations.go +2 −1
  • internal/calendar/routes.go +3 −0

CI passed — run details

landed from feat/dashboard-feed

diff --git a/Makefile b/Makefile
index 814f9b4..be9dd80 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/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/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 ec7f57e..6a6cc8a 100644
--- a/go.mod
+++ b/go.mod
@@ -21,7 +21,7 @@ require (
github.com/chromedp/cdproto v0.0.0-20250724212937-08a3db8b4327
github.com/chromedp/sysutil v1.1.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
- github.com/go-json-experiment/json v0.0.0-20250725192818-e39067aee2d2 // indirect
+ github.com/go-json-experiment/json v0.0.0-20250725192818-e39067aee2d2
github.com/gobwas/httphead v0.1.0 // indirect
github.com/gobwas/pool v0.2.1 // indirect
github.com/gobwas/ws v1.4.0 // indirect
@@ -42,7 +42,10 @@ require (
modernc.org/sqlite v1.55.0 // indirect
)
-require amadan.net/rastrillo/native/server v0.0.0-20260923173546-2a5d07b2c8d3
+require (
+ amadan.net/oficina/home/dashboard v0.0.0-20261024234842-3774eb68f816
+ amadan.net/rastrillo/native/server v0.0.0-20260923173546-2a5d07b2c8d3
+)
require (
amadan.net/rastrillo/rastrillo/money v0.1.0 // indirect
diff --git a/go.sum b/go.sum
index 51c7269..a979ce6 100644
--- a/go.sum
+++ b/go.sum
@@ -2,6 +2,8 @@ amadan.net/oficina/estilo.git v0.0.0-20261024233714-f14458a4683c h1:jPbFJwPi7lHe
amadan.net/oficina/estilo.git v0.0.0-20261024233714-f14458a4683c/go.mod h1:4u0jNBtIdMLOsJyrScfqoEuYDJF7BBM3qM9YWbzt6aw=
amadan.net/oficina/home/connect v0.0.0-20261024233715-ff16bf56bc4d h1:9sVZBph2xUuejZt73DYaoCfoyvrvZCnuPHcyMsg562E=
amadan.net/oficina/home/connect v0.0.0-20261024233715-ff16bf56bc4d/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=
diff --git a/internal/calendar/app.go b/internal/calendar/app.go
index 12bccda..505105a 100644
--- a/internal/calendar/app.go
+++ b/internal/calendar/app.go
@@ -30,13 +30,14 @@ import (
// development mail recorder both hang off this struct, and every later
// test depends on them.
type App struct {
- native *nativeauth.Auth
- home *homeConnection
- cfg Config
- db *db.DB
- mux *http.ServeMux
- logger *slog.Logger
- store *Store
+ dashboard http.Handler
+ native *nativeauth.Auth
+ home *homeConnection
+ cfg Config
+ db *db.DB
+ mux *http.ServeMux
+ logger *slog.Logger
+ store *Store
// mailRecorder is non-nil only in development — see buildMailer.
mailRecorder *recordingMailer
@@ -176,6 +177,11 @@ 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
diff --git a/internal/calendar/credits_inventory_test.go b/internal/calendar/credits_inventory_test.go
index 851c02b..806bd87 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/estilo.git": true, "amadan.net/oficina/home/handoff": true, "amadan.net/oficina/home/connect": true, "amadan.net/rastrillo/native/server": true})
+ inventory, err := catalog.Collect(bytes.NewReader(raw), map[string]bool{"amadan.net/oficina/home/dashboard": 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/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/routes.go b/internal/calendar/routes.go
index 426eacc..c560301 100644
--- a/internal/calendar/routes.go
+++ b/internal/calendar/routes.go
@@ -38,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)