feat(admin): staff instance detail, subscriptions and richer search

Closes the rest of what spec 4's screens need. Account search now also
matches a Paddle customer ID and resolves an instance UUID to its owning
account -- a support email often contains a UUID and nothing else, and the
old search returned nothing for it.

GET /api/staff/instances/:id is the "why did this stop working" screen's
data: the instance, its account, its whole licence history newest first, and
whether the control plane currently holds the blob we think it holds.
Injection state is reported only for cloud, because for self-hosted the
customer holds the blob and there is nothing for us to have written.

Account detail gains subscriptions, customer users and its own audit trail.
No secret leaves: the password hash and both verify-token fields are json:"-".

The control-plane write surface is unchanged -- still exactly one UpdateOne
of three licence fields in inject.go, with reads everywhere else.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
mrhid6
2026-07-25 20:50:11 +01:00
co-authored by Claude Opus 5
parent 4bb7400b8e
commit 55526263a0
3 changed files with 124 additions and 13 deletions
@@ -310,7 +310,7 @@ git commit -m "feat(admin): session probe, self-hosted signup and the relink cap
- `GET /api/staff/accounts?q=` also matching `paddle_customer_id` and an instance UUID
- `GET /api/staff/accounts/:id` also returning `subscriptions`, `users`, `audit`
- [ ] **Step 1: Search accounts by Paddle ID and instance UUID**
- [x] **Step 1: Search accounts by Paddle ID and instance UUID**
In `staffListAccounts`, replace the `if q := c.Query("q"); q != ""` block:
@@ -332,7 +332,7 @@ In `staffListAccounts`, replace the `if q := c.Query("q"); q != ""` block:
}
```
- [ ] **Step 2: Fill out account detail**
- [x] **Step 2: Fill out account detail**
Replace the body of `staffGetAccount` after the account lookup:
@@ -366,7 +366,7 @@ Replace the body of `staffGetAccount` after the account lookup:
`CustomerUser.PasswordHash` and both verify-token fields are `json:"-"`, so no secret leaves here.
- [ ] **Step 3: Add staff instance detail**
- [x] **Step 3: Add staff instance detail**
Append to `admin/internal/api/staff.go`:
@@ -447,7 +447,7 @@ func staffListSubscriptions(c *gin.Context) {
}
```
- [ ] **Step 4: Filter audit by account**
- [x] **Step 4: Filter audit by account**
In `staffAudit`, replace `bson.M{}` with a filter:
@@ -460,7 +460,7 @@ In `staffAudit`, replace `bson.M{}` with a filter:
options.Find().SetLimit(500).SetSort(bson.D{{Key: "created_at", Value: -1}}))
```
- [ ] **Step 5: Route them**
- [x] **Step 5: Route them**
In the `staff` group in `admin/internal/api/routes.go`:
@@ -469,7 +469,7 @@ In the `staff` group in `admin/internal/api/routes.go`:
staff.GET("/subscriptions", staffListSubscriptions)
```
- [ ] **Step 6: Build and confirm the write surface is unchanged**
- [x] **Step 6: Build and confirm the write surface is unchanged**
```bash
sh /tmp/gorun.sh admin go build ./... && sh /tmp/gorun.sh admin go vet ./...
@@ -478,7 +478,7 @@ grep -rn 'Control("' admin/internal/ --include=*.go | grep -v "db.go"
Expected: build clean; exactly one `UpdateOne` on `instances` in `inject.go`, and reads only elsewhere. `staffGetInstance` adds a read, never a write.
- [ ] **Step 7: Confirm search by UUID**
- [x] **Step 7: Confirm search by UUID**
With the spec-3 verification stack running and an instance adopted:
@@ -489,7 +489,7 @@ curl -s localhost:8083/api/staff/instances/6a0fe3f0-49d2-4aa1-967c-a3094b200b5d
Expected: the owning account, and an instance payload whose `injection.state` is `current`.
- [ ] **Step 8: Commit**
- [x] **Step 8: Commit**
```bash
git add admin/