console: People and accounts for operators
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
12 files changed,
+579
−0
approved_operator_pages_copy_test.go+5 −0internal/console/claim_invariant_fixtures_test.go+1 −0internal/console/claim_invariant_probes_read_test.go+1 −0internal/console/opdashboard_test.go+8 −0internal/console/oppeople.go+158 −0internal/console/oppeople_test.go+326 −0internal/console/opshots_test.go+2 −0internal/console/perfwalk_test.go+21 −0internal/console/server.go+4 −0internal/console/static/ops.css+8 −0internal/console/templates/ops_people.html+44 −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 68cc8c201..9f842e536 100644 |
| --- a/approved_operator_pages_copy_test.go |
| +++ b/approved_operator_pages_copy_test.go |
| @@ -70,6 +70,11 @@ var operatorPagesCopyBuilt = []string{ |
| "OPS-73", "OPS-74", "OPS-75", "OPS-76", |
| // Task 9 review fix: the box reports could not be read. |
| "OPS-154", |
| + // Task 10: People and accounts. The tabs, the search placeholders and |
| + // the band's labels are built in oppeople.go (peopleView's data). |
| + "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", |
| } |
| // operatorPagesBuiltRows is entryBuiltRows for operatorPagesCopyBuilt. |
diff --git a/internal/console/claim_invariant_fixtures_test.go b/internal/console/claim_invariant_fixtures_test.go| index d0acefbff..82fe873c7 100644 |
| --- a/internal/console/claim_invariant_fixtures_test.go |
| +++ b/internal/console/claim_invariant_fixtures_test.go |
| @@ -894,6 +894,7 @@ var claimFixtures = map[string]claimFixture{ |
| "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"), |
| + "route GET /fleet/people": claimRead("operator people and accounts list; SQLite only"), |
| "route GET /fleet/store": claimRead("operator entitlement queue page"), |
| "route GET /healthz": claimRead("answers ok and the build"), |
| "route GET /invite/{token}": claimRead("shows an invitation; joining is the POST"), |
diff --git a/internal/console/claim_invariant_probes_read_test.go b/internal/console/claim_invariant_probes_read_test.go| index 877928f83..730b0e0e8 100644 |
| --- a/internal/console/claim_invariant_probes_read_test.go |
| +++ b/internal/console/claim_invariant_probes_read_test.go |
| @@ -174,6 +174,7 @@ var claimReadProbes = map[string]claimProbe{ |
| "route GET /fleet/economics/accounts": claimPageRead(nil, "/fleet/economics/accounts", "<h1>Fleet economics: accounts</h1>"), |
| "route GET /fleet/index": claimPageRead(nil, "/fleet/index", "rst-shell-console=\"index\""), |
| "route GET /fleet/metrics": claimPageRead(nil, "/fleet/metrics", "<h1>Fleet metrics</h1>"), |
| + "route GET /fleet/people": claimPageRead(nil, "/fleet/people", "<h1>People and accounts</h1>"), |
| "route GET /fleet/store": claimPageRead(claimWorldApply, "/fleet/store", "<h1>Storage requests</h1>"), |
| "route GET /healthz": claimPageRead(nil, "/healthz", "ok"), |
| "route GET /static/{hash}/{file...}": claimPageRead(nil, assetURL("rastrillo/tokens.css"), "--rst-"), |
diff --git a/internal/console/opdashboard_test.go b/internal/console/opdashboard_test.go| index 2b93bab9b..5d3b7b5fa 100644 |
| --- a/internal/console/opdashboard_test.go |
| +++ b/internal/console/opdashboard_test.go |
| @@ -103,6 +103,14 @@ func seedOperatorWorld(t *testing.T, fx *consoleFixture) operatorWorld { |
| if err != nil { |
| t.Fatal(err) |
| } |
| + // Minted on the wall clock; created on the world's, like everything |
| + // else it seeds. |
| + for _, a := range []*Account{shop, notes} { |
| + if _, err := fx.st.db.Exec(`UPDATE accounts SET created_at = ? WHERE id = ?`, now.Unix(), a.ID); err != nil { |
| + t.Fatal(err) |
| + } |
| + a.CreatedAt = time.Unix(now.Unix(), 0) |
| + } |
| if err := fx.st.AddMember(shop.ID, "cat@example.com", RoleMember, now); err != nil { |
| t.Fatal(err) |
| } |
diff --git a/internal/console/oppeople.go b/internal/console/oppeople.go| new file mode 100644 |
| index 000000000..afd94db1a |
| --- /dev/null |
| +++ b/internal/console/oppeople.go |
| @@ -0,0 +1,158 @@ |
| +package console |
| + |
| +import ( |
| + "log" |
| + "math" |
| + "net/http" |
| + "net/url" |
| + "strconv" |
| + "strings" |
| + "unicode/utf8" |
| +) |
| + |
| +// People and accounts (/fleet/people, spec 2026-10-25 Part 3): everyone who |
| +// has signed in and every live account, searchable and paged, with how many |
| +// people were active today, this week and this month. SQLite only: no |
| +// bucket read, no remote call. |
| + |
| +// peoplePageSize is the rows on one page of either list. |
| +const peoplePageSize = 50 |
| + |
| +// searchMax is the longest search the page runs, in characters; a longer |
| +// q is cut to it. |
| +const searchMax = 100 |
| + |
| +// peopleShows is every view of the page, by its show value. The first is |
| +// the default. |
| +var peopleShows = []string{"people", "accounts"} |
| + |
| +// peopleQuery is the page's parameters, parsed and clamped. |
| +type peopleQuery struct { |
| + Show, Q string |
| + Page int |
| +} |
| + |
| +// parsePeopleQuery reads show, q and page: Show is "people" unless show is |
| +// exactly "accounts"; Q is trimmed and cut at searchMax characters; Page is |
| +// a positive integer, else 1. |
| +func parsePeopleQuery(v url.Values) peopleQuery { |
| + q := peopleQuery{Show: peopleShows[0], Page: 1} |
| + if v.Get("show") == "accounts" { |
| + q.Show = "accounts" |
| + } |
| + q.Q = strings.TrimSpace(v.Get("q")) |
| + if utf8.RuneCountInString(q.Q) > searchMax { |
| + q.Q = string([]rune(q.Q)[:searchMax]) |
| + } |
| + if n, err := strconv.Atoi(v.Get("page")); err == nil && n > 0 { |
| + q.Page = n |
| + } |
| + return q |
| +} |
| + |
| +// values is the query a link keeps: show when it is not the default, and q |
| +// when there is one. Never page. |
| +func (q peopleQuery) values() url.Values { |
| + v := url.Values{} |
| + if q.Show != peopleShows[0] { |
| + v.Set("show", q.Show) |
| + } |
| + if q.Q != "" { |
| + v.Set("q", q.Q) |
| + } |
| + return v |
| +} |
| + |
| +// peopleView is the page's data (page.People). |
| +type peopleView struct { |
| + Query peopleQuery |
| + Tabs opTabs |
| + Bar opListBar |
| + Pager opPager |
| + People []PersonRow |
| + Accounts []AccountRow |
| + Total int |
| + // Active is the band: today, 7 days, 30 days. A zero Label means the |
| + // counts could not be read, and the band is left out. |
| + Active [3]opStat |
| +} |
| + |
| +// peopleTabs is the view switch: People and Accounts, the current one |
| +// marked. |
| +func peopleTabs(show string) opTabs { |
| + return opTabs{Label: "Show", Items: []opTab{ |
| + {Label: "People", Href: "/fleet/people", Current: show == "people"}, |
| + {Label: "Accounts", Href: "/fleet/people?show=accounts", Current: show == "accounts"}, |
| + }} |
| +} |
| + |
| +// peopleBar is the search over the current view. It carries show across, |
| +// and its clear link drops q and page. |
| +func peopleBar(q peopleQuery) opListBar { |
| + b := opListBar{Action: "/fleet/people", Query: q.Q, Placeholder: "Search people by address", ClearHref: "/fleet/people"} |
| + if q.Show == "accounts" { |
| + b.Placeholder = "Search accounts by name or ID" |
| + b.Hidden = [][2]string{{"show", "accounts"}} |
| + b.ClearHref = "/fleet/people?show=accounts" |
| + } |
| + return b |
| +} |
| + |
| +// peopleList fills v's list for page and returns the matching total. |
| +func (s *Server) peopleList(v *peopleView, page int) (int, error) { |
| + offset := (page - 1) * peoplePageSize |
| + if v.Query.Show == "accounts" { |
| + rows, total, err := s.store.AccountsPage(v.Query.Q, offset, peoplePageSize) |
| + v.Accounts = rows |
| + return total, err |
| + } |
| + rows, total, err := s.store.PeoplePage(v.Query.Q, offset, peoplePageSize) |
| + v.People = rows |
| + return total, err |
| +} |
| + |
| +// handlePeople serves People and accounts, for signed-in operators only, |
| +// behind operatorOnly's 404-to-everyone gate. A page past the last shows |
| +// the last. A failed count leaves the band out; a failed list read is a |
| +// 500, since an empty list would say there is no one. |
| +func (s *Server) handlePeople(w http.ResponseWriter, r *http.Request) { |
| + addr, raw, ok := s.operatorOnly(w, r) |
| + if !ok { |
| + return |
| + } |
| + q := parsePeopleQuery(r.URL.Query()) |
| + p := s.opPage(addr, raw, "people") |
| + v := &peopleView{Query: q, Tabs: peopleTabs(q.Show), Bar: peopleBar(q)} |
| + |
| + if c, err := s.store.OperatorCounts(s.now()); err != nil { |
| + log.Printf("console: people counts: %v", err) |
| + } else { |
| + v.Active = [3]opStat{ |
| + {Label: "Active today", Value: opNumber(c.ActiveToday)}, |
| + {Label: "Active in the last 7 days", Value: opNumber(c.Active7)}, |
| + {Label: "Active in the last 30 days", Value: opNumber(c.Active30)}, |
| + } |
| + } |
| + |
| + // A page number so large its offset would overflow is past the last |
| + // page anyway. |
| + page := min(q.Page, math.MaxInt32) |
| + total, err := s.peopleList(v, page) |
| + pages := (total + peoplePageSize - 1) / peoplePageSize |
| + if err == nil && page > 1 && page > pages { |
| + page = max(pages, 1) |
| + total, err = s.peopleList(v, page) |
| + pages = (total + peoplePageSize - 1) / peoplePageSize |
| + } |
| + if err != nil { |
| + log.Printf("console: people list (%s): %v", q.Show, err) |
| + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) |
| + return |
| + } |
| + v.Query.Page, v.Total = page, total |
| + if pages > 1 { |
| + v.Pager = opPager{Items: opPages("/fleet/people", q.values(), page, pages)} |
| + } |
| + p.People = v |
| + s.render(w, http.StatusOK, "ops_people", p) |
| +} |
diff --git a/internal/console/oppeople_test.go b/internal/console/oppeople_test.go| new file mode 100644 |
| index 000000000..fb0621781 |
| --- /dev/null |
| +++ b/internal/console/oppeople_test.go |
| @@ -0,0 +1,326 @@ |
| +package console |
| + |
| +import ( |
| + "fmt" |
| + "net/http" |
| + "net/url" |
| + "strings" |
| + "testing" |
| + "time" |
| +) |
| + |
| +// People and accounts at /fleet/people (oppeople.go, |
| +// templates/ops_people.html). |
| + |
| +// peopleGet is path as c, which must answer 200. |
| +func peopleGet(t *testing.T, fx *consoleFixture, c *http.Client, path string) string { |
| + t.Helper() |
| + status, _, body := get(t, c, fx.ts.URL+path) |
| + if status != http.StatusOK { |
| + t.Fatalf("%s = %d:\n%s", path, status, body) |
| + } |
| + return body |
| +} |
| + |
| +// peopleRows is the page's list rows after the head row: each row's markup |
| +// from "<div rst-lrow>" to the next row. |
| +func peopleRows(t *testing.T, body string) (head string, rows []string) { |
| + t.Helper() |
| + list := dashCut(t, body, "<div rst-card co-cols=", "</main>") |
| + parts := strings.Split(list, "<div rst-lrow") |
| + if len(parts) < 2 { |
| + return "", nil |
| + } |
| + return parts[1], parts[2:] |
| +} |
| + |
| +// peopleRowFor is the one row naming who, or "". |
| +func peopleRowFor(rows []string, who string) string { |
| + for _, r := range rows { |
| + if strings.Contains(r, ">"+who+"</") { |
| + return r |
| + } |
| + } |
| + return "" |
| +} |
| + |
| +func peopleTitle(at time.Time) string { |
| + return `title="` + at.UTC().Format("2006-01-02 15:04 UTC") + `"` |
| +} |
| + |
| +func TestPeoplePageListsPeopleAndAccounts(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + w := seedOperatorWorld(t, fx) |
| + body := peopleGet(t, fx, w.c, "/fleet/people") |
| + for _, want := range []string{ |
| + "<h1>People and accounts</h1>", |
| + "<p rst-page-header-sub>Everyone who has signed in and every account.</p>", |
| + `<nav rst-seg-tabs aria-label="Show"><a href="/fleet/people" aria-current="page">People</a><a href="/fleet/people?show=accounts">Accounts</a></nav>`, |
| + `placeholder="Search people by address"`, |
| + "<span rst-stat-label>Active today</span>", |
| + "<span rst-stat-label>Active in the last 7 days</span>", |
| + "<span rst-stat-label>Active in the last 30 days</span>", |
| + } { |
| + if !strings.Contains(body, want) { |
| + t.Errorf("/fleet/people has no %s", want) |
| + } |
| + } |
| + head, rows := peopleRows(t, body) |
| + if !strings.Contains(head, "<span>Person</span><span>Joined</span><span>Last seen</span><span>Accounts</span>") { |
| + t.Errorf("people head: %s", head) |
| + } |
| + day := 24 * time.Hour |
| + for _, p := range []struct { |
| + addr string |
| + joined time.Duration |
| + seen bool |
| + accounts int |
| + }{ |
| + {"ann@example.com", 10 * time.Second, true, 1}, |
| + {"ben@example.com", 20 * time.Second, true, 1}, |
| + {"cat@example.com", 2 * day, true, 1}, |
| + {"dan@example.com", 5 * day, false, 0}, |
| + {"eve@example.com", 9 * day, false, 0}, |
| + {"fay@example.com", 21 * day, false, 0}, |
| + {"gus@example.com", 25 * day, false, 0}, |
| + {"hal@example.com", 29 * day, false, 0}, |
| + } { |
| + r := peopleRowFor(rows, p.addr) |
| + if r == "" { |
| + t.Errorf("no row for %s", p.addr) |
| + continue |
| + } |
| + wants := []string{`<span class="rst-nm">` + p.addr + `</span>`, peopleTitle(w.now.Add(-p.joined)), fmt.Sprintf("<span>%d</span>", p.accounts)} |
| + if p.seen { |
| + wants = append(wants, peopleTitle(w.now)) |
| + } else { |
| + wants = append(wants, `<span class="rst-cell-mut">not yet</span>`) |
| + } |
| + for _, want := range wants { |
| + if !strings.Contains(r, want) { |
| + t.Errorf("%s's row has no %s: %s", p.addr, want, r) |
| + } |
| + } |
| + } |
| + if len(rows) < 9 || peopleRowFor(rows, "paul@keymail.dev") == "" { |
| + t.Errorf("%d people rows, want the eight seeded and Paul", len(rows)) |
| + } |
| + |
| + body = peopleGet(t, fx, w.c, "/fleet/people?show=accounts") |
| + for _, want := range []string{ |
| + `<a href="/fleet/people">People</a><a href="/fleet/people?show=accounts" aria-current="page">Accounts</a>`, |
| + `placeholder="Search accounts by name or ID"`, |
| + `<input type="hidden" name="show" value="accounts">`, |
| + } { |
| + if !strings.Contains(body, want) { |
| + t.Errorf("the accounts view has no %s", want) |
| + } |
| + } |
| + head, rows = peopleRows(t, body) |
| + if !strings.Contains(head, "<span>Account</span><span>Created</span><span>Plan</span><span>Apps</span><span>Members</span>") { |
| + t.Errorf("accounts head: %s", head) |
| + } |
| + for _, a := range []struct { |
| + acct *Account |
| + members int |
| + }{{w.shop, 2}, {w.notes, 1}} { |
| + r := peopleRowFor(rows, a.acct.Name) |
| + if r == "" { |
| + t.Errorf("no row for %s", a.acct.Name) |
| + continue |
| + } |
| + var plan string |
| + if err := fx.st.db.QueryRow(`SELECT COALESCE((SELECT plan FROM account_plans WHERE account_id = ?), '')`, a.acct.ID).Scan(&plan); err != nil { |
| + t.Fatal(err) |
| + } |
| + planCell := `<span>` + plan + `</span>` |
| + if plan == "" { |
| + planCell = `<span class="rst-cell-mut">none</span>` |
| + } |
| + 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), |
| + } { |
| + if !strings.Contains(r, want) { |
| + t.Errorf("%s's row has no %s: %s", a.acct.Name, want, r) |
| + } |
| + } |
| + } |
| +} |
| + |
| +func TestPeoplePageSearch(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + w := seedOperatorWorld(t, fx) |
| + |
| + body := peopleGet(t, fx, w.c, "/fleet/people?q=ann") |
| + if _, rows := peopleRows(t, body); len(rows) != 1 || peopleRowFor(rows, "ann@example.com") == "" { |
| + t.Errorf("?q=ann lists %d rows, want ann@example.com alone:\n%s", len(rows), strings.Join(rows, "\n")) |
| + } |
| + if !strings.Contains(body, `value="ann"`) || !strings.Contains(body, `<a rst-search-clear href="/fleet/people"`) { |
| + t.Errorf("?q=ann does not keep its query and a clear link to /fleet/people") |
| + } |
| + |
| + body = peopleGet(t, fx, w.c, "/fleet/people?show=accounts&q=sho") |
| + if _, rows := peopleRows(t, body); len(rows) != 1 || peopleRowFor(rows, "shop") == "" { |
| + t.Errorf("?show=accounts&q=sho lists %d rows, want shop alone:\n%s", len(rows), strings.Join(rows, "\n")) |
| + } |
| + if !strings.Contains(body, `<a rst-search-clear href="/fleet/people?show=accounts"`) { |
| + t.Errorf("the accounts search's clear link does not keep show and drop q") |
| + } |
| + |
| + body = peopleGet(t, fx, w.c, "/fleet/people?q=nobody-here&page=2") |
| + if !strings.Contains(body, "<p rst-empty-body>No people match that search.</p>") { |
| + t.Errorf("an empty people search does not say so") |
| + } |
| + if _, rows := peopleRows(t, body); len(rows) != 0 { |
| + t.Errorf("an empty people search lists %d rows", len(rows)) |
| + } |
| + if !strings.Contains(body, `<a rst-search-clear href="/fleet/people"`) { |
| + t.Errorf("the clear link does not drop q and page") |
| + } |
| + body = peopleGet(t, fx, w.c, "/fleet/people?show=accounts&q=nobody-here") |
| + if !strings.Contains(body, "<p rst-empty-body>No accounts match that search.</p>") { |
| + t.Errorf("an empty accounts search does not say so") |
| + } |
| +} |
| + |
| +// peopleSeedTo adds people until there are n in all, joined a minute apart. |
| +func peopleSeedTo(t *testing.T, fx *consoleFixture, n int) { |
| + t.Helper() |
| + var have int |
| + if err := fx.st.db.QueryRow(`SELECT COUNT(*) FROM users`).Scan(&have); err != nil { |
| + t.Fatal(err) |
| + } |
| + now := time.Now() |
| + for i := have; i < n; i++ { |
| + if _, err := fx.st.EnsureUser(fmt.Sprintf("member-%03d@example.com", i), now.Add(-time.Duration(i)*time.Minute)); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| +} |
| + |
| +// peopleCurrentPage is the page number the pager marks current, or "". |
| +func peopleCurrentPage(body string) string { |
| + _, rest, ok := strings.Cut(body, "<nav rst-pagination") |
| + if !ok { |
| + return "" |
| + } |
| + _, rest, ok = strings.Cut(rest, `<span aria-current="page">`) |
| + if !ok { |
| + return "" |
| + } |
| + n, _, _ := strings.Cut(rest, "</span>") |
| + return n |
| +} |
| + |
| +func TestPeoplePagePaging(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + c := signInOperator(t, fx) |
| + peopleSeedTo(t, fx, 120) |
| + |
| + body := peopleGet(t, fx, c, "/fleet/people") |
| + if _, rows := peopleRows(t, body); len(rows) != 50 { |
| + t.Errorf("page 1 has %d rows, want 50", len(rows)) |
| + } |
| + if got := peopleCurrentPage(body); got != "1" { |
| + t.Errorf("page 1's pager marks %q current, want 1", got) |
| + } |
| + for _, want := range []string{`<a href="/fleet/people?page=2">2</a>`, `<a href="/fleet/people?page=3">3</a>`} { |
| + if !strings.Contains(body, want) { |
| + t.Errorf("page 1's pager has no %s", want) |
| + } |
| + } |
| + body = peopleGet(t, fx, c, "/fleet/people?page=3") |
| + if _, rows := peopleRows(t, body); len(rows) != 20 { |
| + t.Errorf("page 3 has %d rows, want 20", len(rows)) |
| + } |
| + if got := peopleCurrentPage(body); got != "3" { |
| + t.Errorf("page 3's pager marks %q current", got) |
| + } |
| + |
| + body = peopleGet(t, fx, c, "/fleet/people?q=member-00") |
| + if strings.Contains(body, "<nav rst-pagination") { |
| + t.Error("a one-page search shows a pager") |
| + } |
| +} |
| + |
| +func TestPeoplePageClampsItsParameters(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + c := signInOperator(t, fx) |
| + peopleSeedTo(t, fx, 120) |
| + |
| + _, first := peopleRows(t, peopleGet(t, fx, c, "/fleet/people")) |
| + for _, p := range []string{"0", "-3", "abc", "", "1.5", "99999999999999999999999"} { |
| + body := peopleGet(t, fx, c, "/fleet/people?page="+url.QueryEscape(p)) |
| + _, rows := peopleRows(t, body) |
| + if peopleCurrentPage(body) != "1" || strings.Join(rows, "") != strings.Join(first, "") { |
| + t.Errorf("page=%q is not page 1", p) |
| + } |
| + } |
| + _, last := peopleRows(t, peopleGet(t, fx, c, "/fleet/people?page=3")) |
| + for _, p := range []string{"4", "99999", "9223372036854775807"} { |
| + body := peopleGet(t, fx, c, "/fleet/people?page="+p) |
| + _, rows := peopleRows(t, body) |
| + if peopleCurrentPage(body) != "3" || len(rows) != 20 || strings.Join(rows, "") != strings.Join(last, "") { |
| + t.Errorf("page=%s is not the last page (3): current %q, %d rows", p, peopleCurrentPage(body), len(rows)) |
| + } |
| + } |
| + body := peopleGet(t, fx, c, "/fleet/people?show=nope") |
| + if !strings.Contains(body, `<a href="/fleet/people" aria-current="page">People</a>`) { |
| + t.Error("show=nope is not the people view") |
| + } |
| + long := strings.Repeat("é", 2000) |
| + body = peopleGet(t, fx, c, "/fleet/people?q="+url.QueryEscape(long)) |
| + if !strings.Contains(body, `value="`+strings.Repeat("é", searchMax)+`"`) { |
| + t.Errorf("a 2,000-character q is not cut to %d characters", searchMax) |
| + } |
| +} |
| + |
| +// TestParsePeopleQuery: not acceptance, a unit test of the parameter rules. |
| +func TestParsePeopleQuery(t *testing.T) { |
| + for _, tc := range []struct { |
| + raw string |
| + want peopleQuery |
| + }{ |
| + {"", peopleQuery{Show: "people", Page: 1}}, |
| + {"show=accounts&q=+shop+&page=2", peopleQuery{Show: "accounts", Q: "shop", Page: 2}}, |
| + {"show=ACCOUNTS&page=0", peopleQuery{Show: "people", Page: 1}}, |
| + {"page=-1&q=%20%20", peopleQuery{Show: "people", Page: 1}}, |
| + {"q=" + strings.Repeat("a", 150), peopleQuery{Show: "people", Q: strings.Repeat("a", searchMax), Page: 1}}, |
| + } { |
| + v, err := url.ParseQuery(tc.raw) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if got := parsePeopleQuery(v); got != tc.want { |
| + t.Errorf("parsePeopleQuery(%q) = %+v, want %+v", tc.raw, got, tc.want) |
| + } |
| + } |
| +} |
| + |
| +// 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. |
| +func TestPerfTargetsCoverOperatorViews(t *testing.T) { |
| + targets := perfOperatorTargets() |
| + shows := map[string]bool{} |
| + for _, tg := range targets["GET /fleet/people"] { |
| + u, err := url.Parse(tg.Path) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if u.Path != "/fleet/people" || tg.Expect != http.StatusOK { |
| + t.Errorf("target %+v is not a 200 on /fleet/people", tg) |
| + } |
| + shows[parsePeopleQuery(u.Query()).Show] = true |
| + } |
| + for _, s := range peopleShows { |
| + if !shows[s] { |
| + t.Errorf("no walk target shows %q", s) |
| + } |
| + } |
| +} |
diff --git a/internal/console/opshots_test.go b/internal/console/opshots_test.go| index bd44e1d7f..978969134 100644 |
| --- a/internal/console/opshots_test.go |
| +++ b/internal/console/opshots_test.go |
| @@ -24,6 +24,8 @@ var opShotPages = []struct{ name, path string }{ |
| {"dashboard", "/fleet"}, |
| {"boxes", "/fleet/boxes"}, |
| {"store", "/fleet/store"}, |
| + {"people", "/fleet/people"}, |
| + {"accounts", "/fleet/people?show=accounts"}, |
| } |
| // 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 3eb9b831f..0f15327e7 100644 |
| --- a/internal/console/perfwalk_test.go |
| +++ b/internal/console/perfwalk_test.go |
| @@ -489,9 +489,30 @@ func perfTargets(fx *consoleFixture) map[string][]perfTarget { |
| // Advanced folded into General; its old URL is a 303 to /settings. |
| m["GET /a/{sqid}/apps/{app}/settings/{section}"] = append(m["GET /a/{sqid}/apps/{app}/settings/{section}"], |
| perfTarget{Path: app + "/settings/advanced", Expect: http.StatusSeeOther}) |
| + for screen, ts := range perfOperatorTargets() { |
| + m[screen] = ts |
| + } |
| return m |
| } |
| +// 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. |
| +func perfOperatorTargets() map[string][]perfTarget { |
| + ok := func(paths ...string) []perfTarget { |
| + var out []perfTarget |
| + for _, p := range paths { |
| + out = append(out, perfTarget{Path: p, Expect: http.StatusOK}) |
| + } |
| + return out |
| + } |
| + 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"), |
| + } |
| +} |
| + |
| // perfReadBudgets reads testdata/perf-budgets.txt for perfWalkTargets, |
| // which has no test to fail; the walk loads it through loadPerfBudgets |
| // first, so a bad file is reported there. |
diff --git a/internal/console/server.go b/internal/console/server.go| index 24d8ae379..6a59858b8 100644 |
| --- a/internal/console/server.go |
| +++ b/internal/console/server.go |
| @@ -1665,6 +1665,7 @@ func NewServer(cfg Config, st *Store) (*Server, error) { |
| s.registerRoute("GET /fleet", s.handleDashboard) |
| s.registerRoute("GET /fleet/boxes", s.handleBoxes) |
| s.registerRoute("GET /fleet/index", s.handleOpIndex) |
| + s.registerRoute("GET /fleet/people", s.handlePeople) |
| s.registerRoute("GET /fleet/store", s.handleStoreApprovalsPage) |
| s.registerRoute("POST /fleet/store/{account}/{decision}", s.handleStoreDecisionPage) |
| s.registerRoute("POST /a/{sqid}/store/apply", s.handleStoreApplyPage) |
| @@ -2249,6 +2250,9 @@ type page struct { |
| // Dash is the dashboard's data (/fleet, opdashboard.go). |
| Dash *dashView |
| + // People is People and accounts' data (/fleet/people, oppeople.go). |
| + People *peopleView |
| + |
| // /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 ec1811a57..299c37eba 100644 |
| --- a/internal/console/static/ops.css |
| +++ b/internal/console/static/ops.css |
| @@ -26,6 +26,8 @@ |
| [co-cols="activity"] { --rst-cols: 6rem minmax(10rem, 1.2fr) minmax(12rem, 2fr) minmax(7rem, 1fr); } |
| [co-cols="boxes"] { --rst-cols: minmax(8rem, 1fr) 7rem 6rem minmax(9rem, 1.4fr) 8rem; } |
| [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; } |
| /* 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 |
| @@ -35,11 +37,17 @@ |
| [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="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="boxes"] > [rst-lrow] > :nth-child(n+3), |
| [co-cols="jobs"] > [rst-lrow] > :nth-child(n+3) { display: none; } |
| } |
| +/* A page's view switch under a stats band: the band has no margin of its |
| + own, so the switch keeps the gap a section head would. */ |
| +[co-tabs] { margin-block-start: 1.5rem; } |
| + |
| /* 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_people.html b/internal/console/templates/ops_people.html| new file mode 100644 |
| index 000000000..c50657cc8 |
| --- /dev/null |
| +++ b/internal/console/templates/ops_people.html |
| @@ -0,0 +1,44 @@ |
| +{{/* People and accounts (/fleet/people, oppeople.go): the active band, |
| + the People/Accounts switch, and one searchable, paged list card. |
| + Everything computed in Go arrives in .People. */}} |
| +{{define "ops_people"}}{{template "op_top" .}} |
| +{{template "op_page_header" (opHeader .Title "Everyone who has signed in and every account.")}} |
| +{{with .People}} |
| +{{if (index .Active 0).Label}} |
| +<div rst-stats rst-card> |
| + {{- range .Active}} |
| + {{template "op_stat" .}} |
| + {{- end}} |
| +</div> |
| +{{end}} |
| +<div co-tabs>{{template "op_seg_tabs" .Tabs}}</div> |
| +{{if eq .Query.Show "accounts"}} |
| +<div rst-card co-cols="accounts"> |
| + {{template "op_list_bar" .Bar}} |
| + {{- if .Accounts}} |
| + <div rst-lrow="head"><span>Account</span><span>Created</span><span>Plan</span><span>Apps</span><span>Members</span></div> |
| + {{- range .Accounts}} |
| + <div rst-lrow><a class="rst-nm" href="/fleet/activity?account={{.Sqid}}">{{.Name}}</a><span class="rst-cell-mut" title="{{fmtTime .Created}}">{{ago .Created}}</span>{{if .Plan}}<span>{{.Plan}}</span>{{else}}<span class="rst-cell-mut">none</span>{{end}}<span>{{opnum .Apps}}</span><span>{{opnum .Members}}</span></div> |
| + {{- end}} |
| + {{- else if .Query.Q}} |
| + {{template "op_empty" (opEmpty "" "No accounts match that search.")}} |
| + {{- end}} |
| +</div> |
| +{{else}} |
| +<div rst-card co-cols="persons"> |
| + {{template "op_list_bar" .Bar}} |
| + {{- if .People}} |
| + <div rst-lrow="head"><span>Person</span><span>Joined</span><span>Last seen</span><span>Accounts</span></div> |
| + {{- range .People}} |
| + <div rst-lrow><span class="rst-nm">{{.Address}}</span><span class="rst-cell-mut" title="{{fmtTime .Joined}}">{{ago .Joined}}</span>{{if .LastSeen.IsZero}}<span class="rst-cell-mut">not yet</span>{{else}}<span class="rst-cell-mut" title="{{fmtTime .LastSeen}}">{{ago .LastSeen}}</span>{{end}}<span>{{opnum .Accounts}}</span></div> |
| + {{- end}} |
| + {{- else if .Query.Q}} |
| + {{template "op_empty" (opEmpty "" "No people match that search.")}} |
| + {{- else}} |
| + {{template "op_empty" (opEmpty "" "No one has signed up yet.")}} |
| + {{- end}} |
| +</div> |
| +{{end}} |
| +{{with .Pager.Items}}{{template "op_pagination" $.People.Pager}}{{end}} |
| +{{end}} |
| +{{template "op_bottom" .}}{{end}} |
diff --git a/internal/console/testdata/claim-routes.txt b/internal/console/testdata/claim-routes.txt| index 21b9363ed..d324c0bb8 100644 |
| --- a/internal/console/testdata/claim-routes.txt |
| +++ b/internal/console/testdata/claim-routes.txt |
| @@ -117,6 +117,7 @@ route GET /fleet/economics |
| route GET /fleet/economics/accounts |
| route GET /fleet/index |
| route GET /fleet/metrics |
| +route GET /fleet/people |
| route GET /fleet/store |
| route GET /healthz |
| route GET /invite/{token} |