Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Admin API: a run whose email a reader may not see says so, and the audit filter lists system

Adarsh8d740dddf764
diff --git a/docs/admin-api.md b/docs/admin-api.md
index 048f79f5..c8b173d2 100644
--- a/docs/admin-api.md
+++ b/docs/admin-api.md
@@ -51,7 +51,8 @@ Keep the token out of URLs, logs and shared files. Send it only in the `Authoriz
| `audit:read` | `GET /api/admin/audit` |
The read-only preset in Settings ticks `runs:read`, `reports:read`, `workers:read`, `queue:read` and `audit:read`:
-no emails, no prompts and no results. With `runs:read`, an account's email in a run needs `accounts:read`.
+no emails, no prompts and no results. With `runs:read`, an account's email in a run needs `accounts:read`. Without it a
+run's `account` is `{ id, emailHidden: true }`; `email: null` always means the account was deleted.
Any valid admin token may call `GET /api/admin/tokens/self`, which says the token's name and scopes, so a tool can
offer only what it may do. `/api/admin/tokens` itself (make, list, revoke) is the owner's signed-in browser's only.
@@ -102,7 +103,7 @@ Times are epoch milliseconds and sizes are bytes. Every answer is `Cache-Control
| `GET /api/admin/accounts/{id}` | | one account with its numbers; 404 `No such account` |
| `PATCH /api/admin/accounts/{id}` | exactly one of `{ disabled: boolean }` or `{ signOut: true }` | the account (no numbers) |
| `DELETE /api/admin/accounts/{id}` | | 204 |
-| `GET /api/admin/generations` | `account`, `status` (`finished`, `running`, `failed`), `kind` (`image`, `video`, `audio`, `model3d`, `text`), `before` (the last page's `next`), `limit` (1 to 100, default 30) | `{ items, next }`; `next` is null on the last page. Each output has a `state`: `shown`, `held` (hidden, or waiting for its check) or `removed` (its file is gone). A failed run on this install's GPUs also has `detail`: the technical reason, which the account never sees |
+| `GET /api/admin/generations` | `account`, `status` (`finished`, `running`, `failed`), `kind` (`image`, `video`, `audio`, `model3d`, `text`), `before` (the last page's `next`), `limit` (1 to 100, default 30) | `{ items, next }`; `next` is null on the last page. Each output has a `state`: `shown`, `held` (hidden, or waiting for its check) or `removed` (its file is gone). A failed run on this install's GPUs also has `detail`: the technical reason, which the account never sees. `account` is `{ id, email }` (`email` null: a deleted account), or `{ id, emailHidden: true }` without `accounts:read` |
| `DELETE /api/admin/generations/{id}` | | 204; 404 for an unknown run or the owner's own |
| `POST /api/admin/outputs/hide` | `{ assetIds?, generationIds? }` (up to 500 each) | `{ hidden }` |
| `POST /api/admin/outputs/unhide` | the same | `{ shown }` |
@@ -117,7 +118,7 @@ Times are epoch milliseconds and sizes are bytes. Every answer is `Cache-Control
| `PATCH /api/admin/workers/{id}` | any of `paused`, `pauseNow`, `drain`, `autoResume`, `hours`, `allow`, `claimAfterMs`, `switchAfterMs`, `rotate` (needs `workers:tokens`), `revoke` | `{ worker, token? }`: a new worker token after `rotate`, once |
| `GET /api/admin/workers/jobs` | `before`, `limit` (1 to 200, 50), `worker`, `generation` | `{ items, next }`: the workers' log, newest first. Each item: `{ id, at, event, workerId, workerName, taskId, generationId, principal, lane, execMs, device }` ([gpu-workers.md](gpu-workers.md)) |
| `GET /api/admin/workers/download` | | the worker program, `fuobe-worker.zip` |
-| `GET /api/admin/audit` | `before` (the last page's `next`), `limit` (1 to 200, default 50), `actor` (`owner` or `token`), `token` (a token id), `action`, `changes=1` (changes only: no reads, file views or refusals) | `{ items, next }` |
+| `GET /api/admin/audit` | `before` (the last page's `next`), `limit` (1 to 200, default 50), `actor` (`owner`, `token` or `system`), `token` (a token id), `action`, `changes=1` (changes only: no reads, file views or refusals) | `{ items, next }` |
| `GET /api/admin/tokens/self` | | `{ id, name, prefix, scopes, expiresAt, createdAt }` |
A log row is `{ id, at, actor: "owner" | "token" | "system", token: { id, name } | null, action, target, detail, status }`.
diff --git a/src/server/account-admin.ts b/src/server/account-admin.ts
index f657746f..a59014a7 100644
--- a/src/server/account-admin.ts
+++ b/src/server/account-admin.ts
@@ -130,11 +130,14 @@ export function accountRunOptions(sp: URLSearchParams): ListOptions | { error: s
export type OutputState = "shown" | "held" | "removed";
/**
- * An account's run as the owner sees it: whose it is (null email: the account was deleted), and each result's state. A
- * run on this install's GPUs also carries `detail`: the technical reason it failed, which the account never sees (its
- * own page shows one plain sentence).
+ * An account's run as the owner sees it: whose it is (null email: the account was deleted; no `email` and
+ * `emailHidden: true`: a reader that may not see emails), and each result's state. A run on this install's GPUs also
+ * carries `detail`: the technical reason it failed, which the account never sees (its own page shows one plain sentence).
*/
-export type AccountRun = Omit<Generation, "outputs"> & { outputs: (OutputFile & { state: OutputState })[]; account: { id: string; email: string | null }; detail?: string };
+export type AccountRun = Omit<Generation, "outputs"> & { outputs: (OutputFile & { state: OutputState })[]; account: AccountOfRun; detail?: string };
+
+/** Whose a run is: its email (null: the account was deleted), or no email and `emailHidden` for a reader that may not see emails. */
+export type AccountOfRun = { id: string; email?: string | null; emailHidden?: true };
/** Each result's state, read from its stored file (its asset row; none: removed). An output that isn't a stored file is shown. */
function withStates(outputs: OutputFile[]): (OutputFile & { state: OutputState })[] {
@@ -203,7 +206,9 @@ export function listAccountRuns(o: ListOptions, show: { content: boolean; emails
};
return {
items: found.map((g) => {
- const run: AccountRun = { ...g, outputs: withStates(g.outputs), account: { id: g.request.account!, email: show.emails ? (emails.get(g.request.account!) ?? null) : null }, ...detail(g) };
+ const id = g.request.account!;
+ const account: AccountOfRun = show.emails ? { id, email: emails.get(id) ?? null } : { id, emailHidden: true };
+ const run: AccountRun = { ...g, outputs: withStates(g.outputs), account, ...detail(g) };
return show.content ? run : factsOnly(run);
}),
next: last && found.length === limit ? `${last.createdAt}:${last.id}` : null,
diff --git a/tests/admin-tokens.test.ts b/tests/admin-tokens.test.ts
index 0671de9a..18f0e851 100644
--- a/tests/admin-tokens.test.ts
+++ b/tests/admin-tokens.test.ts
@@ -553,7 +553,7 @@ describe("admin tokens: accounts' content needs its own scopes", () => {
.run(id, "a private prompt", JSON.stringify({ account: a.id, feature: "image", modelId: "oss-z-image-turbo", prompt: "a private prompt" }), JSON.stringify([{ url: file.url, kind: "image", contentType: "image/png" }]), now, now, now);
return { account: a, id };
}
- type Page = { items: { id: string; prompt?: string; request?: unknown; outputs: { url?: string; state: string }[]; account: { id: string; email: string | null } }[] };
+ type Page = { items: { id: string; prompt?: string; request?: unknown; outputs: { url?: string; state: string }[]; account: { id: string; email?: string | null; emailHidden?: true } }[] };
const runsOf = async (token?: string, cookie?: string) => (await (await routes.runs.GET(req("/api/admin/generations?limit=100", { token, cookie }))).json()) as Page;
it("runs:read alone gets each run's facts: no prompt, no request, no result file, no email", async () => {
@@ -564,7 +564,8 @@ describe("admin tokens: accounts' content needs its own scopes", () => {
expect(run.prompt).toBeUndefined();
expect(run.request).toBeUndefined();
expect(run.outputs).toEqual([{ kind: "image", state: "shown" }]);
- expect(run.account).toEqual({ id: r.account.id, email: null });
+ // Hidden, never null (null says the account was deleted).
+ expect(run.account).toEqual({ id: r.account.id, emailHidden: true });
expect(JSON.stringify(page)).not.toContain("a private prompt");
});
@@ -573,9 +574,9 @@ describe("admin tokens: accounts' content needs its own scopes", () => {
const withContent = (await runsOf(make(["runs:read", "outputs:view"]).token)).items.find((x) => x.id === r.id)!;
expect(withContent.prompt).toBe("a private prompt");
expect(withContent.outputs[0].url).toMatch(/^\/api\/files\//);
- expect(withContent.account.email).toBeNull();
+ expect(withContent.account).toEqual({ id: r.account.id, emailHidden: true });
const withEmail = (await runsOf(make(["runs:read", "accounts:read"]).token)).items.find((x) => x.id === r.id)!;
- expect(withEmail.account.email).toBe(r.account.email);
+ expect(withEmail.account).toEqual({ id: r.account.id, email: r.account.email });
expect(withEmail.prompt).toBeUndefined();
const owner = (await runsOf(undefined, ownerCookie)).items.find((x) => x.id === r.id)!;
expect(owner.prompt).toBe("a private prompt");