Add Tenants to Administration, and let an account be put in one
A tenant is a separate organisation on one server: its own people, domains and limits, and an administrator who manages only what is in it. It gets a section under Access, gated by sysTenantQuery and sysTenantGet, with a notice on a server that does not report Enterprise, where anyone inside a tenant is held to an ordinary user's permissions. The panel edits the tenant's name, logo, role and limits. The logo is an https address, drawn through the image proxy the strict image policy requires, or an image data URL. Limits change one quotas/<name> pointer each, so the four ihasmail does not offer keep their values, and an empty field is no limit. The role is the most anyone inside can be allowed. Stalwart keeps no list on a tenant -- each account, group, domain, list and role names its own -- so what a tenant holds is counted with memberTenantId queries and shown against its limits. Domains are added and taken out from the tenant's panel, one memberTenantId change each; only a domain in no tenant can be added, and its accounts stay where they are. Delete is offered once every count reads zero. A tenant does nothing until someone administers it, so the account panel gains a Tenant choice for an administrator who can read tenants: an Administrator inside a tenant administers that tenant. Nobody moves their own account. The mock has a tenant holding a domain and an administrator, a spare domain to assign, memberTenantId filters on every query, and Stalwart's rule that only an administrator outside every tenant may move things into one. A test of taking a domain back out found that the mock's pointer handling dropped a top-level null instead of storing it, so nothing had ever been cleared that way; it stores null now, as the server reads it back. Nothing about tenants has been written on a live server: production has none. KNOWN-ISSUES says what was read from source. Thirty-nine new strings and one plural, in all nine catalogues.
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { client } from "@/jmap/client";
|
||||
import { countTenantMembers, drawableLogo, quotasPatch, setDomainTenant } from "@/lib/adminTenants";
|
||||
|
||||
describe("a tenant's limits", () => {
|
||||
it("change one pointer each, leaving the quotas ihasmail does not offer alone", () => {
|
||||
const before = { maxAccounts: 25, maxDomains: 2, maxOauthClients: 7 };
|
||||
expect(quotasPatch(before, { maxAccounts: 30, maxDomains: null, maxGroups: 5, maxRoles: null })).toEqual({
|
||||
"quotas/maxAccounts": 30,
|
||||
"quotas/maxDomains": null,
|
||||
"quotas/maxGroups": 5,
|
||||
});
|
||||
expect(quotasPatch(before, { maxAccounts: 25 })).toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
describe("what a tenant holds", () => {
|
||||
it("is counted with a memberTenantId filter per kind, users and groups apart", async () => {
|
||||
const call = vi.spyOn(client, "call").mockImplementation(async (method, args) => {
|
||||
const f = (args as { filter: Record<string, unknown> }).filter;
|
||||
if (method === "x:Role/query") throw new Error("forbidden");
|
||||
return { total: method === "x:Account/query" && f["@type"] === "Group" ? 2 : 1 };
|
||||
});
|
||||
expect(await countTenantMembers("t1")).toEqual({ accounts: 1, groups: 2, lists: 1, domains: 1 });
|
||||
expect(call).toHaveBeenCalledWith("x:Account/query", { filter: { "@type": "User", memberTenantId: "t1" }, limit: 0, calculateTotal: true });
|
||||
expect(call).toHaveBeenCalledWith("x:Domain/query", { filter: { memberTenantId: "t1" }, limit: 0, calculateTotal: true });
|
||||
call.mockRestore();
|
||||
});
|
||||
|
||||
it("moves a domain in and out by its memberTenantId", async () => {
|
||||
const call = vi.spyOn(client, "call").mockResolvedValue({ updated: { d4: null } });
|
||||
await setDomainTenant("d4", "t1");
|
||||
expect(call).toHaveBeenLastCalledWith("x:Domain/set", { update: { d4: { memberTenantId: "t1" } } });
|
||||
await setDomainTenant("d4", null);
|
||||
expect(call).toHaveBeenLastCalledWith("x:Domain/set", { update: { d4: { memberTenantId: null } } });
|
||||
call.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
describe("a tenant's logo", () => {
|
||||
it("is drawn only from https or an image data URL", () => {
|
||||
expect(drawableLogo("https://example.com/logo.png")).toBe("https://example.com/logo.png");
|
||||
expect(drawableLogo("data:image/png;base64,AAAA")).toBe("data:image/png;base64,AAAA");
|
||||
expect(drawableLogo("http://example.com/logo.png")).toBeNull();
|
||||
expect(drawableLogo("javascript:alert(1)")).toBeNull();
|
||||
expect(drawableLogo("data:text/html;base64,AAAA")).toBeNull();
|
||||
expect(drawableLogo(null)).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user