Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.d/fixed-18816-customers-layout-and-noise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- The Customers section is laid out like the Inbox and Calendar: each person is a card with an initial or source icon, the name as the title, a muted line, tags as chips and grouped actions that wrap under the content on narrow screens, with no sideways scrolling and long keys cut with a tooltip. "me" is a badge, "0 goals" is no longer printed on every row, and the evidence behind a suggestion sits under "Why is this suggested?" as readable links (at most five). Suggested people are grouped by source with "Show N more", and accepting, dismissing or answering a "Same person?" question keeps the group open, its expansion and the scroll position, and moves the focus to the next suggestion. A suggestion can now be added to an existing customer ("Add to existing..." on a suggestion, "Add a suggested person here" on a profile); it reuses the merge, so Undo merge takes it back (#18816).
- Customers discovery no longer suggests people who are already customers or who are not people. A hive user whose access-list name is a bare GitHub login (what a device-flow sign-in produces) is now linked to that GitHub login, so they are not suggested again, and a suggestion that points at an identity a customer owns expires. Calendar group and room addresses, mailing-list addresses, no-reply and service mailboxes and the hive's own `hive@<host>` address are never suggested, and those already stored expire on the next sweep (#18816).
18 changes: 17 additions & 1 deletion dashboard/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2400,7 +2400,23 @@
"Customers"
],
"summary": "Accept a suggested person",
"description": "Turns a suggestion into a customer. This is the human decision that lets the hive build a profile of someone who never signed up. Owner or read-write. Audited as customer_accept.",
"description": "Turns a suggestion into a customer. This is the human decision that lets the hive build a profile of someone who never signed up. With the optional body {\"into\": \"<customer id or me>\"} it attaches the suggestion to that existing customer instead: the identity becomes one of theirs (a manual decision, so it is not suggested again), no new person is created, the activity moves onto them on the next sweep, and POST /api/customers/{id}/unmerge undoes it. Owner or read-write. Audited as customer_accept, or customer_attach with the target's id.",
"requestBody": {
"required": false,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"into": {
"type": "string",
"description": "Existing customer id, or me, to attach the suggestion to"
}
}
}
}
}
},
"parameters": [
{
"name": "sid",
Expand Down
38 changes: 34 additions & 4 deletions src/cmd/hive/customers_sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"net/mail"
"net/url"
"strings"
"time"

Expand All @@ -14,6 +15,7 @@ import (
"github.com/hivecommons/hive/pkg/github"
"github.com/hivecommons/hive/pkg/inbox"
"github.com/hivecommons/hive/pkg/mailallow"
"github.com/hivecommons/hive/pkg/mailin/wire"
"github.com/hivecommons/hive/pkg/meetings"
"github.com/hivecommons/hive/pkg/meetings/schedule"
)
Expand All @@ -29,8 +31,8 @@ const (
// customersSweepInterval is how often discovery runs. Everything it
// reads is local, so the cost of a pass is a few file reads.
customersSweepInterval = 10 * time.Minute
// githubUserPrefix marks an access-list entry the hub authenticated
// with GitHub ("github:alice"): the name is a GitHub login.
// githubUserPrefix is the optional provider prefix of an access-list
// entry the hub authenticated with GitHub ("github:alice").
githubUserPrefix = "github:"
)

Expand Down Expand Up @@ -142,6 +144,7 @@ func customersSweepInput(src customersSources) customers.SweepInput {
if src.cfg == nil {
return in
}
in.OwnAddresses = customersOwnAddresses(src.cfg)
in.Users, in.Links = customersUsers(src)
in.Sightings = append(in.Sightings, customersGitHubSightings(src)...)
in.Sightings = append(in.Sightings, customersLocalSightings(src)...)
Expand Down Expand Up @@ -173,8 +176,11 @@ func customersUsers(src customersSources) ([]customers.HiveUser, []customers.Pro
if role == config.RoleOwner {
owners = append(owners, name)
}
// The hub writes a GitHub-authenticated user as "github:<login>".
if login, ok := strings.CutPrefix(strings.ToLower(name), githubUserPrefix); ok && login != "" {
// The hub writes a GitHub-authenticated user as "github:<login>",
// and a device-flow login is the bare login: the access list
// treats the two as one user. Either way the name is a GitHub
// login, as long as it is shaped like one.
if login := customersGitHubLogin(name); login != "" {
links = append(links, customers.ProvenLink{User: name, Identity: customers.Identity{
Kind: customers.KindGitHub, Value: login, Source: customersSourceAccessList,
}})
Expand All @@ -198,6 +204,30 @@ func customersUsers(src customersSources) ([]customers.HiveUser, []customers.Pro
return users, links
}

// customersGitHubLogin is the GitHub login an access-list name stands for, or
// "" when it is not one: a name with another provider prefix, an address or
// anything else a login cannot be.
func customersGitHubLogin(name string) string {
login := strings.TrimPrefix(strings.ToLower(strings.TrimSpace(name)), githubUserPrefix)
if !customers.LooksLikeGitHubLogin(login) {
return ""
}
return login
}

// customersOwnAddresses are this hive's own mail addresses: hive@<dashboard
// host>. Mail and invites sent to it are never a person.
func customersOwnAddresses(cfg *config.Config) []string {
if cfg == nil {
return nil
}
u, err := url.Parse(strings.TrimSpace(cfg.Hub.DashboardURL))
if err != nil || u.Hostname() == "" {
return nil
}
return []string{wire.LocalPart + "@" + strings.ToLower(u.Hostname())}
}

// customersIsPerson reports whether a GitHub login is a person rather than
// a bot or this hive's own author account.
func customersIsPerson(cfg *config.Config, login string) bool {
Expand Down
35 changes: 35 additions & 0 deletions src/cmd/hive/customers_sweep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ func TestCustomersSweepInputMapsLocalState(t *testing.T) {
"github:Olivia|github|olivia": customersSourceAccessList,
"github:Olivia|github|olivia-gh": customersSourceOwner,
"rita|email|rita@example.com": customersSourceProof,
// A bare access-list name is the GitHub login of a device-flow user.
"rita|github|rita": customersSourceAccessList,
"max|github|max": customersSourceAccessList,
"reed|github|reed": customersSourceAccessList,
}
if len(links) != len(wantLinks) {
t.Fatalf("links = %v, want %v (an unproven email must not link)", links, wantLinks)
Expand Down Expand Up @@ -370,3 +374,34 @@ func TestCustomersAuditResolver(t *testing.T) {
t.Fatal("the audit resolver is not registered")
}
}

// TestCustomersBareAccessListNameIsGitHubLogin pins the root cause of
// hive users showing up as suggested GitHub people: the access list holds a
// device-flow user as the bare login, not "github:<login>", and only the
// prefixed form used to be linked.
func TestCustomersBareAccessListNameIsGitHubLogin(t *testing.T) {
for name, want := range map[string]string{
"danathar": "danathar", "GitHub:Alice": "alice", "github:bob-1": "bob-1", " carol ": "carol",
"ibmid:abc": "", "dave@example.com": "", "has.dot": "", "under_score": "", "-lead": "", "a--b": "", "": "", "github:": "",
"x23456789012345678901234567890123456789x": "",
} {
if got := customersGitHubLogin(name); got != want {
t.Errorf("customersGitHubLogin(%q) = %q, want %q", name, got, want)
}
}
}

func TestCustomersOwnAddresses(t *testing.T) {
cfg := &config.Config{}
cfg.Hub.DashboardURL = "https://Hosted-X.hive.example.dev/"
got := customersOwnAddresses(cfg)
if len(got) != 1 || got[0] != "hive@hosted-x.hive.example.dev" {
t.Fatalf("own addresses = %v", got)
}
if customersOwnAddresses(&config.Config{}) != nil || customersOwnAddresses(nil) != nil {
t.Fatal("an unknown host must give no own address")
}
if in := customersSweepInput(customersSources{cfg: cfg}); len(in.OwnAddresses) != 1 {
t.Fatalf("the sweep input lacks the own address: %v", in.OwnAddresses)
}
}
4 changes: 4 additions & 0 deletions src/cmd/hive/customerswire.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ func installCustomersAgentContext(c *customersDashboard, setKickLookup func(sche
}
}

func (c *customersDashboard) AcceptInto(v dashboard.CustomersViewer, suggestionID, into string) (dashboard.CustomerResult, error) {
return customerResult(c.svc.AcceptInto(customersViewer(v), suggestionID, into))
}

func (c *customersDashboard) Merge(v dashboard.CustomersViewer, id, from string) (dashboard.CustomerResult, error) {
return customerResult(c.svc.Merge(customersViewer(v), id, from))
}
Expand Down
24 changes: 12 additions & 12 deletions src/docs/api-reference/customers.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ The rules are enforced twice: by the handlers and again by the store's service o

| Method | Path | Auth | Purpose | Source |
|---|---|---|---|---|
| `GET` | `/api/customers` | Signed-in user | The Customers section: `{enabled, full, owner, me, people, suggestions, default_tags, levels}`. `me` is the viewer's own profile, created on first read. `people` and `suggestions` are empty without the full view | `pkg/dashboard/api_customers.go:164` |
| `POST` | `/api/customers` | Full view | Add a customer by hand: `{name, identities?: [{kind, value}]}`. 409 when an identity belongs to another customer; a `hive_user` identity is refused. Audited as `customer_add` | `pkg/dashboard/api_customers.go:165` |
| `GET` | `/api/customers/{id}` | Signed-in user; self reaches only `me` | One profile, with edge counts and open "Same person?" hints for the full view. A viewer without the full view gets no notes, satisfaction, merge history, counts or hints. Opening someone else's profile is audited as `customer_profile_open` | `pkg/dashboard/api_customers.go:166` |
| `POST` | `/api/customers/{id}/edit` | Full view; self only as `/api/customers/me/edit` | One change: `{op, ...}` with `op` one of `name`, `notes`, `identity_add` (`kind`, `value`), `identity_remove` (`key`), `tag` (`tag`, `state` of `on`, `off` or `auto`), `goal_add` (`text`), `goal_edit` (`goal_id`, `text`), `goal_confirm`, `goal_reject` (`goal_id`), `satisfaction_set` (`level`), `satisfaction_confirm`, `satisfaction_reject`. Self may use the name, identity, tag and goal ops; an identity added by self is an unconfirmed claim that resolves nobody until the full view confirms it with `identity_add`. Audited as `customer_edit` with the person and the op, never the value | `pkg/dashboard/api_customers.go:167` |
| `DELETE` | `/api/customers/{id}` | Owner only | Forget: deletes the customer, their identities and every edge to them, and keeps one salted-hash tombstone per confirmed identity so discovery does not rebuild them. 200 `{forgotten, edges_removed}`. Audited as `customer_forget` | `pkg/dashboard/api_customers.go:168` |
| `POST` | `/api/customers/suggestions/{sid}/accept` | Full view | Turn a suggested person into a customer. Audited as `customer_accept` | `pkg/dashboard/api_customers.go:169` |
| `POST` | `/api/customers/suggestions/{sid}/dismiss` | Full view | Delete a suggestion and tombstone its key, so it is not offered again. Audited as `customer_dismiss` | `pkg/dashboard/api_customers.go:170` |
| `POST` | `/api/customers/hints/{hid}/answer` | Full view | Answer a "Same person?" question: `{same}`. `true` makes the suggested identity the customer's own and deletes the suggestion; `false` closes the question for good. A question between two customers is answered by merging them, so `true` on one is 400. Audited as `customer_hint_answer` | `pkg/dashboard/api_customers.go:171` |
| `POST` | `/api/customers/{id}/merge` | Full view | Fold the customer `{from}` into this one: identities, tags, goals and activity move across and the merge is recorded. 409 for two dashboard users. Audited as `customer_merge` | `pkg/dashboard/api_customers.go:172` |
| `POST` | `/api/customers/{id}/unmerge` | Full view | Undo a merge: `{from}` comes back as it stood, with exactly what the merge brought it. Audited as `customer_unmerge` | `pkg/dashboard/api_customers.go:173` |
| `POST` | `/api/customers/{id}/split` | Full view | Move identities `{identities: ["kind:value"], name?}` off this customer onto a new one, with the activity they produced; returns the new customer. Audited as `customer_split` | `pkg/dashboard/api_customers.go:174` |
| `GET` | `/api/customers/{id}/export` | Owner only | Everything held about one customer as a JSON download: the profile, merge history, hints and up to 10,000 activity references. Audited as `customer_export` | `pkg/dashboard/api_customers.go:175` |
| `GET` | `/api/customers` | Signed-in user | The Customers section: `{enabled, full, owner, me, people, suggestions, default_tags, levels}`. `me` is the viewer's own profile, created on first read. `people` and `suggestions` are empty without the full view | `pkg/dashboard/api_customers.go:174` |
| `POST` | `/api/customers` | Full view | Add a customer by hand: `{name, identities?: [{kind, value}]}`. 409 when an identity belongs to another customer; a `hive_user` identity is refused. Audited as `customer_add` | `pkg/dashboard/api_customers.go:175` |
| `GET` | `/api/customers/{id}` | Signed-in user; self reaches only `me` | One profile, with edge counts and open "Same person?" hints for the full view. A viewer without the full view gets no notes, satisfaction, merge history, counts or hints. Opening someone else's profile is audited as `customer_profile_open` | `pkg/dashboard/api_customers.go:176` |
| `POST` | `/api/customers/{id}/edit` | Full view; self only as `/api/customers/me/edit` | One change: `{op, ...}` with `op` one of `name`, `notes`, `identity_add` (`kind`, `value`), `identity_remove` (`key`), `tag` (`tag`, `state` of `on`, `off` or `auto`), `goal_add` (`text`), `goal_edit` (`goal_id`, `text`), `goal_confirm`, `goal_reject` (`goal_id`), `satisfaction_set` (`level`), `satisfaction_confirm`, `satisfaction_reject`. Self may use the name, identity, tag and goal ops; an identity added by self is an unconfirmed claim that resolves nobody until the full view confirms it with `identity_add`. Audited as `customer_edit` with the person and the op, never the value | `pkg/dashboard/api_customers.go:177` |
| `DELETE` | `/api/customers/{id}` | Owner only | Forget: deletes the customer, their identities and every edge to them, and keeps one salted-hash tombstone per confirmed identity so discovery does not rebuild them. 200 `{forgotten, edges_removed}`. Audited as `customer_forget` | `pkg/dashboard/api_customers.go:178` |
| `POST` | `/api/customers/suggestions/{sid}/accept` | Full view | Turn a suggested person into a customer. With the optional body `{into}` (an existing customer id, or `me`) it attaches the suggestion to that customer instead: the identity becomes one of theirs, pinned as a manual decision, no new person is created, the activity moves onto them on the next sweep, and `unmerge` undoes it with the id in the target's merge history. Audited as `customer_accept`, or `customer_attach` with the target's id and never a name | `pkg/dashboard/api_customers.go:179` |
| `POST` | `/api/customers/suggestions/{sid}/dismiss` | Full view | Delete a suggestion and tombstone its key, so it is not offered again. Audited as `customer_dismiss` | `pkg/dashboard/api_customers.go:180` |
| `POST` | `/api/customers/hints/{hid}/answer` | Full view | Answer a "Same person?" question: `{same}`. `true` makes the suggested identity the customer's own and deletes the suggestion; `false` closes the question for good. A question between two customers is answered by merging them, so `true` on one is 400. Audited as `customer_hint_answer` | `pkg/dashboard/api_customers.go:181` |
| `POST` | `/api/customers/{id}/merge` | Full view | Fold the customer `{from}` into this one: identities, tags, goals and activity move across and the merge is recorded. 409 for two dashboard users. Audited as `customer_merge` | `pkg/dashboard/api_customers.go:182` |
| `POST` | `/api/customers/{id}/unmerge` | Full view | Undo a merge: `{from}` comes back as it stood, with exactly what the merge brought it. Audited as `customer_unmerge` | `pkg/dashboard/api_customers.go:183` |
| `POST` | `/api/customers/{id}/split` | Full view | Move identities `{identities: ["kind:value"], name?}` off this customer onto a new one, with the activity they produced; returns the new customer. Audited as `customer_split` | `pkg/dashboard/api_customers.go:184` |
| `GET` | `/api/customers/{id}/export` | Owner only | Everything held about one customer as a JSON download: the profile, merge history, hints and up to 10,000 activity references. Audited as `customer_export` | `pkg/dashboard/api_customers.go:185` |
| `POST` | `/api/graph` | Signed-in user | The customer graph over GraphQL, read-only (no mutations, so a read-only user may call it): `{query, operationName?, variables?}`, answered with a GraphQL `{data, errors}` document. Access follows the viewer exactly as above; see [the customer graph](#the-customer-graph). Audited as `customer_graph_query` with the operation name, node count and error count, never the query text | `pkg/dashboard/api_graph.go:47` |

## The customer graph
Expand Down
11 changes: 7 additions & 4 deletions src/docs/security-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,13 @@ hash, so they are not rebuilt.

Links between identities are made only on exact keys. A display name never links
anyone. One link rests on an assumption you should know about. When the access
list holds a name such as `github:alice`, the hive treats `alice` as that
person's GitHub login. The hub put that entry there after it signed the person
in with GitHub, so the hive trusts it. If your access list is edited by hand, an
entry like that gives the named person's profile the matching GitHub activity.
list holds a name such as `github:alice`, or the bare login `alice` that a
GitHub device-flow sign-in produces (the access list treats the two as one
user), the hive treats `alice` as that person's GitHub login. A name with
another provider prefix, an address, a dot or an underscore is not read as a
login. The hub put that entry there after it signed the person in with GitHub,
so the hive trusts it. If your access list is edited by hand, an entry like
that gives the named person's profile the matching GitHub activity.

A read-only user sees only their own profile. An identity they add is shown as
unconfirmed. It links nothing until the owner or a read-write user confirms it.
Expand Down
Loading
Loading