Andrey Antukh 8853445951 🎉 Add the superuser admin panel
Operators get a full instance administration panel behind a new
"superuser" access rule. The :app.auth/superusers service resolves
the configured :superusers emails to profile ids once at startup,
so guarded calls are a plain contains? with no query. A token
carrying "superuser" as an operator-granted scope also passes, for
automation without a session; tokens are created with empty perms,
so this opens nothing by itself.

The check is a branch of wrap-authentication, after auth and
before params validation, so outsiders get 403
:superuser-required without leaking expected params. Other token
scopes keep their exact meaning. get-profile and the login
response report the same answer as :is-superuser; the team-scoped
:is-admin is untouched. On devenv any authenticated profile
passes, as the /dbg gate does. The :admins config becomes
:superusers (PENPOT_SUPERUSERS) with no compatibility layer:
operators must rename it or instance-admin access fails closed.
Quote notifications go to the same set.

Admin operations live in app.rpc.admin.* behind
/api/admin/methods, with the same auth wrapping as main but
excluded from the main API docs. Profiles can be listed,
inspected, blocked, unblocked, deleted and restored, teams listed
with members and features, projects and files listed with validate
and repair, error reports listed and shared through JWE links,
and the virtual clock read and set.

Delete and restore run as durable jobs on the unified job table:
the command stamps the object's own row inline so it reads back
instantly, then a delete-object or restore-object job walks the
rest of the tree through app.features.object-cascade. Listing
uses created-at cursors over the new 0157 indexes.

The panel itself is a static SPA served under /admin (public like
any asset; the JS gate reads :is-superuser from get-profile)
with dashboard, users, teams, projects, files and error-report
pages. Devenv points /admin at the backend.

Covered by backend-tests rpc-superuser-test plus
rpc-admin-{users,teams,project,file,delete,restore,misc,
error-reports,error-share} and http-admin tests, with green
regressions on profile, auth and quotes.

Relates to #12015

AI-assisted-by: muse-spark-1.3-contributor
2026-10-21 12:59:22 +02:00

82 lines
2.4 KiB
JavaScript

// Shared status badges for the admin panel: fixed class maps with
// values painted as text, never the raw value as a class. These used
// to live in `pages/users.js`, which coupled every list (and the user
// detail) to the users page; they live here now.
const STATUS_BADGES = {
deleted: "admin-badge-status-deleted",
blocked: "admin-badge-status-blocked",
inactive: "admin-badge-status-inactive",
demo: "admin-badge-status-demo",
active: "admin-badge-status-active",
};
const DEFAULT_BADGES = {
yes: "admin-badge-status-active",
no: "admin-badge-status-inactive",
};
// Derive the badge key from a profile row.
export function statusOf(item) {
if (item.deletedAt) {
return "deleted";
}
if (item.isBlocked) {
return "blocked";
}
if (item.isDemo) {
return "demo";
}
if (!item.isActive) {
return "inactive";
}
return "active";
}
export function statusCell(status) {
const badge = document.createElement("span");
badge.className = "admin-badge " + (STATUS_BADGES[status] || STATUS_BADGES.active);
badge.textContent = status;
return badge;
}
// Yes/no badge for the team "Default" column.
export function defaultCell(value) {
const badge = document.createElement("span");
badge.className = "admin-badge " + (DEFAULT_BADGES[value] || DEFAULT_BADGES.no);
badge.textContent = value;
return badge;
}
const JOB_STATUS_BADGES = {
new: "admin-badge-status-demo",
scheduled: "admin-badge-status-demo",
retry: "admin-badge-status-demo",
running: "admin-badge-status-active",
completed: "admin-badge-status-inactive",
failed: "admin-badge-status-blocked",
cancelled: "admin-badge-status-deleted",
aborted: "admin-badge-status-deleted",
};
const JOB_KIND_BADGES = {
system: "admin-badge-source-legacy",
user: "admin-badge-source-logging",
};
// Badge for a job status or kind: fixed class maps, never the raw
// value as a class. Unknown values fall back to a neutral badge.
export function jobStatusCell(status) {
const badge = document.createElement("span");
badge.className = "admin-badge " + (JOB_STATUS_BADGES[status] || "admin-badge-status-inactive");
badge.textContent = status;
return badge;
}
export function jobKindCell(kind) {
const badge = document.createElement("span");
badge.className = "admin-badge " + (JOB_KIND_BADGES[kind] || "admin-badge-source-legacy");
badge.textContent = kind;
return badge;
}