Skip to content

feat(admin): show which users shared which models - #457

Merged
argszero merged 1 commit into
mainfrom
feat/admin-sharing-visibility
Dec 3, 2026
Merged

argszero merged 1 commit into
mainfrom
feat/admin-sharing-visibility

Conversation

@argszero

@argszero argszero commented Dec 3, 2026

Copy link
Copy Markdown
Owner

What this does

Admins had no single place to answer "who is sharing models, and which models do they share?". The sharing list shows raw key rows, so the answer had to be assembled by eye.

This adds an admin-only GET /api/admin/sharings and a fifth Sharing overview tab to the admin view.

Host request, translated from Chinese:

An administrator should be able to see conveniently which users have shared models, and which models they shared. Design it well.

Design discussion: #456. Closes #456.

API

GET /api/admin/sharings — admin only, 403 for everyone else, same guard and same response style as GET /api/admin/usage.

The two questions are each other's inverse, so one pass over the data answers both:

  • users[] — aggregated per sharer: user_id, email, name, dept_name, keys{on,paused,off}, keys_live, quota, used, last_created_at, and models[] (each provider, model, keys{on,paused,off}, keys_live).
  • models[] — aggregated per (provider, model): the same keys/keys_live/quota/used, plus sharers (a count of people) and owners[] (user_id, email, name).
  • totals — users, models, keys{on,paused,off}, keys_live.

Data source is the existing keys table (one row = one listing), with the sharer taken as keys.owner_id → users.id.

A row with status = 'off' is a listing taken down: it leaves both rosters, because it serves no traffic, but it is still counted in keys.off, so nothing is hidden — only no longer called "sharing right now".

No key material is selected at all: encrypted_key never enters the query, so the response cannot carry a plaintext, masked or encrypted key.

UI

  • Fifth admin tab Sharing overview (共享概览), beside Members / Usage / Organization / Models.
  • Stat cards, a per-member table, a per-model table, a search box over both, empty and error states, ZH + EN copy.
  • Both tables are registered in the table gate; the search box is registered in the query-state gate so it is cleared at the identity boundary.
  • Cache tokens bumped in ui/index.html for i18n.js and app.js.

Gates

Measured on this branch:

  • cargo test — 617 passed, 0 failed, including the new routes::tests::admin_sharings_lists_who_shared_what, which asserts four things at once: 403 for a non-admin; members appear once each with only their own models; two members sharing one model give sharers: 2 not two listings; a status='off' row leaves both rosters while totals.keys.off still counts it; and no key value of any kind appears in the body.
  • cargo clippy --all-targets -- -D warnings — clean.
  • cargo fmt --check — clean.
  • Roster constants re-derived in the same pass: table_gate 7 → 8 tables, state_gate gains #sharing-search, and the six i18n constants in i18n_pack.rs move to their new values.

Not in this change

No schema change: the aggregate reads columns that already exist, and SCHEMA_VERSION stays 18. No index on keys.owner_id either — the keys table is a listing table (a member's listings are single-digit), so a full scan is cheaper than an index that would move SCHEMA_VERSION.

Admins had no single place to see who is sharing models and which models
each member shares: the sharing list exposed the raw key rows, so the
answer had to be assembled by eye from a flat table.

Add an admin-only GET /api/admin/sharings that aggregates the keys table
by member and by model — quota, used, live/paused/off key counts, the
last creation time, and the models each member shares — and add a fifth
"Sharing overview" tab to the admin view rendering it with stat cards, a
per-member table, a per-model table and a search box.

No schema change: the aggregate reads columns that already exist, and the
keys table is small enough that a full scan is the right plan.

Closes #456
@argszero
argszero merged commit bb6461b into main Dec 3, 2026
2 checks passed
@argszero argszero mentioned this pull request Dec 3, 2026
argszero added a commit that referenced this pull request Dec 3, 2026
Cut v0.7.37 over the one commit since v0.7.36: the admin sharing
overview (#457), which adds an admin-only GET /api/admin/sharings and a
fifth "Sharing overview" tab in the admin view.

Version string moved 0.7.36 -> 0.7.37 in the five carriers (8 places)
and a matching CHANGELOG section. No schema change: SCHEMA_VERSION
stays 18.

cargo test 617/0 (616 at v0.7.36); fmt and clippy clean.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Admin view: see which members share which models

1 participant