Open Administration on a dashboard of what the role can read

Administration used to open on its first section. It opens on a grid of
cards now: users, domains, messages waiting in the delivery queue, server
memory, and the last 24 hours' received and sent. Each card is there only
when the role holds what its number needs -- a count is a query, the
metric history a query and a get -- so a helpdesk role that reads accounts
and domains sees those two cards and nothing about the server.

What the cards count is whatever Stalwart answers for the signed-in
account, which scopes a tenant administrator's accounts, domains and queue
to the tenancy. The metric history has no tenant in it, and Stalwart's
Tenant Administrator role does not hold it, so a tenant's dashboard is
users, domains and pending.

The history is Enterprise-only and switched off by default. A server that
refuses it leaves those cards off; one that records nothing says so rather
than showing zeroes. Received and sent add up the queue counters Stalwart's
own dashboard uses, filtered with the comparison names the live server
accepts (a bare timestamp is unsupportedFilter). The column count follows
the number of cards so rows stay even, and falls back by the grid's own
width rather than the window's.

The server's test for whether an account is offered Administration matches
the client's again, now that a count is enough. The mock answers the queue
and an hourly history ending in the current hour; MOCK_METRICS=off refuses
the history as Community does, a tenant administrator gets the queue, and
helpdesk reads domains, as the demo's does.

ROADMAP and FEATURES said reporting and queues were out of scope; they say
the dashboard reads a handful of numbers and that managing queues, logs
and settings stays out. KNOWN-ISSUES records what was settled on the live
server and what was only read from source.

Fourteen new strings, in all nine catalogues.
This commit is contained in:
2026-09-15 08:06:59 -07:00
parent bb8d6eb92d
commit 0054b8a3ce
28 changed files with 838 additions and 37 deletions
+25 -2
View File
@@ -14,7 +14,7 @@
* for a check Stalwart does not make. See there.
*/
export type AdminObject = "Account" | "Domain" | "Role" | "MailingList" | "DkimSignature" | "DnsServer" | "Tenant";
export type AdminObject = "Account" | "Domain" | "Role" | "MailingList" | "DkimSignature" | "DnsServer" | "Tenant" | "QueuedMessage" | "Metric";
export type AdminOp = "Get" | "Query" | "Create" | "Update" | "Destroy";
export type Permissions = ReadonlySet<string>;
@@ -27,16 +27,39 @@ export function can(perms: Permissions, object: AdminObject, op: AdminOp): boole
return perms.has(`sys${object}${op}`);
}
export type AdminSection = "accounts" | "domains";
export type AdminSection = "dashboard" | "accounts" | "domains";
export type DashboardCard = "users" | "domains" | "pending" | "memory" | "received" | "sent";
/**
* The dashboard's cards an account may see.
*
* A count is a query with `calculateTotal`, so a query alone earns one. The
* three read from the metric history need the get as well, since the query
* only finds the records. Stalwart scopes the first three to a tenant
* administrator's own tenancy; the metric history has no tenant in it at all,
* and the Tenant Administrator role Stalwart creates does not hold it -- which
* is how a tenant's dashboard comes to show only what is theirs.
*/
export function dashboardCards(perms: Permissions): DashboardCard[] {
const out: DashboardCard[] = [];
if (can(perms, "Account", "Query")) out.push("users");
if (can(perms, "Domain", "Query")) out.push("domains");
if (can(perms, "QueuedMessage", "Query")) out.push("pending");
if (can(perms, "Metric", "Query") && can(perms, "Metric", "Get")) out.push("memory", "received", "sent");
return out;
}
/**
* The sections an account may open, in the order they are listed.
*
* A list that cannot be read is not worth an entry, so each takes both halves
* of reading one: the query that finds the objects and the get that shows them.
* The dashboard comes first, and is there whenever it has a card to show.
*/
export function adminSections(perms: Permissions): AdminSection[] {
const out: AdminSection[] = [];
if (dashboardCards(perms).length) out.push("dashboard");
if (can(perms, "Account", "Query") && can(perms, "Account", "Get")) out.push("accounts");
if (can(perms, "Domain", "Query") && can(perms, "Domain", "Get")) out.push("domains");
return out;