Add scoped read-only Oficina dashboard feed
9 files changed,
+124
−3
go.mod+1 −0go.sum+2 −0internal/slides/app.go+3 −0internal/slides/dashboard.go+49 −0internal/slides/dashboard_test.go+59 −0internal/slides/handlers.go+2 −0internal/slides/home.go+3 −0internal/slides/home_test.go+3 −2internal/slides/migrations.go+2 −1
CI cancelled — superseded by a newer push — run details
diff --git a/go.mod b/go.mod| index 969daad..b0372b2 100644 |
| --- a/go.mod |
| +++ b/go.mod |
| @@ -7,6 +7,7 @@ toolchain go1.26.5 |
| require ( |
| amadan.net/oficina/estilo.git v0.0.0-20261024225350-d53b8e9533a1 |
| amadan.net/oficina/home/connect v0.0.0-20261001093757-2bec942ddd0c |
| + amadan.net/oficina/home/dashboard v0.0.0-20261024234842-3774eb68f816 |
| amadan.net/oficina/home/handoff v0.0.0-20260908102137-481d2d57f489 |
| amadan.net/rastrillo/rastrillo v0.27.1-0.20261006204347-fb806a287060 |
| github.com/chromedp/cdproto v0.0.0-20250724212937-08a3db8b4327 |
diff --git a/go.sum b/go.sum| index e8281d7..be1a639 100644 |
| --- a/go.sum |
| +++ b/go.sum |
| @@ -2,6 +2,8 @@ amadan.net/oficina/estilo.git v0.0.0-20261024225350-d53b8e9533a1 h1:Xaidrm9rzFyn |
| amadan.net/oficina/estilo.git v0.0.0-20261024225350-d53b8e9533a1/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/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-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/rastrillo v0.27.1-0.20261006204347-fb806a287060 h1:K2PXcCKfm+AYrqgH1ea6cNsFs4sN7MKLvq+uBY11NZE= |
diff --git a/internal/slides/app.go b/internal/slides/app.go| index 6f08bc2..3ef78fe 100644 |
| --- a/internal/slides/app.go |
| +++ b/internal/slides/app.go |
| @@ -68,6 +68,9 @@ func New(d *db.DB, cfg Config) (*http.ServeMux, *app, error) { |
| r.NotFound(a.routeNotFound) |
| r.MethodNotAllowed(a.methodNotAllowed(r)) |
| + if a.dashboard != nil { |
| + r.Handle("/api/oficina/dashboard", a.dashboard) |
| + } |
| r.Get("/help/open-source", a.credits) |
| // The account menu's Appearance (estilo chrome). Inside the app-wide |
| // CSRF check above and outside the session group below: a session |
diff --git a/internal/slides/dashboard.go b/internal/slides/dashboard.go| new file mode 100644 |
| index 0000000..05eda2e |
| --- /dev/null |
| +++ b/internal/slides/dashboard.go |
| @@ -0,0 +1,49 @@ |
| +package slides |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "os" |
| + "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: "documents", Resolve: func(ctx context.Context, subject string) (int64, error) { |
| + p, e := a.home.Resolve(ctx, subject) |
| + if errors.Is(e, linkstore.ErrStorage) { |
| + return 0, dashboard.ErrUnavailable |
| + } |
| + return p.ID, e |
| + }, Read: a.dashboardDocuments}) |
| + if e != nil { |
| + return e |
| + } |
| + a.dashboard = h |
| + return nil |
| +} |
| +func (a *app) dashboardDocuments(ctx context.Context, id int64, _ string, _ time.Time) (dashboard.Response, error) { |
| + var viewer User |
| + if e := a.db.G.WithContext(ctx).First(&viewer, id).Error; e != nil { |
| + return dashboard.Response{}, e |
| + } |
| + var rows []Deck |
| + if e := a.visibleDecks(ctx, viewer).Order("decks.updated_at DESC, decks.id DESC").Limit(dashboard.MaxItems + 1).Find(&rows).Error; e != nil { |
| + return dashboard.Response{}, e |
| + } |
| + out := dashboard.Response{Truncated: len(rows) > dashboard.MaxItems} |
| + if out.Truncated { |
| + rows = rows[:dashboard.MaxItems] |
| + } |
| + for _, d := range rows { |
| + out.Items = append(out.Items, dashboard.Item{ID: d.Sqid, Title: d.Title, URL: a.cfg.Origin + "/d/" + d.Sqid, Updated: d.UpdatedAt}) |
| + } |
| + return out, nil |
| +} |
diff --git a/internal/slides/dashboard_test.go b/internal/slides/dashboard_test.go| new file mode 100644 |
| index 0000000..9d4a423 |
| --- /dev/null |
| +++ b/internal/slides/dashboard_test.go |
| @@ -0,0 +1,59 @@ |
| +package slides |
| + |
| +import ( |
| + "amadan.net/oficina/home/dashboard" |
| + "github.com/go-json-experiment/json" |
| + "net/http/httptest" |
| + "testing" |
| + "time" |
| +) |
| + |
| +func TestDashboardScopedDecksAndExistingLink(t *testing.T) { |
| + t.Setenv("OFICINA_DASHBOARD_TEAM", "blue") |
| + mux, a, u, key := homeFixtureDirectory(t, "https://oficina.example.com") |
| + subject := "pr_abcdefghijklmnopqrstuvwxyz" |
| + homeLinkedSubject(t, a, u, subject) |
| + for _, row := range []Deck{{Sqid: "own", Title: "Own", OwnerID: u.ID, Rung: "private"}, {Sqid: "private", Title: "Hidden", OwnerID: 999, Rung: "private"}, {Sqid: "shared", Title: "Shared", OwnerID: 999, Rung: "granted"}} { |
| + if e := a.db.G.Create(&row).Error; e != nil { |
| + t.Fatal(e) |
| + } |
| + } |
| + var shared Deck |
| + a.db.G.Where("sqid=?", "shared").First(&shared) |
| + if e := a.db.G.Create(&DeckGrant{DeckID: shared.ID, UserID: u.ID}).Error; e != nil { |
| + t.Fatal(e) |
| + } |
| + call := func(sub string) *httptest.ResponseRecorder { |
| + jti, _ := dashboard.ID() |
| + nonce, _ := dashboard.ID() |
| + now := time.Now().Unix() |
| + token, e := dashboard.Sign(key, dashboard.Claims{Version: 1, Issuer: "https://home.example.com", Audience: homeTestOrigin, Directory: "https://oficina.example.com", Subject: sub, Team: "blue", Purpose: "dashboard-read", KeyID: "test", 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() |
| + mux.ServeHTTP(w, r) |
| + return w |
| + } |
| + w := call(subject) |
| + var data dashboard.Response |
| + if w.Code != 200 || json.Unmarshal(w.Body.Bytes(), &data) != nil || len(data.Items) != 2 { |
| + t.Fatal("feed", w.Code, w.Body.String()) |
| + } |
| + for _, item := range data.Items { |
| + if item.Title == "Hidden" { |
| + t.Fatal("private deck exposed") |
| + } |
| + } |
| + if w := call("pr_bbbbbbbbbbbbbbbbbbbbbbbbbb"); w.Code != 403 { |
| + t.Fatal("unknown link", w.Code) |
| + } |
| + if e := a.db.G.Where("id=?", u.ID).Delete(&User{}).Error; e != nil { |
| + t.Fatal(e) |
| + } |
| + if w := call(subject); w.Code != 403 { |
| + t.Fatal("deleted viewer", w.Code) |
| + } |
| +} |
diff --git a/internal/slides/handlers.go b/internal/slides/handlers.go| index 2de7561..a6c1575 100644 |
| --- a/internal/slides/handlers.go |
| +++ b/internal/slides/handlers.go |
| @@ -3,6 +3,7 @@ package slides |
| import ( |
| "context" |
| "log/slog" |
| + "net/http" |
| "time" |
| "amadan.net/oficina/home/connect" |
| @@ -26,6 +27,7 @@ import ( |
| // The handlers themselves live beside what they serve: sign-in in |
| // auth.go, the deck screens in decks.go. |
| type app struct { |
| + dashboard http.Handler |
| home *connect.Bridge |
| homeRoutes *connect.Routes |
| homeSessions *sessions.Sessions |
diff --git a/internal/slides/home.go b/internal/slides/home.go| index d995a05..d41cd68 100644 |
| --- a/internal/slides/home.go |
| +++ b/internal/slides/home.go |
| @@ -76,6 +76,9 @@ func (a *app) initHome(c *connect.DecodedCredentials) error { |
| } |
| a.home = b |
| a.directory = c.Directory |
| + if err := a.configureDashboard(c); err != nil { |
| + return err |
| + } |
| a.homeRoutes, err = connect.NewRoutes(b, connect.RoutesConfig{Namespace: "oficina/slides", Origin: a.cfg.Origin, Issuer: c.Issuer, DEK: c.DEK, SessionCookie: sess.CookieName(), ReadSession: read, SignOut: sess.SignOut, LocalSignin: a.signin, Protect: csrf.Protect(a.cfg.Origin), Render: a.renderHome, FormPolicy: connect.FormPolicy(c.Issuer)}) |
| return err |
| } |
diff --git a/internal/slides/home_test.go b/internal/slides/home_test.go| index 5f9a885..2009570 100644 |
| --- a/internal/slides/home_test.go |
| +++ b/internal/slides/home_test.go |
| @@ -77,7 +77,8 @@ func homeSession(t *testing.T, a *app, subject, method string) *http.Cookie { |
| t.Fatal("missing session cookie") |
| return nil |
| } |
| -func homeLinked(t *testing.T, a *app, u User) { |
| +func homeLinked(t *testing.T, a *app, u User) { homeLinkedSubject(t, a, u, "home-person") } |
| +func homeLinkedSubject(t *testing.T, a *app, u User, subject string) { |
| t.Helper() |
| ctx := context.Background() |
| now := time.Now() |
| @@ -102,7 +103,7 @@ func homeLinked(t *testing.T, a *app, u User) { |
| if err := store.BindNonce(ctx, init, local, nonce, now); err != nil { |
| t.Fatal(err) |
| } |
| - proof, err := store.Complete(ctx, init, local, linkstore.Home{Issuer: c.Issuer, Subject: "home-person", Nonce: nonce, AuthTime: now}, now) |
| + proof, err := store.Complete(ctx, init, local, linkstore.Home{Issuer: c.Issuer, Subject: subject, Nonce: nonce, AuthTime: now}, now) |
| if err != nil { |
| t.Fatal(err) |
| } |
diff --git a/internal/slides/migrations.go b/internal/slides/migrations.go| index 870ba98..9b1d37f 100644 |
| --- a/internal/slides/migrations.go |
| +++ b/internal/slides/migrations.go |
| @@ -1,6 +1,7 @@ |
| package slides |
| import ( |
| + "amadan.net/oficina/home/dashboard" |
| "embed" |
| rauth "amadan.net/rastrillo/rastrillo/auth" |
| @@ -37,4 +38,4 @@ var Schema = migrate.MustFromFS(migrationFS, "slides") |
| // must apply before auth.Schema, and this app's own Schema last. |
| // Get this line wrong and either boot silently skips a subsystem's |
| // tables, or generate/check try to drop them. |
| -var BootSchema = migrate.Merge(sessions.Schema, rauth.Schema, Schema) |
| +var BootSchema = migrate.Merge(migrate.MustFromFS(dashboard.Migrations, "oficina_dashboard"), sessions.Schema, rauth.Schema, Schema) |