Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Normalize portal account role labels

rcourtmanc0ea4ecb43c7
diff --git a/docs/release-control/v6/internal/PULSE_ACCOUNT_PORTAL_SPEC.md b/docs/release-control/v6/internal/PULSE_ACCOUNT_PORTAL_SPEC.md
index 65bdac3c3d..f0841cd85e 100644
--- a/docs/release-control/v6/internal/PULSE_ACCOUNT_PORTAL_SPEC.md
+++ b/docs/release-control/v6/internal/PULSE_ACCOUNT_PORTAL_SPEC.md
@@ -232,6 +232,10 @@ Core rules:
Hosted-only accounts may not mention self-hosted billing utilities by
default, and hosted view-only roles must say when owner/admin authority is
still required to open hosted billing.
+33. User-facing role labels must stay on product vocabulary. The portal may
+ describe account role as `Owner`, `Admin`, `Tech`, or `Read-only`, but it
+ must not leak internal identifiers such as `read_only` or legacy aliases
+ such as `member`.
## Screen Model
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 9fc3f2e220..64d8c01c28 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -325,6 +325,10 @@ billing still needs owner/admin authority.
The same permission contract must also drive the compact account-context
summary: the strip may not describe full hosted access-control or billing
ownership when the current role can only review workspaces or roster state.
+That same typed runtime contract must also normalize account-role labels before
+render: customer-facing copy may say `Owner`, `Admin`, `Tech`, or `Read-only`,
+but it must not surface raw runtime identifiers such as `read_only` or legacy
+aliases such as `member`.
plus a package-local `tsc --noEmit` gate, so future account-shell work should
extend the typed source boundary instead of reviving opaque global runtime
objects, document-wide render events, or untyped embedded asset edits.
diff --git a/docs/release-control/v6/internal/subsystems/cloud-paid.md b/docs/release-control/v6/internal/subsystems/cloud-paid.md
index 3f7e802d41..393d09ee79 100644
--- a/docs/release-control/v6/internal/subsystems/cloud-paid.md
+++ b/docs/release-control/v6/internal/subsystems/cloud-paid.md
@@ -886,6 +886,10 @@ authority.
The same rule applies to the compact account-context strip: it must describe
the current user's effective hosted tasks, not restate full access-control and
billing capability when those actions are blocked behind owner/admin roles.
+That same owned shell must also keep role labels on product vocabulary:
+customer-facing copy may say `Owner`, `Admin`, `Tech`, or `Read-only`, but it
+must not leak internal identifiers such as `read_only` or legacy aliases such
+as `member`.
That same canonical shell/runtime boundary now also owns the bootstrap truth
for when self-hosted commercial history is relevant. Hosted-only accounts must
not render self-hosted license, refund, privacy, or support-escalation copy
diff --git a/internal/cloudcp/portal/dist/build_manifest.json b/internal/cloudcp/portal/dist/build_manifest.json
index c6b3fa4ba8..893651c46e 100644
--- a/internal/cloudcp/portal/dist/build_manifest.json
+++ b/internal/cloudcp/portal/dist/build_manifest.json
@@ -1,11 +1,13 @@
{
- "source_hash": "3a3ac320be4e6c5b7c49ae85a4da68ed536911a14ee62d93989c8dd1dbe5690e",
+ "source_hash": "28526fdef0c6ead9b953af6bdd043b5d3666234e37a54c60ae51ad5632805e36",
"build_inputs": [
"package.json",
"tsconfig.json",
"build.mjs",
"src/account_controller.test.ts",
"src/account_controller.ts",
+ "src/account_roles.test.ts",
+ "src/account_roles.ts",
"src/account_runtime.test.ts",
"src/account_runtime.ts",
"src/account_view.test.ts",
diff --git a/internal/cloudcp/portal/dist/portal_app.js b/internal/cloudcp/portal/dist/portal_app.js
index 0e25c87c56..c3967badd0 100644
--- a/internal/cloudcp/portal/dist/portal_app.js
+++ b/internal/cloudcp/portal/dist/portal_app.js
@@ -1,11 +1,11 @@
(() => {
- // src/account_view.ts
- function normalizedAccessRole(role) {
+ // src/account_roles.ts
+ function normalizePortalRole(role) {
if (role === "member") return "read_only";
return role || "read_only";
}
- function roleLabel(role) {
- switch (normalizedAccessRole(role)) {
+ function portalRoleLabel(role) {
+ switch (normalizePortalRole(role)) {
case "owner":
return "Owner";
case "admin":
@@ -20,8 +20,8 @@
return role || "Member";
}
}
- function roleCapabilityCopy(role) {
- switch (normalizedAccessRole(role)) {
+ function portalRoleCapabilityCopy(role) {
+ switch (normalizePortalRole(role)) {
case "owner":
return "Full account control, including billing, access control, and workspace control.";
case "admin":
@@ -36,6 +36,8 @@
return "Has access through the account roster.";
}
}
+
+ // src/account_view.ts
function getElement(id) {
return document.getElementById(id);
}
@@ -176,7 +178,7 @@
function countMembersByRole(members, role) {
var count = 0;
for (var i = 0; i < members.length; i += 1) {
- if (normalizedAccessRole(members[i].role) === role) count += 1;
+ if (normalizePortalRole(members[i].role) === role) count += 1;
}
return count;
}
@@ -228,19 +230,19 @@
return cell;
}
function renderAccessRoleControl(accountID, member, isOwner, canManage, activeJob) {
- var currentRole = normalizedAccessRole(member.role);
+ var currentRole = normalizePortalRole(member.role);
var group = createAccessControlCell("access-control-cell-role");
if (!canManage || activeJob !== "change_role") {
var badge = document.createElement("span");
badge.className = "access-role-badge";
- badge.textContent = roleLabel(currentRole);
+ badge.textContent = portalRoleLabel(currentRole);
group.appendChild(badge);
return group;
}
if (currentRole === "owner" && !isOwner) {
var locked = document.createElement("span");
locked.className = "access-role-badge";
- locked.textContent = roleLabel(currentRole);
+ locked.textContent = portalRoleLabel(currentRole);
group.appendChild(locked);
return group;
}
@@ -250,7 +252,7 @@
for (var j = 0; j < roles.length; j += 1) {
var opt = document.createElement("option");
opt.value = roles[j];
- opt.textContent = roleLabel(roles[j]);
+ opt.textContent = portalRoleLabel(roles[j]);
if (currentRole === roles[j]) opt.selected = true;
sel.appendChild(opt);
}
@@ -272,7 +274,7 @@
group.appendChild(idleText);
return group;
}
- if (normalizedAccessRole(member.role) === "owner" && !isOwner) {
+ if (normalizePortalRole(member.role) === "owner" && !isOwner) {
var lockedText = document.createElement("span");
lockedText.className = "access-control-locked";
lockedText.textContent = "Locked";
@@ -303,12 +305,12 @@
topline.appendChild(email);
var roleBadge = document.createElement("span");
roleBadge.className = "access-inline-role-badge";
- roleBadge.textContent = roleLabel(member.role);
+ roleBadge.textContent = portalRoleLabel(member.role);
topline.appendChild(roleBadge);
identity.appendChild(topline);
var caption = document.createElement("div");
caption.className = "access-member-caption";
- caption.textContent = roleCapabilityCopy(member.role);
+ caption.textContent = portalRoleCapabilityCopy(member.role);
identity.appendChild(caption);
row.appendChild(identity);
row.appendChild(renderAccessRoleControl(accountID, member, isOwner, canManage, activeJob));
@@ -2027,7 +2029,7 @@
return results;
}
function accountContextRoleMeta(account) {
- return titleCase(account.role) + (account.can_manage ? " access" : " role");
+ return portalRoleLabel(account.role) + (account.can_manage ? " access" : " role");
}
function accountContextLeadCopy(account) {
var accountPrefix = account.kind === "msp" ? "Hosted workspace account" : "Hosted account";
@@ -2037,7 +2039,7 @@
return accountPrefix + (account.has_billing ? " where you can open workspaces and review who already has access. An owner or admin handles access changes and billing." : " where you can open workspaces and review who already has access. An owner or admin handles account changes.");
}
function accountContextAccessSummary(account) {
- return account.can_manage ? titleCase(account.role) : "View only";
+ return account.can_manage ? portalRoleLabel(account.role) : "View only";
}
function accountContextBillingSummary(account) {
if (!account.has_billing) return "Not attached";
@@ -2046,7 +2048,7 @@
function renderAccountContextStrip(account) {
var workspaceLabel = workspaceCountLabel((account.workspaces || []).length);
var billingLabel = accountContextBillingSummary(account);
- return '<section class="portal-account-context"><div class="portal-account-context-copy"><div class="portal-account-context-meta"><span class="account-eyebrow">' + escapeHTML(accountKindLabel(account)) + '</span><span class="portal-account-context-separator">/</span><span class="portal-account-context-access">' + escapeHTML(accountContextRoleMeta(account)) + '</span></div><div class="portal-account-context-row"><h2>' + escapeHTML(account.name) + '</h2><div class="portal-account-context-chips"><span class="account-context-chip">' + escapeHTML(account.kind_label) + '</span><span class="account-context-chip">' + escapeHTML(titleCase(account.role)) + '</span><span class="account-context-chip">' + escapeHTML(workspaceLabel) + "</span></div></div><p>" + escapeHTML(accountContextLeadCopy(account)) + '</p></div><div class="portal-account-context-summary"><div class="portal-account-context-stat"><span>Access</span><strong>' + escapeHTML(accountContextAccessSummary(account)) + '</strong></div><div class="portal-account-context-stat"><span>Workspaces</span><strong>' + escapeHTML(workspaceLabel) + '</strong></div><div class="portal-account-context-stat"><span>Billing</span><strong>' + escapeHTML(billingLabel) + "</strong></div></div></section>";
+ return '<section class="portal-account-context"><div class="portal-account-context-copy"><div class="portal-account-context-meta"><span class="account-eyebrow">' + escapeHTML(accountKindLabel(account)) + '</span><span class="portal-account-context-separator">/</span><span class="portal-account-context-access">' + escapeHTML(accountContextRoleMeta(account)) + '</span></div><div class="portal-account-context-row"><h2>' + escapeHTML(account.name) + '</h2><div class="portal-account-context-chips"><span class="account-context-chip">' + escapeHTML(account.kind_label) + '</span><span class="account-context-chip">' + escapeHTML(portalRoleLabel(account.role)) + '</span><span class="account-context-chip">' + escapeHTML(workspaceLabel) + "</span></div></div><p>" + escapeHTML(accountContextLeadCopy(account)) + '</p></div><div class="portal-account-context-summary"><div class="portal-account-context-stat"><span>Access</span><strong>' + escapeHTML(accountContextAccessSummary(account)) + '</strong></div><div class="portal-account-context-stat"><span>Workspaces</span><strong>' + escapeHTML(workspaceLabel) + '</strong></div><div class="portal-account-context-stat"><span>Billing</span><strong>' + escapeHTML(billingLabel) + "</strong></div></div></section>";
}
function shellSectionButton(section, activeSection, index, title, copy, badge) {
var badgeHTML = badge ? '<span class="portal-shell-nav-badge">' + escapeHTML(badge) + "</span>" : "";
diff --git a/internal/cloudcp/portal/frontend/src/account_roles.test.ts b/internal/cloudcp/portal/frontend/src/account_roles.test.ts
new file mode 100644
index 0000000000..1ca3336dfd
--- /dev/null
+++ b/internal/cloudcp/portal/frontend/src/account_roles.test.ts
@@ -0,0 +1,16 @@
+import { describe, expect, it } from 'vitest';
+
+import { normalizePortalRole, portalRoleCapabilityCopy, portalRoleLabel } from './account_roles';
+
+describe('account roles', function() {
+ it('normalizes internal and legacy read-only roles into product labels', function() {
+ expect(normalizePortalRole('member')).toBe('read_only');
+ expect(normalizePortalRole('read_only')).toBe('read_only');
+ expect(portalRoleLabel('member')).toBe('Read-only');
+ expect(portalRoleLabel('read_only')).toBe('Read-only');
+ });
+
+ it('returns product copy for read-only operators', function() {
+ expect(portalRoleCapabilityCopy('read_only')).toContain('review workspace status');
+ });
+});
diff --git a/internal/cloudcp/portal/frontend/src/account_roles.ts b/internal/cloudcp/portal/frontend/src/account_roles.ts
new file mode 100644
index 0000000000..4caa9d5141
--- /dev/null
+++ b/internal/cloudcp/portal/frontend/src/account_roles.ts
@@ -0,0 +1,38 @@
+export function normalizePortalRole(role: string): string {
+ if (role === 'member') return 'read_only';
+ return role || 'read_only';
+}
+
+export function portalRoleLabel(role: string): string {
+ switch (normalizePortalRole(role)) {
+ case 'owner':
+ return 'Owner';
+ case 'admin':
+ return 'Admin';
+ case 'tech':
+ return 'Tech';
+ case 'read_only':
+ return 'Read-only';
+ case 'member':
+ return 'Member';
+ default:
+ return role || 'Member';
+ }
+}
+
+export function portalRoleCapabilityCopy(role: string): string {
+ switch (normalizePortalRole(role)) {
+ case 'owner':
+ return 'Full account control, including billing, access control, and workspace control.';
+ case 'admin':
+ return 'Can manage workspaces and billing for this account.';
+ case 'tech':
+ return 'Can manage workspaces without billing ownership.';
+ case 'read_only':
+ return 'Can review workspace status without making control-plane changes.';
+ case 'member':
+ return 'Has access through the account roster.';
+ default:
+ return 'Has access through the account roster.';
+ }
+}
diff --git a/internal/cloudcp/portal/frontend/src/account_view.ts b/internal/cloudcp/portal/frontend/src/account_view.ts
index c784afdf80..f4ad613499 100644
--- a/internal/cloudcp/portal/frontend/src/account_view.ts
+++ b/internal/cloudcp/portal/frontend/src/account_view.ts
@@ -6,48 +6,10 @@ import type {
PortalAccessMember,
PortalWorkspaceSummary,
} from './types';
+import { normalizePortalRole, portalRoleCapabilityCopy, portalRoleLabel } from './account_roles';
type FormValueElement = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;
-function normalizedAccessRole(role: string): string {
- if (role === 'member') return 'read_only';
- return role || 'read_only';
-}
-
-function roleLabel(role: string): string {
- switch (normalizedAccessRole(role)) {
- case 'owner':
- return 'Owner';
- case 'admin':
- return 'Admin';
- case 'tech':
- return 'Tech';
- case 'read_only':
- return 'Read-only';
- case 'member':
- return 'Member';
- default:
- return role || 'Member';
- }
-}
-
-function roleCapabilityCopy(role: string): string {
- switch (normalizedAccessRole(role)) {
- case 'owner':
- return 'Full account control, including billing, access control, and workspace control.';
- case 'admin':
- return 'Can manage workspaces and billing for this account.';
- case 'tech':
- return 'Can manage workspaces without billing ownership.';
- case 'read_only':
- return 'Can review workspace status without making control-plane changes.';
- case 'member':
- return 'Has access through the account roster.';
- default:
- return 'Has access through the account roster.';
- }
-}
-
export function getElement<T extends HTMLElement = HTMLElement>(id: string): T | null {
return document.getElementById(id) as T | null;
}
@@ -203,7 +165,7 @@ function setContainerMessage(container: HTMLElement, title: string, msg: string,
function countMembersByRole(members: PortalAccessMember[], role: string): number {
var count = 0;
for (var i = 0; i < members.length; i += 1) {
- if (normalizedAccessRole(members[i].role) === role) count += 1;
+ if (normalizePortalRole(members[i].role) === role) count += 1;
}
return count;
}
@@ -269,19 +231,19 @@ function createAccessControlCell(className: string): HTMLDivElement {
}
function renderAccessRoleControl(accountID: string, member: PortalAccessMember, isOwner: boolean, canManage: boolean, activeJob: PortalAccessJob): HTMLElement {
- var currentRole = normalizedAccessRole(member.role);
+ var currentRole = normalizePortalRole(member.role);
var group = createAccessControlCell('access-control-cell-role');
if (!canManage || activeJob !== 'change_role') {
var badge = document.createElement('span');
badge.className = 'access-role-badge';
- badge.textContent = roleLabel(currentRole);
+ badge.textContent = portalRoleLabel(currentRole);
group.appendChild(badge);
return group;
}
if (currentRole === 'owner' && !isOwner) {
var locked = document.createElement('span');
locked.className = 'access-role-badge';
- locked.textContent = roleLabel(currentRole);
+ locked.textContent = portalRoleLabel(currentRole);
group.appendChild(locked);
return group;
}
@@ -292,7 +254,7 @@ function renderAccessRoleControl(accountID: string, member: PortalAccessMember,
for (var j = 0; j < roles.length; j += 1) {
var opt = document.createElement('option');
opt.value = roles[j];
- opt.textContent = roleLabel(roles[j]);
+ opt.textContent = portalRoleLabel(roles[j]);
if (currentRole === roles[j]) opt.selected = true;
sel.appendChild(opt);
}
@@ -315,7 +277,7 @@ function renderAccessMemberAction(accountID: string, member: PortalAccessMember,
group.appendChild(idleText);
return group;
}
- if (normalizedAccessRole(member.role) === 'owner' && !isOwner) {
+ if (normalizePortalRole(member.role) === 'owner' && !isOwner) {
var lockedText = document.createElement('span');
lockedText.className = 'access-control-locked';
lockedText.textContent = 'Locked';
@@ -352,14 +314,14 @@ function renderAccessMemberRow(accountID: string, member: PortalAccessMember, is
var roleBadge = document.createElement('span');
roleBadge.className = 'access-inline-role-badge';
- roleBadge.textContent = roleLabel(member.role);
+ roleBadge.textContent = portalRoleLabel(member.role);
topline.appendChild(roleBadge);
identity.appendChild(topline);
var caption = document.createElement('div');
caption.className = 'access-member-caption';
- caption.textContent = roleCapabilityCopy(member.role);
+ caption.textContent = portalRoleCapabilityCopy(member.role);
identity.appendChild(caption);
row.appendChild(identity);
diff --git a/internal/cloudcp/portal/frontend/src/shell_view.test.ts b/internal/cloudcp/portal/frontend/src/shell_view.test.ts
index 7f0bf6d324..bbc0b2e309 100644
--- a/internal/cloudcp/portal/frontend/src/shell_view.test.ts
+++ b/internal/cloudcp/portal/frontend/src/shell_view.test.ts
@@ -417,6 +417,40 @@ describe('shell view', function() {
expect(html).not.toContain('Workspace or access path failed');
});
+ it('renders read-only account roles without leaking internal identifiers', function() {
+ var html = renderAuthenticatedPortalHTML(
+ createContext({
+ bootstrap: createBootstrap({
+ accounts: [
+ {
+ id: 'acct_view',
+ name: 'Viewer Account',
+ kind: 'cloud',
+ kind_label: 'Cloud',
+ role: 'read_only',
+ can_manage: false,
+ has_billing: true,
+ workspaces: [
+ {
+ id: 'ws_view',
+ display_name: 'Viewer Workspace',
+ state: 'active',
+ healthy: true,
+ health_status: 'healthy',
+ },
+ ],
+ },
+ ],
+ }),
+ })
+ );
+
+ expect(html).toContain('Read-only role');
+ expect(html).toContain('Read-only');
+ expect(html).not.toContain('Read_only role');
+ expect(html).not.toContain('READ_ONLY');
+ });
+
it('renders self-hosted overview copy when no hosted accounts are attached', function() {
var html = renderAuthenticatedPortalHTML(
createContext({
diff --git a/internal/cloudcp/portal/frontend/src/shell_view.ts b/internal/cloudcp/portal/frontend/src/shell_view.ts
index 56154e3f04..5424b2b2d1 100644
--- a/internal/cloudcp/portal/frontend/src/shell_view.ts
+++ b/internal/cloudcp/portal/frontend/src/shell_view.ts
@@ -5,6 +5,7 @@ import type {
PortalShellSection,
PortalWorkspaceSummary,
} from './types';
+import { portalRoleLabel } from './account_roles';
export interface ShellViewContext {
bootstrap: PortalBootstrapData;
@@ -301,7 +302,7 @@ function renderOverviewMetricStrip(
}
function accountContextRoleMeta(account: PortalAccountSummary): string {
- return titleCase(account.role) + (account.can_manage ? ' access' : ' role');
+ return portalRoleLabel(account.role) + (account.can_manage ? ' access' : ' role');
}
function accountContextLeadCopy(account: PortalAccountSummary): string {
@@ -317,7 +318,7 @@ function accountContextLeadCopy(account: PortalAccountSummary): string {
}
function accountContextAccessSummary(account: PortalAccountSummary): string {
- return account.can_manage ? titleCase(account.role) : 'View only';
+ return account.can_manage ? portalRoleLabel(account.role) : 'View only';
}
function accountContextBillingSummary(account: PortalAccountSummary): string {
@@ -341,7 +342,7 @@ function renderAccountContextStrip(account: PortalAccountSummary): string {
'<h2>' + escapeHTML(account.name) + '</h2>' +
'<div class="portal-account-context-chips">' +
'<span class="account-context-chip">' + escapeHTML(account.kind_label) + '</span>' +
- '<span class="account-context-chip">' + escapeHTML(titleCase(account.role)) + '</span>' +
+ '<span class="account-context-chip">' + escapeHTML(portalRoleLabel(account.role)) + '</span>' +
'<span class="account-context-chip">' + escapeHTML(workspaceLabel) + '</span>' +
'</div>' +
'</div>' +