diff --git a/README.md b/README.md index bfe76b2..1e5cd54 100644 --- a/README.md +++ b/README.md @@ -119,14 +119,14 @@ a required BuildKit secret, never through build arguments or committed files. ## Catalog and release -The next app release is **0.1.11**, also recorded in `web/package.json`. +The next app release is **0.1.12**, also recorded in `web/package.json`. `catalog/entry.yaml` carries no committed version: the first tag (`v0.1.0`) created `versions[]` with `ghcr.io/appthrust/tracker@sha256:`, stream `0.1`; later tags append at publication time. Do not add a version with an unbuilt or placeholder image digest. OpenAPI's `info.version` describes the API schema, not the app release. This repository has no hand-maintained changelog. -After the release prerequisites are available, push the SemVer tag `v0.1.11`. +After the release prerequisites are available, push the SemVer tag `v0.1.12`. The tag workflow: 1. Performs one multi-platform build on `ubuntu-24.04` for Linux amd64 and arm64, @@ -146,8 +146,8 @@ The tag workflow: Publication commands used by the workflow: ```sh -bun hack/publish-entry.ts submit --version 0.1.11 --digest sha256: -bun hack/publish-entry.ts await --version 0.1.11 --digest sha256: +bun hack/publish-entry.ts submit --version 0.1.12 --digest sha256: +bun hack/publish-entry.ts await --version 0.1.12 --digest sha256: ``` Writers are serialized by `tracker-catalog-publish`; the workflow is guarded to @@ -168,7 +168,7 @@ After publication, each estate's `AppCatalogSource` syncs the signed catalog. Install Issues from the Project Marketplace (Directory is an automatic dependency). Existing `follow` installations on stream `0.1` roll to the new version; `pinned` installations show `UpdateAvailable` and require an explicit -version update. Confirm the installation is Ready, `/releasez` reports `0.1.11`, +version update. Confirm the installation is Ready, `/releasez` reports `0.1.12`, the Project lists the `tracker` Access Key space as Ready, and an exchanged key reads `/api/tracker/v1/me`. These are release steps, not actions performed by a source-only version bump. diff --git a/cmd/server/internal/api/api.go b/cmd/server/internal/api/api.go index 60b5ccc..1d7edd6 100644 --- a/cmd/server/internal/api/api.go +++ b/cmd/server/internal/api/api.go @@ -111,14 +111,15 @@ func (a *API) route(pattern string, mutation, roles bool, fn endpoint) { return } s := &request{r: r, w: w} - if claims.Principal.Kind == "key" { + key := claims.Principal.Kind == "key" + if key { actor, err := keyActor(claims.Principal, a.workspace, mutation) if err != nil { httpx.WriteError(w, err, "tracker") return } // The assertion is addressed to Tracker only: it is never forwarded - // to Directory, so people stay the stored snapshots. + // to Directory. The person's name comes from Tracker's own record. s.actor = actor if mutation { log.Printf("tracker access key mutation: %s %s key=%q subject=%q request_id=%q", r.Method, r.URL.Path, claims.Principal.KeyName, actor.Sub, r.Header.Get("X-Request-Id")) @@ -149,7 +150,21 @@ func (a *API) route(pattern string, mutation, roles bool, fn endpoint) { } var body any var status int - err := a.store.InWorkspace(ctx, a.workspace, mutation, func(tx *store.Tx) error { s.tx = tx; var err error; body, status, err = fn(s); return err }) + err := a.store.InWorkspace(ctx, a.workspace, mutation, func(tx *store.Tx) error { + s.tx = tx + if key { + name, err := tx.KnownName(s.actor.Sub) + if err != nil { + return err + } + if name != "" { + s.actor.Name = name + } + } + var err error + body, status, err = fn(s) + return err + }) if err != nil { writeStoreError(w, err) return diff --git a/cmd/server/internal/api/keys_test.go b/cmd/server/internal/api/keys_test.go index cfa0532..70a7cd9 100644 --- a/cmd/server/internal/api/keys_test.go +++ b/cmd/server/internal/api/keys_test.go @@ -5,6 +5,7 @@ import ( "crypto/ecdsa" "crypto/elliptic" "crypto/rand" + "encoding/base64" "encoding/json" "io" "net/http" @@ -75,6 +76,24 @@ func TestAccessKeyActsAsItsUserWithinScopeAndProject(t *testing.T) { page := call[store.Page](h, "admin", "GET", "/issues?filter="+url.QueryEscape(`{"reporter":["me"]}`), nil, 200) require.Len(t, page.Items, 1, "the signed-in user owns what their key reported") + // A key carries no name: it takes the one its user last wrote under while + // signed in, and falls back to the subject before any such write. + require.Equal(t, "admin", issue.Reporter.Name) + owner := assertion("pj-test", user("owner"), scopeRead, scopeWrite) + status, data = do(owner, "GET", "/me", nil) + require.Equal(t, 200, status, string(data)) + require.Contains(t, string(data), `"name":"owner"`) + claims, err := json.Marshal(map[string]string{"sub": "owner", "email": "owner@example.test", "name": "Olivia Owner"}) + require.NoError(t, err) + session := "Bearer " + base64.RawURLEncoding.EncodeToString([]byte(`{"alg":"none"}`)) + "." + base64.RawURLEncoding.EncodeToString(claims) + "." + status, data = do(session, "POST", "/issues", map[string]string{"title": "Signed in", "type": "task"}) + require.Equal(t, 201, status, string(data)) + status, data = do(owner, "POST", "/issues/"+issue.ID+"/comments", map[string]string{"body": "From the key"}) + require.Equal(t, 201, status, string(data)) + var comment domain.Comment + require.NoError(t, json.Unmarshal(data, &comment)) + require.Equal(t, domain.Person{Sub: "owner", Name: "Olivia Owner"}, comment.Author) + issue2 := map[string]string{"title": "Refused", "type": "task"} for _, test := range []struct { name, bearer, method, path string diff --git a/cmd/server/internal/api/openapi.json b/cmd/server/internal/api/openapi.json index 2e59788..1d81f28 100644 --- a/cmd/server/internal/api/openapi.json +++ b/cmd/server/internal/api/openapi.json @@ -2,7 +2,7 @@ "openapi": "3.1.0", "info": { "title": "Tracker API", - "version": "0.1.11", + "version": "0.1.12", "description": "Contract: design/API.md. One workspace per PLATFORM_PROJECT_ID. The bearer is the signed-in user's token or an Access Key assertion (audience tracker; scope tracker:read for GET, tracker:write otherwise)." }, "servers": [ diff --git a/cmd/server/internal/store/migrations/012_activity_actor.sql b/cmd/server/internal/store/migrations/012_activity_actor.sql new file mode 100644 index 0000000..32b0580 --- /dev/null +++ b/cmd/server/internal/store/migrations/012_activity_actor.sql @@ -0,0 +1,2 @@ +-- Access Key requests resolve the caller's display name from their latest signed-in write. +CREATE INDEX tracker_activity_actor ON tracker_activity (actor_sub, created_at DESC); diff --git a/cmd/server/internal/store/people.go b/cmd/server/internal/store/people.go new file mode 100644 index 0000000..d856d78 --- /dev/null +++ b/cmd/server/internal/store/people.go @@ -0,0 +1,19 @@ +package store + +import ( + "database/sql" + "errors" +) + +// KnownName returns the display name most recently recorded for a person by a +// signed-in write, or "" when this workspace has never seen one. Access Key +// requests carry no name, and their own writes record the subject as the name, +// so those rows are not a source. +func (t *Tx) KnownName(sub string) (string, error) { + var name string + err := t.SQL.QueryRowContext(t.Context, `SELECT a.actor_name FROM tracker_activity a JOIN tracker_issue i ON i.id=a.issue_id WHERE i.workspace_id=$1 AND a.actor_sub=$2 AND a.actor_name<>a.actor_sub ORDER BY a.created_at DESC LIMIT 1`, t.WorkspaceID, sub).Scan(&name) + if errors.Is(err, sql.ErrNoRows) { + return "", nil + } + return name, err +} diff --git a/cmd/server/internal/store/projects_test.go b/cmd/server/internal/store/projects_test.go index 7301bd6..a657689 100644 --- a/cmd/server/internal/store/projects_test.go +++ b/cmd/server/internal/store/projects_test.go @@ -246,7 +246,7 @@ func TestProjectsMigrationFromV010(t *testing.T) { } var versions int require.NoError(t, tx.SQL.QueryRowContext(t.Context(), `SELECT count(*) FROM tracker_schema_migrations`).Scan(&versions)) - require.Equal(t, 11, versions) + require.Equal(t, 12, versions) var reporterIndex string require.NoError(t, tx.SQL.QueryRowContext(t.Context(), `SELECT indexdef FROM pg_indexes WHERE schemaname=current_schema() AND indexname='tracker_issue_reporter'`).Scan(&reporterIndex)) require.Contains(t, reporterIndex, "USING btree (workspace_id, reporter_sub) WHERE (deleted_at IS NULL)") diff --git a/design/API.md b/design/API.md index 3c371b2..5f095fe 100644 --- a/design/API.md +++ b/design/API.md @@ -461,9 +461,12 @@ Rules (`cmd/server/internal/api/keys.go`, `keyActor`): What the user's key creates belongs to that user: `reporter: ['me']` in the SPA lists it. The assertion carries no name or email and is never forwarded to -Directory, so a key write stores `name = sub` as the person snapshot and +Directory. Since v0.1.12 the key's person takes the display name of that +user's most recent signed-in write in this workspace (`store.KnownName`, from +the activity log); before any such write the name is the subject id. `GET /me` +returns `{ sub, name, role: 'Viewer', isAdmin: false }` with the same name. `GET /people` answers `source: 'unavailable'`; a signed-in reader still sees -the Directory name. `GET /me` returns `{ sub, name: sub, role: 'Viewer', isAdmin: false }`. +the Directory name. Each mutation request made with a key writes one `tracker access key mutation:` log line (method, path, key name, subject, edge `X-Request-Id`) before diff --git a/web/package.json b/web/package.json index 8c35c41..e4374c5 100644 --- a/web/package.json +++ b/web/package.json @@ -1,6 +1,6 @@ { "name": "@appthrust/tracker", - "version": "0.1.11", + "version": "0.1.12", "private": true, "type": "module", "scripts": {