console: platform-wide Activity for operators
/fleet/activity: every audit row, newest first, fifty to a page with Newest and Older keyed on the row id, filtered by kind and by account. The account filter resolves deleted accounts too, so a deleted account's history stays reachable from its links. SQLite only. Also: the People accounts test checks Plan, Apps and Members in order (Task 10 review note), and on a phone the activity lists keep When at a fixed width so What lines up.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
13 files changed,
+655
−11
approved_operator_pages_copy_test.go+4 −0internal/console/claim_invariant_fixtures_test.go+1 −0internal/console/claim_invariant_probes_read_test.go+1 −0internal/console/opactivity.go+183 −0internal/console/opactivity_test.go+365 −0internal/console/opdashboard_test.go+13 −4internal/console/oppeople_test.go+31 −4internal/console/opshots_test.go+1 −0internal/console/perfwalk_test.go+10 −1internal/console/server.go+4 −0internal/console/static/ops.css+15 −2internal/console/templates/ops_activity.html+26 −0internal/console/testdata/claim-routes.txt+1 −0
CI failed — run details
diff --git a/approved_operator_pages_copy_test.go b/approved_operator_pages_copy_test.go| index 9f842e536..f4eaaf7ce 100644 |
| --- a/approved_operator_pages_copy_test.go |
| +++ b/approved_operator_pages_copy_test.go |
| @@ -75,6 +75,10 @@ var operatorPagesCopyBuilt = []string{ |
| "OPS-103", "OPS-104@oppeople.go", "OPS-105@oppeople.go", "OPS-106@oppeople.go", |
| "OPS-107@oppeople.go", "OPS-108@oppeople.go", "OPS-109@oppeople.go", "OPS-110@oppeople.go", |
| "OPS-111", "OPS-112", "OPS-113", "OPS-114", "OPS-115", "OPS-116", "OPS-117", "OPS-118", |
| + // Task 11: Activity. The dropdown's accessible name and the pager's |
| + // Newest and Older are built in opactivity.go (feedView's data). |
| + "OPS-119", "OPS-120@opactivity.go", "OPS-121", "OPS-122", "OPS-123", "OPS-124", "OPS-125", |
| + "OPS-126", "OPS-127", "OPS-128@opactivity.go", "OPS-129@opactivity.go", "OPS-130", "OPS-148", |
| } |
| // operatorPagesBuiltRows is entryBuiltRows for operatorPagesCopyBuilt. |
diff --git a/internal/console/claim_invariant_fixtures_test.go b/internal/console/claim_invariant_fixtures_test.go| index 82fe873c7..ae330986f 100644 |
| --- a/internal/console/claim_invariant_fixtures_test.go |
| +++ b/internal/console/claim_invariant_fixtures_test.go |
| @@ -891,6 +891,7 @@ var claimFixtures = map[string]claimFixture{ |
| "route GET /fleet": claimRead("operator dashboard: SQLite counts, fleet.json, box snapshots, the storage queue"), |
| "route GET /fleet/boxes": claimRead("operator boxes view: fleet.json, box snapshots, the storage queue"), |
| "route GET /fleet/economics": claimRead("operator economics view"), |
| + "route GET /fleet/activity": claimRead("operator activity feed; SQLite only"), |
| "route GET /fleet/economics/accounts": claimRead("operator per-account economics table"), |
| "route GET /fleet/index": claimRead("operator section index; reads nothing remote"), |
| "route GET /fleet/metrics": claimRead("operator box metrics"), |
diff --git a/internal/console/claim_invariant_probes_read_test.go b/internal/console/claim_invariant_probes_read_test.go| index 730b0e0e8..9b272356a 100644 |
| --- a/internal/console/claim_invariant_probes_read_test.go |
| +++ b/internal/console/claim_invariant_probes_read_test.go |
| @@ -169,6 +169,7 @@ var claimReadProbes = map[string]claimProbe{ |
| "route GET /auth/cli": claimPageRead(nil, "/auth/cli", "<h1>Approve a terminal</h1>"), |
| "route GET /invite/{token}": claimInvitePageProbe(), |
| "route GET /fleet": claimPageRead(nil, "/fleet", "<h1>Dashboard</h1>"), |
| + "route GET /fleet/activity": claimPageRead(nil, "/fleet/activity", "<h1>Activity</h1>"), |
| "route GET /fleet/boxes": claimPageRead(nil, "/fleet/boxes", "<h1>Boxes</h1>"), |
| "route GET /fleet/economics": claimPageRead(nil, "/fleet/economics", "<h1>Fleet economics</h1>"), |
| "route GET /fleet/economics/accounts": claimPageRead(nil, "/fleet/economics/accounts", "<h1>Fleet economics: accounts</h1>"), |
diff --git a/internal/console/opactivity.go b/internal/console/opactivity.go| new file mode 100644 |
| index 000000000..7362792a9 |
| --- /dev/null |
| +++ b/internal/console/opactivity.go |
| @@ -0,0 +1,183 @@ |
| +package console |
| + |
| +import ( |
| + "fmt" |
| + "log" |
| + "net/http" |
| + "net/url" |
| + "strconv" |
| +) |
| + |
| +// Activity (/fleet/activity, spec 2026-10-25 Part 3): every audit row on the |
| +// platform, newest first, filtered by kind and by account, fifty to a page |
| +// with Newest and Older links keyed on the row id. SQLite only: no bucket |
| +// read, no remote call. |
| + |
| +// feedPageSize is the rows on one page of the feed. |
| +const feedPageSize = 50 |
| + |
| +// feedKind is one choice of the kind filter: its query value, its label, |
| +// and the actions it keeps (or, when Exclude, the actions it drops). |
| +type feedKind struct { |
| + Key, Label string |
| + Actions []string |
| + Exclude bool |
| +} |
| + |
| +// feedKinds is every kind, in the dropdown's order. The first is the |
| +// default; "other" is every action the named kinds hold. |
| +var feedKinds = []feedKind{ |
| + {Key: "all", Label: "Everything"}, |
| + {Key: "deploys", Label: "Deploys", Actions: deployActions}, |
| + {Key: "signins", Label: "Sign-ins", Actions: []string{auditSignin, auditFirstSignin}}, |
| + {Key: "accounts", Label: "Accounts and invites", Actions: []string{ |
| + auditInviteSent, auditInviteAccepted, auditAccountCreated, auditAccountDeleted}}, |
| + {Key: "other", Label: "Other changes", Actions: feedNamedActions(), Exclude: true}, |
| +} |
| + |
| +// feedNamedActions is every action the deploys, sign-ins and accounts kinds |
| +// keep: what "other" leaves out. |
| +func feedNamedActions() []string { |
| + out := append([]string(nil), deployActions...) |
| + return append(out, accountAuditActions...) |
| +} |
| + |
| +// feedKindOf is the kind with that key, or the first (everything). |
| +func feedKindOf(key string) feedKind { |
| + for _, k := range feedKinds { |
| + if k.Key == key { |
| + return k |
| + } |
| + } |
| + return feedKinds[0] |
| +} |
| + |
| +// filter is the store filter for kind k, every account. |
| +func (k feedKind) filter() ActivityFilter { |
| + if k.Exclude { |
| + return ActivityFilter{Exclude: k.Actions} |
| + } |
| + return ActivityFilter{Actions: k.Actions} |
| +} |
| + |
| +// feedQuery is the page's parameters, parsed and clamped. Account is the |
| +// sqid as given; the handler resolves it. |
| +type feedQuery struct { |
| + Kind, Account string |
| + Before int64 |
| +} |
| + |
| +// parseFeedQuery reads kind, account and before: an unknown kind is "all"; |
| +// before is a positive integer, else 0; account is kept as text. |
| +func parseFeedQuery(v url.Values) feedQuery { |
| + q := feedQuery{Kind: feedKindOf(v.Get("kind")).Key, Account: v.Get("account")} |
| + if n, err := strconv.ParseInt(v.Get("before"), 10, 64); err == nil && n > 0 { |
| + q.Before = n |
| + } |
| + return q |
| +} |
| + |
| +// href is the feed's URL with q's kind and account (each when set), and |
| +// before when it is positive. |
| +func (q feedQuery) href() string { |
| + v := url.Values{} |
| + if q.Kind != feedKinds[0].Key { |
| + v.Set("kind", q.Kind) |
| + } |
| + if q.Account != "" { |
| + v.Set("account", q.Account) |
| + } |
| + if q.Before > 0 { |
| + v.Set("before", strconv.FormatInt(q.Before, 10)) |
| + } |
| + if enc := v.Encode(); enc != "" { |
| + return "/fleet/activity?" + enc |
| + } |
| + return "/fleet/activity" |
| +} |
| + |
| +// AccountHref is the feed of one account, keeping the kind: where a row's |
| +// account name links. |
| +func (q feedQuery) AccountHref(sqid string) string { |
| + return feedQuery{Kind: q.Kind, Account: sqid}.href() |
| +} |
| + |
| +// ClearAccountHref is the feed without the account filter, keeping the kind. |
| +func (q feedQuery) ClearAccountHref() string { |
| + return feedQuery{Kind: q.Kind}.href() |
| +} |
| + |
| +// feedView is the page's data (page.Feed). AccountName is the filter line's |
| +// name when an account filter is on: the account's name, or the sqid as |
| +// given when no account has it. AccountDeleted marks a deleted account. |
| +type feedView struct { |
| + Query feedQuery |
| + Kind opDropdown |
| + AccountName string |
| + AccountDeleted bool |
| + Rows []FeedRow |
| + Pager opPager |
| +} |
| + |
| +// feedDropdown is the kind filter: the current kind as its label, each |
| +// kind's link keeping the account and dropping before. |
| +func feedDropdown(q feedQuery) opDropdown { |
| + cur := feedKindOf(q.Kind) |
| + d := opDropdown{Label: cur.Label, Aria: fmt.Sprintf("Filter by kind: %s", cur.Label)} |
| + for _, k := range feedKinds { |
| + d.Items = append(d.Items, opTab{Label: k.Label, Href: feedQuery{Kind: k.Key, Account: q.Account}.href(), Current: k.Key == cur.Key}) |
| + } |
| + return d |
| +} |
| + |
| +// handleActivity serves Activity, for signed-in operators only, behind |
| +// operatorOnly's 404-to-everyone gate. It reads one row past the page to |
| +// know whether Older exists. The account filter is resolved whatever the |
| +// account's deleted_at (OperatorAccountBySqid), so a deleted account's |
| +// history stays reachable from its links; a sqid with no row shows nothing. |
| +// A failed read is a 500, since an empty feed would say nothing happened. |
| +func (s *Server) handleActivity(w http.ResponseWriter, r *http.Request) { |
| + addr, raw, ok := s.operatorOnly(w, r) |
| + if !ok { |
| + return |
| + } |
| + q := parseFeedQuery(r.URL.Query()) |
| + p := s.opPage(addr, raw, "activity") |
| + v := &feedView{Query: q, Kind: feedDropdown(q)} |
| + |
| + f := feedKindOf(q.Kind).filter() |
| + if q.Account != "" { |
| + a, err := s.store.OperatorAccountBySqid(q.Account) |
| + if err != nil { |
| + log.Printf("console: activity account %q: %v", q.Account, err) |
| + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) |
| + return |
| + } |
| + if a == nil { |
| + f.AccountID, v.AccountName = -1, q.Account |
| + } else { |
| + f.AccountID, v.AccountName, v.AccountDeleted = a.ID, a.Name, a.Deleted |
| + } |
| + } |
| + |
| + rows, err := s.store.ActivityFeed(f, q.Before, feedPageSize+1) |
| + if err != nil { |
| + log.Printf("console: activity feed (%s): %v", q.Kind, err) |
| + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) |
| + return |
| + } |
| + older := len(rows) > feedPageSize |
| + if older { |
| + rows = rows[:feedPageSize] |
| + } |
| + v.Rows = rows |
| + if q.Before > 0 { |
| + v.Pager.Items = append(v.Pager.Items, opPageItem{Label: "Newest", Href: feedQuery{Kind: q.Kind, Account: q.Account}.href()}) |
| + } |
| + if older { |
| + next := feedQuery{Kind: q.Kind, Account: q.Account, Before: rows[len(rows)-1].ID} |
| + v.Pager.Items = append(v.Pager.Items, opPageItem{Label: "Older", Href: next.href()}) |
| + } |
| + p.Feed = v |
| + s.render(w, http.StatusOK, "ops_activity", p) |
| +} |
diff --git a/internal/console/opactivity_test.go b/internal/console/opactivity_test.go| new file mode 100644 |
| index 000000000..396d5e3e9 |
| --- /dev/null |
| +++ b/internal/console/opactivity_test.go |
| @@ -0,0 +1,365 @@ |
| +package console |
| + |
| +import ( |
| + "fmt" |
| + "html" |
| + "net/http" |
| + "net/url" |
| + "regexp" |
| + "strconv" |
| + "strings" |
| + "testing" |
| + "time" |
| +) |
| + |
| +// Activity at /fleet/activity (opactivity.go, templates/ops_activity.html). |
| + |
| +// feedRow is one rendered row's cells: who, the account cell's markup, |
| +// what and the app cell's markup. |
| +type feedRow struct{ Who, Account, What, App string } |
| + |
| +var feedRowCells = regexp.MustCompile(`^><span class="rst-cell-mut" title="[^"]*">[^<]*</span>` + |
| + `<span>([^<]*)</span>(<a href="[^"]*">[^<]*</a>|<span class="rst-cell-mut">none</span>)` + |
| + `<span>([^<]*)</span>(<span>[^<]*</span>|<span class="rst-cell-mut">none</span>)</div>`) |
| + |
| +// feedRows is the page's rows, newest first, each parsed to its cells. |
| +func feedRows(t *testing.T, body string) []feedRow { |
| + t.Helper() |
| + head, rows := peopleRows(t, body) |
| + if len(rows) > 0 && !strings.Contains(head, "<span>When</span><span>Who</span><span>Account</span><span>What</span><span>App</span>") { |
| + t.Errorf("feed head: %s", head) |
| + } |
| + var out []feedRow |
| + for _, r := range rows { |
| + m := feedRowCells.FindStringSubmatch(r) |
| + if m == nil { |
| + t.Fatalf("a feed row is not When, Who, Account, What, App: %s", r) |
| + } |
| + out = append(out, feedRow{Who: html.UnescapeString(m[1]), Account: m[2], What: html.UnescapeString(m[3]), App: m[4]}) |
| + } |
| + return out |
| +} |
| + |
| +// feedWhats is each row's What. |
| +func feedWhats(rows []feedRow) []string { |
| + var out []string |
| + for _, r := range rows { |
| + out = append(out, r.What) |
| + } |
| + return out |
| +} |
| + |
| +// feedAudit is the audit rows matching where (a SQL condition on audit, "" |
| +// for all), newest first: each id and detail. |
| +func feedAudit(t *testing.T, fx *consoleFixture, where string, args ...any) (ids []int64, details []string) { |
| + t.Helper() |
| + q := `SELECT id, detail FROM audit` |
| + if where != "" { |
| + q += ` WHERE ` + where |
| + } |
| + rows, err := fx.st.db.Query(q+` ORDER BY id DESC`, args...) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + defer rows.Close() |
| + for rows.Next() { |
| + var id int64 |
| + var d string |
| + if err := rows.Scan(&id, &d); err != nil { |
| + t.Fatal(err) |
| + } |
| + ids, details = append(ids, id), append(details, d) |
| + } |
| + if err := rows.Err(); err != nil { |
| + t.Fatal(err) |
| + } |
| + return ids, details |
| +} |
| + |
| +// feedPagerLink is the pager's link labelled label, or "" when there is none. |
| +func feedPagerLink(body, label string) string { |
| + _, nav, ok := strings.Cut(body, "<nav rst-pagination") |
| + if !ok { |
| + return "" |
| + } |
| + nav, _, _ = strings.Cut(nav, "</nav>") |
| + m := regexp.MustCompile(`<a href="([^"]*)">` + label + `</a>`).FindStringSubmatch(nav) |
| + if m == nil { |
| + return "" |
| + } |
| + return html.UnescapeString(m[1]) |
| +} |
| + |
| +// feedFilterLine is the toolbar's filter line, or "". |
| +func feedFilterLine(body string) string { |
| + _, rest, ok := strings.Cut(body, "<p co-filter>") |
| + if !ok { |
| + return "" |
| + } |
| + line, _, _ := strings.Cut(rest, "</p>") |
| + return line |
| +} |
| + |
| +// feedSeedMore records n more rows on shop's app, each with its own detail, |
| +// a second apart after the world's. |
| +func feedSeedMore(t *testing.T, fx *consoleFixture, w operatorWorld, n int) { |
| + t.Helper() |
| + for i := 0; i < n; i++ { |
| + if err := fx.st.RecordActivity(w.shop.ID, "shop", "ann@example.com", |
| + Activity{Action: "env-set", Detail: fmt.Sprintf("Set variable %03d", i)}, w.now.Add(time.Duration(i)*time.Second)); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| +} |
| + |
| +func TestActivityPageNewestFirstAndPaged(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + w := seedOperatorWorld(t, fx) |
| + feedSeedMore(t, fx, w, 120) |
| + ids, details := feedAudit(t, fx, "") |
| + if len(ids) < 2*feedPageSize+2 { |
| + t.Fatalf("%d audit rows, want more than two pages", len(ids)) |
| + } |
| + |
| + body := peopleGet(t, fx, w.c, "/fleet/activity") |
| + for _, want := range []string{ |
| + "<h1>Activity</h1>", |
| + "<p rst-page-header-sub>All activity across every account, newest first.</p>", |
| + `<summary rst-btn aria-label="Filter by kind: Everything">Everything `, |
| + } { |
| + if !strings.Contains(body, want) { |
| + t.Errorf("/fleet/activity has no %s", want) |
| + } |
| + } |
| + rows := feedRows(t, body) |
| + if got, want := strings.Join(feedWhats(rows), "|"), strings.Join(details[:feedPageSize], "|"); got != want { |
| + t.Errorf("page 1 is not the newest 50 rows, newest first:\n got %s\nwant %s", got, want) |
| + } |
| + if got := feedPagerLink(body, "Newest"); got != "" { |
| + t.Errorf("the first page links Newest (%s)", got) |
| + } |
| + older := feedPagerLink(body, "Older") |
| + if want := "/fleet/activity?before=" + strconv.FormatInt(ids[feedPageSize-1], 10); older != want { |
| + t.Fatalf("page 1's Older = %q, want %q", older, want) |
| + } |
| + |
| + body = peopleGet(t, fx, w.c, older) |
| + rows = feedRows(t, body) |
| + if got, want := strings.Join(feedWhats(rows), "|"), strings.Join(details[feedPageSize:2*feedPageSize], "|"); got != want { |
| + t.Errorf("page 2 does not continue page 1:\n got %s\nwant %s", got, want) |
| + } |
| + if got := feedPagerLink(body, "Newest"); got != "/fleet/activity" { |
| + t.Errorf("page 2's Newest = %q, want /fleet/activity", got) |
| + } |
| + |
| + last := feedPagerLink(body, "Older") |
| + body = peopleGet(t, fx, w.c, last) |
| + rows = feedRows(t, body) |
| + if got, want := strings.Join(feedWhats(rows), "|"), strings.Join(details[2*feedPageSize:], "|"); got != want { |
| + t.Errorf("page 3 is not the rest:\n got %s\nwant %s", got, want) |
| + } |
| + if got := feedPagerLink(body, "Older"); got != "" { |
| + t.Errorf("the last page links Older (%s)", got) |
| + } |
| + body = peopleGet(t, fx, w.c, feedPagerLink(body, "Newest")) |
| + if got, want := strings.Join(feedWhats(feedRows(t, body)), "|"), strings.Join(details[:feedPageSize], "|"); got != want { |
| + t.Errorf("Newest does not return to the first page") |
| + } |
| +} |
| + |
| +func TestActivityPageFiltersByKindAndAccount(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + w := seedOperatorWorld(t, fx) |
| + feedSeedMore(t, fx, w, 2) |
| + named := strings.Join(feedNamedActions(), "','") |
| + |
| + for _, tc := range []struct { |
| + kind, label, where string |
| + must []string |
| + }{ |
| + {"deploys", "Deploys", `action IN ('promote', 'rollback')`, []string{"Made v2 live", "Made v1 live"}}, |
| + {"signins", "Sign-ins", `action IN ('signin', 'first-signin')`, []string{"Signed in"}}, |
| + {"accounts", "Accounts and invites", `action IN ('invite-sent', 'invite-accepted', 'account-created', 'account-deleted')`, |
| + []string{"Invited dan@example.com"}}, |
| + {"other", "Other changes", `action NOT IN ('` + named + `')`, []string{"Set variable 000", "Set variable 001"}}, |
| + } { |
| + body := peopleGet(t, fx, w.c, "/fleet/activity?kind="+tc.kind) |
| + _, want := feedAudit(t, fx, tc.where) |
| + got := feedWhats(feedRows(t, body)) |
| + if strings.Join(got, "|") != strings.Join(want, "|") { |
| + t.Errorf("kind=%s shows %q, want %q", tc.kind, got, want) |
| + } |
| + for _, m := range tc.must { |
| + if !strings.Contains("|"+strings.Join(got, "|")+"|", "|"+m+"|") { |
| + t.Errorf("kind=%s has no %q row", tc.kind, m) |
| + } |
| + } |
| + if !strings.Contains(body, `<summary rst-btn aria-label="Filter by kind: `+tc.label+`">`+tc.label+" ") { |
| + t.Errorf("kind=%s's dropdown is not labelled %s", tc.kind, tc.label) |
| + } |
| + if !strings.Contains(body, `<a href="/fleet/activity?kind=`+tc.kind+`" aria-current="true">`+tc.label) { |
| + t.Errorf("kind=%s's dropdown does not mark it current", tc.kind) |
| + } |
| + } |
| + if _, rows := feedAudit(t, fx, `action IN ('`+named+`')`); len(rows) == 0 { |
| + t.Fatal("the world has no row of a named kind") |
| + } |
| + |
| + sqid := w.shop.Sqid |
| + body := peopleGet(t, fx, w.c, "/fleet/activity?account="+sqid) |
| + _, want := feedAudit(t, fx, `account_id = ?`, w.shop.ID) |
| + rows := feedRows(t, body) |
| + if got := feedWhats(rows); strings.Join(got, "|") != strings.Join(want, "|") || len(got) == 0 { |
| + t.Errorf("account=shop shows %q, want %q", got, want) |
| + } |
| + for _, r := range rows { |
| + if r.Account != `<a href="/fleet/activity?account=`+sqid+`">shop</a>` { |
| + t.Errorf("account=shop shows a row of %s", r.Account) |
| + } |
| + } |
| + if line := feedFilterLine(body); line != `Showing only shop. <a href="/fleet/activity">Show all accounts</a>` { |
| + t.Errorf("account=shop's filter line = %q", line) |
| + } |
| + // The kind and the account combine; each link keeps the other. |
| + body = peopleGet(t, fx, w.c, "/fleet/activity?kind=deploys&account="+sqid) |
| + if got := feedWhats(feedRows(t, body)); strings.Join(got, "|") != "Made v2 live" { |
| + t.Errorf("deploys of shop = %q, want shop's promote alone", got) |
| + } |
| + for _, want := range []string{ |
| + `<a href="/fleet/activity?kind=deploys">Show all accounts</a>`, |
| + `<a href="/fleet/activity?account=` + sqid + `">Everything</a>`, |
| + `<a href="/fleet/activity?account=` + sqid + `&kind=signins">Sign-ins</a>`, |
| + } { |
| + if !strings.Contains(body, want) { |
| + t.Errorf("deploys of shop has no %s", want) |
| + } |
| + } |
| + if line := feedFilterLine(peopleGet(t, fx, w.c, "/fleet/activity")); line != "" { |
| + t.Errorf("the unfiltered feed has a filter line: %q", line) |
| + } |
| +} |
| + |
| +func TestActivityPageClampsItsParameters(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + w := seedOperatorWorld(t, fx) |
| + feedSeedMore(t, fx, w, 60) |
| + |
| + first := peopleGet(t, fx, w.c, "/fleet/activity") |
| + firstRows := strings.Join(feedWhats(feedRows(t, first)), "|") |
| + for _, p := range []string{"before=-1", "before=abc", "before=0", "before=", "kind=nope", "kind=", "kind=ALL", "before=1.5"} { |
| + body := peopleGet(t, fx, w.c, "/fleet/activity?"+p) |
| + if got := strings.Join(feedWhats(feedRows(t, body)), "|"); got != firstRows { |
| + t.Errorf("%s is not the first page of everything", p) |
| + } |
| + if feedPagerLink(body, "Newest") != "" { |
| + t.Errorf("%s links Newest", p) |
| + } |
| + if !strings.Contains(body, `aria-label="Filter by kind: Everything"`) { |
| + t.Errorf("%s is not the Everything kind", p) |
| + } |
| + } |
| + for _, p := range []string{"account=zzzz", "account=zzzz&kind=deploys", "before=99999999999999999999"} { |
| + status, _, body := get(t, w.c, fx.ts.URL+"/fleet/activity?"+p) |
| + if p == "before=99999999999999999999" { |
| + // Past int64: not a positive integer, so the first page. |
| + if got := strings.Join(feedWhats(feedRows(t, body)), "|"); status != http.StatusOK || got != firstRows { |
| + t.Errorf("%s = %d, not the first page", p, status) |
| + } |
| + continue |
| + } |
| + if status != http.StatusOK || !strings.Contains(body, "<p rst-empty-body>No activity matches these filters.</p>") { |
| + t.Errorf("%s = %d without the empty state", p, status) |
| + } |
| + if rows := feedRows(t, body); len(rows) != 0 { |
| + t.Errorf("%s lists %d rows", p, len(rows)) |
| + } |
| + if line := feedFilterLine(body); !strings.HasPrefix(line, "Showing only zzzz. ") { |
| + t.Errorf("%s's filter line = %q", p, line) |
| + } |
| + } |
| +} |
| + |
| +func TestActivityFollowsADeletedAccountsLink(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + w := seedOperatorWorld(t, fx) |
| + notes := w.notes |
| + // Paul owns notes, which holds no app, so its settings door deletes it. |
| + if err := fx.st.AddMember(notes.ID, "paul@keymail.dev", RoleOwner, w.now); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := fx.st.TrashAppRow(notes.ID, "notes", w.now); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := fx.st.PurgeAppRow(notes.ID, "notes"); err != nil { |
| + t.Fatal(err) |
| + } |
| + if n, err := fx.st.AppCount(notes.ID); err != nil || n != 0 { |
| + t.Fatalf("notes holds %d apps (%v), want none", n, err) |
| + } |
| + if status, _, body := postGated(t, fx, w.c, fx.ts.URL+"/a/"+notes.Sqid+"/delete", |
| + url.Values{"csrf": {sessionToken(t, fx, w.c)}, "confirm": {"notes"}}); status != http.StatusSeeOther { |
| + t.Fatalf("delete notes = %d:\n%s", status, body) |
| + } |
| + if a, err := fx.st.AccountBySqid(notes.Sqid); err != nil || a != nil { |
| + t.Fatalf("a member-facing lookup of the deleted notes = %+v, %v; want nil", a, err) |
| + } |
| + |
| + link := `<a href="/fleet/activity?account=` + notes.Sqid + `">notes</a>` |
| + var deleted *feedRow |
| + rows := feedRows(t, peopleGet(t, fx, w.c, "/fleet/activity")) |
| + for i, r := range rows { |
| + if r.What == "Deleted the account notes" { |
| + deleted = &rows[i] |
| + } |
| + } |
| + if deleted == nil || deleted.Account != link { |
| + t.Fatalf("the account-deleted row = %+v, want it linking %s", deleted, link) |
| + } |
| + |
| + body := peopleGet(t, fx, w.c, "/fleet/activity?account="+notes.Sqid) |
| + _, want := feedAudit(t, fx, `account_id = ?`, notes.ID) |
| + got := feedWhats(feedRows(t, body)) |
| + if strings.Join(got, "|") != strings.Join(want, "|") || len(got) < 2 || got[0] != "Deleted the account notes" { |
| + t.Errorf("notes's feed = %q, want %q, the deletion first", got, want) |
| + } |
| + if line := feedFilterLine(body); line != `Showing only notes (deleted). <a href="/fleet/activity">Show all accounts</a>` { |
| + t.Errorf("notes's filter line = %q", line) |
| + } |
| +} |
| + |
| +func TestActivityShowsAccountLevelRows(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + w := seedOperatorWorld(t, fx) |
| + none := `<span class="rst-cell-mut">none</span>` |
| + for _, r := range feedRows(t, peopleGet(t, fx, w.c, "/fleet/activity")) { |
| + if r.Who == "cat@example.com" && r.What == "Signed in" { |
| + if r.Account != none || r.App != none { |
| + t.Errorf("the sign-in row's account and app = %s, %s; want none", r.Account, r.App) |
| + } |
| + return |
| + } |
| + } |
| + t.Error("no row for cat's sign-in") |
| +} |
| + |
| +// TestParseFeedQuery: not acceptance, a unit test of the parameter rules. |
| +func TestParseFeedQuery(t *testing.T) { |
| + for _, tc := range []struct { |
| + raw string |
| + want feedQuery |
| + }{ |
| + {"", feedQuery{Kind: "all"}}, |
| + {"kind=other&account=abc&before=42", feedQuery{Kind: "other", Account: "abc", Before: 42}}, |
| + {"kind=Deploys&before=-1", feedQuery{Kind: "all"}}, |
| + {"before=0x10&kind=signins", feedQuery{Kind: "signins"}}, |
| + {"before=9223372036854775808", feedQuery{Kind: "all"}}, |
| + } { |
| + v, err := url.ParseQuery(tc.raw) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if got := parseFeedQuery(v); got != tc.want { |
| + t.Errorf("parseFeedQuery(%q) = %+v, want %+v", tc.raw, got, tc.want) |
| + } |
| + } |
| +} |
diff --git a/internal/console/opdashboard_test.go b/internal/console/opdashboard_test.go| index 5d3b7b5fa..f32d41fe5 100644 |
| --- a/internal/console/opdashboard_test.go |
| +++ b/internal/console/opdashboard_test.go |
| @@ -802,11 +802,20 @@ func TestDashboardRemoteReadsAreTheDeclaredOnes(t *testing.T) { |
| } |
| } |
| +// opScaleAuditBase is the id of seedOperatorScale's first audit row; the |
| +// rest follow it, one apart, so a walk target can name an id deep in the |
| +// feed without a fixture to ask. |
| +const opScaleAuditBase = 1_000_000 |
| + |
| +// opScaleAccount is the sqid of seedOperatorScale's account i. |
| +func opScaleAccount(i int) string { return fmt.Sprintf("opscale%02d", i) } |
| + |
| // seedOperatorScale fills the operator tables for the walk (perfSeed), so |
| // every operator screen is measured over populated tables: 300 people |
| // joined across 60 days (half seen, a third with a session), 60 accounts |
| // with 2 to 6 members, 1 to 8 apps and a plan row each, and 3,000 audit |
| -// rows over the accounts' actions and deploys. One transaction, straight |
| +// rows over the accounts' actions and deploys (ids from opScaleAuditBase). |
| +// One transaction, straight |
| // into SQLite, so the walk's setup stays quick; nothing here is remote. |
| func seedOperatorScale(t *testing.T, fx *consoleFixture) { |
| t.Helper() |
| @@ -855,7 +864,7 @@ func seedOperatorScale(t *testing.T, fx *consoleFixture) { |
| id := func(i int) int64 { return int64(9000 + i) } |
| for i := 0; i < accounts; i++ { |
| created := n - int64(i)*day |
| - exec(accts, id(i), fmt.Sprintf("opscale%02d", i), fmt.Sprintf("shop-%d", i), created) |
| + exec(accts, id(i), opScaleAccount(i), fmt.Sprintf("shop-%d", i), created) |
| for j := 0; j < 2+i%5; j++ { |
| role := RoleMember |
| if j == 0 { |
| @@ -871,7 +880,7 @@ func seedOperatorScale(t *testing.T, fx *consoleFixture) { |
| } |
| exec(plans, id(i), "free", "operator", 1, "paul@keymail.dev", created) |
| } |
| - audit := prep(`INSERT INTO audit (account_id, app, address, action, detail, created_at) VALUES (?, ?, ?, ?, ?, ?)`) |
| + audit := prep(`INSERT INTO audit (id, account_id, app, address, action, detail, created_at) VALUES (?, ?, ?, ?, ?, ?, ?)`) |
| kinds := []string{"first-signin", "signin", "invite-sent", "invite-accepted", "account-created", "account-deleted", "promote", "rollback"} |
| for i := 0; i < audits; i++ { |
| action, acct, app := kinds[i%len(kinds)], id(i%accounts), "" |
| @@ -881,7 +890,7 @@ func seedOperatorScale(t *testing.T, fx *consoleFixture) { |
| case "signin", "first-signin": |
| acct = 0 |
| } |
| - exec(audit, acct, app, person(i), action, "detail", n-int64(audits-i)*60) |
| + exec(audit, opScaleAuditBase+int64(i), acct, app, person(i), action, "detail", n-int64(audits-i)*60) |
| } |
| if err := tx.Commit(); err != nil { |
| t.Fatal(err) |
diff --git a/internal/console/oppeople_test.go b/internal/console/oppeople_test.go| index fb0621781..544b7090d 100644 |
| --- a/internal/console/oppeople_test.go |
| +++ b/internal/console/oppeople_test.go |
| @@ -140,9 +140,9 @@ func TestPeoplePageListsPeopleAndAccounts(t *testing.T) { |
| for _, want := range []string{ |
| `<a class="rst-nm" href="/fleet/activity?account=` + a.acct.Sqid + `">` + a.acct.Name + `</a>`, |
| peopleTitle(a.acct.CreatedAt), |
| - planCell, |
| - "<span>1</span>", // one app each |
| - fmt.Sprintf("<span>%d</span></div>", a.members), |
| + // Plan, Apps (one each) and Members, in order: notes has one |
| + // member too, so a loose "<span>1</span>" would pass on either. |
| + planCell + "<span>1</span>" + fmt.Sprintf("<span>%d</span></div>", a.members), |
| } { |
| if !strings.Contains(r, want) { |
| t.Errorf("%s's row has no %s: %s", a.acct.Name, want, r) |
| @@ -304,7 +304,8 @@ func TestParsePeopleQuery(t *testing.T) { |
| // TestPerfTargetsCoverOperatorViews: not acceptance. Route enumeration sees |
| // patterns, never the views a query selects, so every view value the |
| // operator pages define must have an explicit walk target: each of |
| -// peopleShows on GET /fleet/people. Task 11 adds feedKinds. |
| +// peopleShows on GET /fleet/people, and each of feedKinds, an account |
| +// filter and a deep page on GET /fleet/activity. |
| func TestPerfTargetsCoverOperatorViews(t *testing.T) { |
| targets := perfOperatorTargets() |
| shows := map[string]bool{} |
| @@ -323,4 +324,30 @@ func TestPerfTargetsCoverOperatorViews(t *testing.T) { |
| t.Errorf("no walk target shows %q", s) |
| } |
| } |
| + |
| + kinds := map[string]bool{} |
| + var account, before bool |
| + for _, tg := range targets["GET /fleet/activity"] { |
| + u, err := url.Parse(tg.Path) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if u.Path != "/fleet/activity" || tg.Expect != http.StatusOK { |
| + t.Errorf("target %+v is not a 200 on /fleet/activity", tg) |
| + } |
| + if u.Query().Has("kind") || len(u.Query()) == 0 { |
| + kinds[parseFeedQuery(u.Query()).Kind] = true |
| + } |
| + q := parseFeedQuery(u.Query()) |
| + account = account || q.Account != "" |
| + before = before || q.Before > 0 |
| + } |
| + for _, k := range feedKinds { |
| + if !kinds[k.Key] { |
| + t.Errorf("no walk target shows the %q kind", k.Key) |
| + } |
| + } |
| + if !account || !before { |
| + t.Errorf("the activity targets lack an account filter (%v) or a deep page (%v)", account, before) |
| + } |
| } |
diff --git a/internal/console/opshots_test.go b/internal/console/opshots_test.go| index 978969134..14cabb26c 100644 |
| --- a/internal/console/opshots_test.go |
| +++ b/internal/console/opshots_test.go |
| @@ -26,6 +26,7 @@ var opShotPages = []struct{ name, path string }{ |
| {"store", "/fleet/store"}, |
| {"people", "/fleet/people"}, |
| {"accounts", "/fleet/people?show=accounts"}, |
| + {"activity", "/fleet/activity"}, |
| } |
| // TestOperatorScreenshots is a review aid, not acceptance: it renders every |
diff --git a/internal/console/perfwalk_test.go b/internal/console/perfwalk_test.go| index 0f15327e7..52b5648af 100644 |
| --- a/internal/console/perfwalk_test.go |
| +++ b/internal/console/perfwalk_test.go |
| @@ -498,7 +498,8 @@ func perfTargets(fx *consoleFixture) map[string][]perfTarget { |
| // perfOperatorTargets is the operator pages' views that a query selects, |
| // which route enumeration cannot see (it registers patterns), each over |
| // seedOperatorScale's rows: TestPerfTargetsCoverOperatorViews holds every |
| -// value of show to a target. |
| +// value of show and every feed kind to a target. Activity's other kind is |
| +// there too: its NOT IN is the likeliest slow query. |
| func perfOperatorTargets() map[string][]perfTarget { |
| ok := func(paths ...string) []perfTarget { |
| var out []perfTarget |
| @@ -507,9 +508,17 @@ func perfOperatorTargets() map[string][]perfTarget { |
| } |
| return out |
| } |
| + activity := ok("/fleet/activity") |
| + for _, k := range feedKinds[1:] { |
| + activity = append(activity, ok("/fleet/activity?kind="+k.Key)...) |
| + } |
| + // One of the scale accounts, and a page 2,000 rows back from its newest. |
| + activity = append(activity, ok("/fleet/activity?account="+opScaleAccount(3), |
| + "/fleet/activity?before="+strconv.Itoa(opScaleAuditBase+1000))...) |
| return map[string][]perfTarget{ |
| "GET /fleet/people": ok("/fleet/people", "/fleet/people?show=accounts", "/fleet/people?q=person-1", |
| "/fleet/people?show=accounts&q=shop-1", "/fleet/people?page=3"), |
| + "GET /fleet/activity": activity, |
| } |
| } |
diff --git a/internal/console/server.go b/internal/console/server.go| index 6a59858b8..8a8868c14 100644 |
| --- a/internal/console/server.go |
| +++ b/internal/console/server.go |
| @@ -1663,6 +1663,7 @@ func NewServer(cfg Config, st *Store) (*Server, error) { |
| s.registerRoute("GET /auth/confirm", s.handleConfirm) |
| s.registerRoute("POST /auth/signout", s.handleSignout) |
| s.registerRoute("GET /fleet", s.handleDashboard) |
| + s.registerRoute("GET /fleet/activity", s.handleActivity) |
| s.registerRoute("GET /fleet/boxes", s.handleBoxes) |
| s.registerRoute("GET /fleet/index", s.handleOpIndex) |
| s.registerRoute("GET /fleet/people", s.handlePeople) |
| @@ -2253,6 +2254,9 @@ type page struct { |
| // People is People and accounts' data (/fleet/people, oppeople.go). |
| People *peopleView |
| + // Feed is Activity's data (/fleet/activity, opactivity.go). |
| + Feed *feedView |
| + |
| // /fleet, below the published boxes table: the per-host PRIVATE detail |
| // read straight out of status/boxes/ (HostRows, view.go). Raw numbers |
| // render here and nowhere public — this page is session-gated to |
diff --git a/internal/console/static/ops.css b/internal/console/static/ops.css| index 299c37eba..10de9ccc5 100644 |
| --- a/internal/console/static/ops.css |
| +++ b/internal/console/static/ops.css |
| @@ -28,18 +28,23 @@ |
| [co-cols="jobs"] { --rst-cols: minmax(10rem, 1.5fr) 9rem 8rem minmax(10rem, 2fr); } |
| [co-cols="persons"] { --rst-cols: minmax(12rem, 2fr) 7rem 7rem 6rem; } |
| [co-cols="accounts"] { --rst-cols: minmax(10rem, 2fr) 7rem minmax(6rem, 1fr) 5rem 6rem; } |
| +[co-cols="feed"] { --rst-cols: 6rem minmax(10rem, 1.2fr) minmax(7rem, 1fr) minmax(12rem, 2fr) minmax(7rem, 1fr); } |
| /* On a phone, Rastrillo's rows drop to a name and one value (its |
| rst-m-hide hides the rest, at the same 800px). These lists have no |
| kebab, so each keeps two cells on two columns and hides the others, |
| - head row included: one row per line, never a cell wrapped below. */ |
| + head row included: one row per line, never a cell wrapped below. The |
| + activity lists lead with When at the desktop's fixed width, so "0m ago" |
| + and "21h47m ago" rows keep What in one column. */ |
| @media (max-width: 800px) { |
| [co-cols] > [rst-lrow] { grid-template-columns: minmax(0, 1fr) auto; } |
| - [co-cols="activity"] > [rst-lrow] { grid-template-columns: auto minmax(0, 1fr); } |
| + [co-cols="activity"] > [rst-lrow], |
| + [co-cols="feed"] > [rst-lrow] { grid-template-columns: 6rem minmax(0, 1fr); } |
| [co-cols="people"] > [rst-lrow] > :is(:nth-child(2), :nth-child(4)), |
| [co-cols="persons"] > [rst-lrow] > :is(:nth-child(2), :nth-child(4)), |
| [co-cols="accounts"] > [rst-lrow] > :is(:nth-child(2), :nth-child(n+4)), |
| [co-cols="activity"] > [rst-lrow] > :is(:nth-child(2), :nth-child(4)), |
| + [co-cols="feed"] > [rst-lrow] > :is(:nth-child(2), :nth-child(3), :nth-child(5)), |
| [co-cols="boxes"] > [rst-lrow] > :nth-child(n+3), |
| [co-cols="jobs"] > [rst-lrow] > :nth-child(n+3) { display: none; } |
| } |
| @@ -48,6 +53,14 @@ |
| own, so the switch keeps the gap a section head would. */ |
| [co-tabs] { margin-block-start: 1.5rem; } |
| +/* Activity's filter line in its toolbar: which account the feed is |
| + narrowed to, and the link that drops it. */ |
| +[co-filter] { color: var(--rst-text-muted); font-size: var(--rst-fs-sm); margin: 0; } |
| + |
| +/* Activity's account links (each row's account, the filter line's clear |
| + link): the accent, not the browser's default blue. */ |
| +[co-cols="feed"] a { color: var(--rst-accent); } |
| + |
| /* A quiet note under a table or a band: what today's pages wrote as a |
| <p class="small">. */ |
| [co-note] { color: var(--rst-text-faint); font-size: var(--rst-fs-sm); margin: var(--rst-sp-2) 0 0; } |
diff --git a/internal/console/templates/ops_activity.html b/internal/console/templates/ops_activity.html| new file mode 100644 |
| index 000000000..aa9f50729 |
| --- /dev/null |
| +++ b/internal/console/templates/ops_activity.html |
| @@ -0,0 +1,26 @@ |
| +{{/* Activity (/fleet/activity, opactivity.go): one card of audit rows, |
| + newest first, under a toolbar holding the kind filter and, when an |
| + account filter is on, the line naming it with its clear link; Newest |
| + and Older below. Everything computed in Go arrives in .Feed. */}} |
| +{{define "ops_activity"}}{{template "op_top" .}} |
| +{{template "op_page_header" (opHeader .Title "All activity across every account, newest first.")}} |
| +{{with .Feed}} |
| +<div rst-card co-cols="feed"> |
| + <div rst-lbar> |
| + {{template "op_dropdown" .Kind}} |
| + {{- if .AccountName}} |
| + <p co-filter>Showing only {{if .AccountDeleted}}{{.AccountName}} (deleted){{else}}{{.AccountName}}{{end}}. <a href="{{.Query.ClearAccountHref}}">Show all accounts</a></p> |
| + {{- end}} |
| + </div> |
| + {{- if .Rows}} |
| + <div rst-lrow="head"><span>When</span><span>Who</span><span>Account</span><span>What</span><span>App</span></div> |
| + {{- range .Rows}} |
| + <div rst-lrow><span class="rst-cell-mut" title="{{fmtTime .At}}">{{ago .At}}</span><span>{{.Address}}</span>{{if .AccountSqid}}<a href="{{$.Feed.Query.AccountHref .AccountSqid}}">{{.AccountName}}</a>{{else}}<span class="rst-cell-mut">none</span>{{end}}<span>{{.Detail}}</span>{{if .App}}<span>{{.App}}</span>{{else}}<span class="rst-cell-mut">none</span>{{end}}</div> |
| + {{- end}} |
| + {{- else}} |
| + {{template "op_empty" (opEmpty "" "No activity matches these filters.")}} |
| + {{- end}} |
| +</div> |
| +{{with .Pager.Items}}{{template "op_pagination" $.Feed.Pager}}{{end}} |
| +{{end}} |
| +{{template "op_bottom" .}}{{end}} |
diff --git a/internal/console/testdata/claim-routes.txt b/internal/console/testdata/claim-routes.txt| index d324c0bb8..a7affe253 100644 |
| --- a/internal/console/testdata/claim-routes.txt |
| +++ b/internal/console/testdata/claim-routes.txt |
| @@ -112,6 +112,7 @@ route GET /auth/email/link |
| route GET /auth/signin |
| route GET /auth/stepup/callback |
| route GET /fleet |
| +route GET /fleet/activity |
| route GET /fleet/boxes |
| route GET /fleet/economics |
| route GET /fleet/economics/accounts |