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.

fix(workloads): stop offering viewers an infrastructure page they cannot open

rcourtman27b4d98bc052
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index c5a70d7a33..ada4f93ff3 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -2246,7 +2246,20 @@ default` instead of fusing provider and badge text such as
inventory must use a distinct no-inventory presentation that points
operators at credentials, permissions, and collection status in the
canonical infrastructure workspace instead of reusing first-run onboarding
- copy.
+ copy. That handoff is conditional on the session being able to open the
+ workspace: the no-inventory presentation takes the session's
+ `infrastructureRead` capability as a parameter, and a session without it
+ must render neither the `/settings/infrastructure` action nor copy naming
+ that page, directing the operator to an administrator instead. The gate
+ reads the destination's own capability — the same one
+ `settingsNavCatalog` requires for the Infrastructure nav item — so the
+ offer and the nav gate cannot drift apart, and the variant stays a
+ parameter of the shared presentation owner rather than a branch at any
+ call site, including the surface's own inline fallback. Sessions whose
+ capabilities have not resolved keep the action, so an administrator never
+ flickers through the restricted copy. Inventory-source health itself stays
+ visible to every session that can read monitoring data; only the
+ Settings handoff is gated.
18. Keep cross-surface investigation handoffs on shared route ownership.
Feature shells such as Alerts and Patrol may decide which governed
destination chips to render, but canonical href, label, dedupe, and
diff --git a/docs/release-control/v6/internal/subsystems/performance-and-scalability.md b/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
index 0e2b611e0d..2b226ef029 100644
--- a/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
+++ b/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
@@ -2255,6 +2255,28 @@ most one tenant-local system-settings read; it must not scan tenants, read
external logo files, call a licensing network service, or add per-route and
per-component refetches. The response remains bounded to an enabled flag, one
120-character display name, and the already size-limited inline image.
+
+### Workloads empty-state capability gating adds no request
+
+The workloads no-inventory empty state gates its Settings handoff on the
+session's `infrastructureRead` capability. That capability must be read from
+the already-published session store in
+`frontend-modern/src/stores/sessionSettingsCapabilities.ts`, which is filled by
+the single `/api/security/status` resolve `useAppRuntimeState.ts` already
+performs on mount — the same response that feeds the session presentation
+policy and session capabilities. The gate must not add a fetch of its own, must
+not poll, and must not be resolved by mounting Settings or by calling
+`/api/security/status` a second time from a workload surface.
+
+Cost on the hot path stays a signal read inside the existing
+`workloadsNoInventoryState` memo in `useWorkloadsState.ts`: no extra query, no
+per-row work, and no additional pass over the workload set. The memo already
+recomputes only when its inputs change, so a session whose capabilities never
+change re-renders the empty state no more often than before. `WorkloadsSurface`
+resolves the same value through the shared presentation helper rather than a
+local literal, so the gate costs one accessor call on the empty-state path and
+nothing at all when workload rows are present.
+
### Per-tenant resource stores are released on offboarding and shutdown
`ResourceHandlers.getStore` opens a SQLite handle per org and caches it for the
diff --git a/frontend-modern/browser-verification.json b/frontend-modern/browser-verification.json
index e092dc910f..208c925e43 100644
--- a/frontend-modern/browser-verification.json
+++ b/frontend-modern/browser-verification.json
@@ -1,46 +1,47 @@
{
"version": 1,
+ "base_sha": "6a958761e84b64dca7052caad855144e57880690",
+ "verified_at": "2026-08-07T21:53:52Z",
"result": "passed",
- "base_sha": "14a82e7684390c9fe0a4bd900417c4adbb7140b8",
- "verified_at": "2026-08-07T20:36:11Z",
"changed_paths": [
- "frontend-modern/src/components/Settings/settingsNavCatalog.ts",
- "frontend-modern/src/types/config.ts"
+ "frontend-modern/src/components/Workloads/WorkloadsSurface.tsx",
+ "frontend-modern/src/components/Workloads/useWorkloadsState.ts",
+ "frontend-modern/src/stores/sessionPresentationPolicy.ts",
+ "frontend-modern/src/stores/sessionSettingsCapabilities.ts",
+ "frontend-modern/src/utils/workloadEmptyStatePresentation.ts"
],
"content_sha256": {
- "frontend-modern/src/components/Settings/settingsNavCatalog.ts": "4bc892c16a978f7a162828f1221acbfea4ec56ee8ddc4d5993536469c86f7252",
- "frontend-modern/src/types/config.ts": "f7fc76d882f2c6fbd00d75860434ab4a8fd5369d031b9e24a18d76f42b607c72"
+ "frontend-modern/src/components/Workloads/WorkloadsSurface.tsx": "b30c1f982a67303aa54381bb868f89bb8bfb37d745518a05aa8f1aa5c84a1258",
+ "frontend-modern/src/components/Workloads/useWorkloadsState.ts": "8fad9ab73ca735495fd3a5b9e7e75d33c1da86bd200d753e2c2f885cb4b7ae8c",
+ "frontend-modern/src/stores/sessionPresentationPolicy.ts": "56bf6f99d519f4373d6329bd4a9f066ec2b6b9d64378fd1a85b2c04b3eb7eac5",
+ "frontend-modern/src/stores/sessionSettingsCapabilities.ts": "d54cb07dd8458b88ce2e90b6c94f8548620f091065a093050a148d5862f34ec2",
+ "frontend-modern/src/utils/workloadEmptyStatePresentation.ts": "704e32f24a8f9e24020288d9b9e80674d3ca90e36f38f32dd52ae4eb7740ab1b"
},
"routes": [
- "/settings/system-general",
- "/settings/system-network"
- ],
- "states": [
- "verified against real admin and non-admin sessions rather than a stubbed capability: one binary built from this worktree on :8920 with PROXY_AUTH_SECRET / PROXY_AUTH_USER_HEADER / PROXY_AUTH_ROLE_HEADER / PROXY_AUTH_ADMIN_ROLE, fronted by two header-injecting reverse proxies differing only in the role header (:8921 admin-user/admin, :8922 viewer-user/viewer)",
- "the served payload confirms the new field tracks the gate: :8921 reports detailLevel=privileged with infrastructureRead=true and systemSettingsRead=true; :8922 reports detailLevel=authenticated with both false",
- "non-admin cold load of /settings/system-general: Network, Pulse server updates, and Recovery are all absent from the settings navigation while General remains, so user-scoped theme, language, and unit preferences stay reachable",
- "non-admin cold load deep-linked at /settings/system-network: the route is refused and the session lands on /settings/monitoring/availability, the first tab it can actually reach - this composes with the capability-aware fallback added in 755a88878 rather than bouncing back to the blocked default",
- "admin cold load deep-linked at /settings/system-network: the route resolves, the Network panel renders, and all three tabs are present, so the gate does not withhold from an entitled session",
- "no stuck loading state in any of the above; this change gates nav visibility only and adds no fetch",
- "rebased onto 14a82e768 after verification; that intervening commit moves API refusal logging from warn to debug and changes no route, payload, or frontend source, and the two verified frontend files are byte-identical across the rebase (content_sha256 unchanged), so the recorded exercise still describes this commit"
- ],
- "interactions": [
- "built the frontend into the embed dir and rebuilt ./cmd/pulse so the served capability and the rendering frontend are the same artifact",
- "curled /api/security/status through both proxies to establish the admin/non-admin A/B before touching the browser, reading infrastructureRead and systemSettingsRead side by side",
- "cold-loaded /settings/system-general as viewer-user at 1280x720 and enumerated every settings nav control by DOM text, so items below the sidebar fold were counted",
- "cold-loaded /settings/system-network as viewer-user and recorded the route the app settled on",
- "cold-loaded /settings/system-network as admin-user and confirmed the panel renders with all three tabs present",
- "repeated the non-admin /settings/system-general load at 375x812 and confirmed the same three tabs absent with General retained",
- "screenshotted the non-admin System > General panel at 375x812"
+ "/proxmox"
],
"viewports": [
{
"width": 1280,
- "height": 720
+ "height": 800
},
{
"width": 375,
"height": 812
}
+ ],
+ "states": [
+ "Workloads 'No workload inventory available' empty state as a real proxy-auth VIEWER session (detailLevel 'authenticated', proxyAuthIsAdmin false, settingsCapabilities.infrastructureRead false, /api/connections 403): description reads 'Contact a Pulse administrator to check source credentials, permissions, and collection status', no 'Review infrastructure sources' button, and querying the DOM for a[href*=\"/settings\"] returned zero nodes.",
+ "Same viewer state: the inventory source-issues banner is unchanged and still present (data-testid workload-inventory-source-issues) — 'Source unreachable: lab-pve / Pulse has VMs and containers enabled for lab-pve, but the Proxmox VE API is unreachable.' with the 'VMs and containers' coverage chip.",
+ "Same route as a real proxy-auth ADMIN session (detailLevel 'privileged', infrastructureRead true) on the same backend: admin behaviour unchanged — original 'Review source credentials, permissions, and collection status in Settings → Infrastructure.' copy plus the 'Review infrastructure sources' button linking to /settings/infrastructure.",
+ "Viewer at 375x812 after reload: same suppressed-CTA copy, banner intact, documentElement.scrollWidth did not exceed the viewport (no horizontal overflow).",
+ "Console at both viewports carried only pre-existing non-admin noise (ws upgrade unsupported by the test proxy; 403s from admin-gated system-settings and update-check polling that other branches address) — no error introduced by this change."
+ ],
+ "interactions": [
+ "Seeded an unreachable Proxmox VE source (host 192.0.2.77, RFC 5737 TEST-NET-1) via POST /api/config/nodes as the admin identity, then polled GET /api/runtime/inventory-sources as the viewer until it reported a blocking state, producing the inventory-issue empty state with zero guests.",
+ "Loaded /proxmox as the viewer at 1280x800 and inspected the rendered empty state, its links, and the source-issues banner via DOM query.",
+ "Resized to 375x812, reloaded /proxmox (the workload table stages width at mount), and re-inspected the same elements.",
+ "Loaded /proxmox as the admin identity at desktop width on the same backend as the A/B control and confirmed the CTA and original copy still render.",
+ "Read console errors for both sessions."
]
}
diff --git a/frontend-modern/src/components/Workloads/WorkloadsSurface.tsx b/frontend-modern/src/components/Workloads/WorkloadsSurface.tsx
index d05c2b6a1a..a9575f874b 100644
--- a/frontend-modern/src/components/Workloads/WorkloadsSurface.tsx
+++ b/frontend-modern/src/components/Workloads/WorkloadsSurface.tsx
@@ -4,6 +4,8 @@ import { buildInfrastructureWorkspacePath } from '@/components/Settings/infrastr
import { EmptyState } from '@/components/shared/EmptyState';
import { ButtonLink } from '@/components/shared/Button';
import { TableCard } from '@/components/shared/TableCard';
+import { sessionCanReadInfrastructureSettings } from '@/stores/sessionSettingsCapabilities';
+import { getWorkloadsNoInventoryState } from '@/utils/workloadEmptyStatePresentation';
import { WorkloadsFilter } from './WorkloadsFilter';
import { DEFAULT_WORKLOADS_VIEW_MODE, hasActiveWorkloadsFilters } from './workloadsFilterModel';
import { WorkloadsTable } from './WorkloadsTable';
@@ -91,13 +93,11 @@ export function WorkloadsSurface(props: WorkloadsSurfaceComponentProps) {
}
if (visibleInventoryIssues().length > 0) {
+ // Falls back to the shared helper rather than a local literal so the
+ // infrastructureRead gate cannot be bypassed by whichever path renders.
return (
- state.workloadsNoInventoryState?.() ?? {
- title: 'No workload inventory available',
- description:
- 'Pulse has infrastructure sources, but no VM, container, or pod inventory is available right now.',
- actionLabel: 'Review infrastructure sources',
- }
+ state.workloadsNoInventoryState?.() ??
+ getWorkloadsNoInventoryState(sessionCanReadInfrastructureSettings())
);
}
diff --git a/frontend-modern/src/components/Workloads/__tests__/WorkloadsSurface.performance.contract.test.tsx b/frontend-modern/src/components/Workloads/__tests__/WorkloadsSurface.performance.contract.test.tsx
index d579b032d8..46eb8b0761 100644
--- a/frontend-modern/src/components/Workloads/__tests__/WorkloadsSurface.performance.contract.test.tsx
+++ b/frontend-modern/src/components/Workloads/__tests__/WorkloadsSurface.performance.contract.test.tsx
@@ -3,6 +3,7 @@ import { fireEvent, render, screen, waitFor } from '@solidjs/testing-library';
import { createSignal, onCleanup, onMount } from 'solid-js';
import { Route, Router } from '@solidjs/router';
import type { Resource } from '@/types/resource';
+import { syncSessionSettingsCapabilities } from '@/stores/sessionSettingsCapabilities';
import { WorkloadsSurface } from '../WorkloadsSurface';
import workloadsSource from '../WorkloadsSurface.tsx?raw';
import workloadsFilterSource from '../WorkloadsFilter.tsx?raw';
@@ -489,6 +490,9 @@ describe('Workloads performance contract', () => {
beforeEach(() => {
vi.clearAllMocks();
localStorage.clear();
+ // Session capability signals live at module scope; reset so a gated case
+ // cannot leak its viewer identity into the next test.
+ syncSessionSettingsCapabilities(null);
mockLocationSearch = '';
mockWorkloads = [];
mockInfrastructureResources = [];
@@ -653,6 +657,79 @@ describe('Workloads performance contract', () => {
);
});
+ it('withholds the infrastructure call to action from sessions without infrastructureRead', () => {
+ // No workloadsNoInventoryState stub here: the surface has to resolve the
+ // copy through the shared helper so the capability gate is what is under
+ // test, not a hand-written empty state.
+ syncSessionSettingsCapabilities({
+ settingsCapabilities: { infrastructureRead: false } as never,
+ });
+
+ render(() => (
+ <Router>
+ <Route
+ path="/"
+ component={() => (
+ <WorkloadsSurface
+ vms={[]}
+ containers={[]}
+ nodes={[]}
+ useWorkloads
+ state={
+ {
+ setClearSurfaceRootRef: vi.fn(),
+ kioskMode: () => false,
+ surfaceConnected: () => true,
+ surfaceInitialDataReceived: () => true,
+ allGuests: () => [],
+ filteredGuests: () => [],
+ search: () => '',
+ viewMode: () => 'all',
+ statusMode: () => 'all',
+ hostFilterConfig: () => undefined,
+ platformFilterConfig: () => undefined,
+ namespaceFilterConfig: () => undefined,
+ containerRuntimeFilterConfig: () => undefined,
+ workloadsGuestsEmptyState: () => ({
+ title: 'No guests found',
+ description: 'No guests match your current filters',
+ }),
+ workloadInventoryIssues: () => [
+ {
+ id: 'pve:delly',
+ name: 'delly',
+ type: 'pve',
+ typeLabel: 'Proxmox VE',
+ state: 'unreachable',
+ stateLabel: 'Source unreachable',
+ coverageLabel: 'VMs and containers',
+ description:
+ 'Pulse has VMs and containers enabled for delly, but the Proxmox VE API is unreachable.',
+ },
+ ],
+ } as any
+ }
+ />
+ )}
+ />
+ </Router>
+ ));
+
+ // The banner itself is unaffected by the gate — only the destination is.
+ expect(screen.getByTestId('workload-inventory-source-issues')).toBeInTheDocument();
+ expect(screen.getByText('Source unreachable: delly')).toBeInTheDocument();
+ expect(screen.getByText('No workload inventory available')).toBeInTheDocument();
+
+ expect(
+ screen.queryByRole('link', { name: 'Review infrastructure sources' }),
+ ).not.toBeInTheDocument();
+ expect(document.querySelector('a[href="/settings/infrastructure"]')).toBeNull();
+ expect(document.body).not.toHaveTextContent('Settings → Infrastructure');
+ expect(document.body).toHaveTextContent(
+ 'Contact a Pulse administrator to check source credentials, permissions, and collection status.',
+ );
+ });
+
it('opens workload row drawers inline without route navigation', async () => {
mockLocationSearch = '?type=all&agent=docker-main';
const routeSearchBeforeOpen = mockLocationSearch;
diff --git a/frontend-modern/src/components/Workloads/useWorkloadsState.ts b/frontend-modern/src/components/Workloads/useWorkloadsState.ts
index 9ec3e920ce..efda85270d 100644
--- a/frontend-modern/src/components/Workloads/useWorkloadsState.ts
+++ b/frontend-modern/src/components/Workloads/useWorkloadsState.ts
@@ -7,6 +7,7 @@ import type { Resource } from '@/types/resource';
import type { ViewMode, WorkloadGuest, WorkloadType } from '@/types/workloads';
import { useWebSocket } from '@/contexts/appRuntime';
import { useAlertsActivation } from '@/stores/alertsActivation';
+import { sessionCanReadInfrastructureSettings } from '@/stores/sessionSettingsCapabilities';
import { usePersistentSignal } from '@/hooks/usePersistentSignal';
import { createNonSuspendingQuery } from '@/hooks/createNonSuspendingQuery';
import { useUnifiedResources } from '@/hooks/useUnifiedResources';
@@ -333,7 +334,9 @@ export function useWorkloadsState(props: WorkloadsSurfaceProps) {
);
const workloadsGuestsEmptyState = createMemo(() => getWorkloadsGuestsEmptyState(search()));
const workloadsLoadingState = createMemo(() => getWorkloadsLoadingState(reconnecting()));
- const workloadsNoInventoryState = createMemo(() => getWorkloadsNoInventoryState());
+ const workloadsNoInventoryState = createMemo(() =>
+ getWorkloadsNoInventoryState(sessionCanReadInfrastructureSettings()),
+ );
const workloadsDisconnectedState = createMemo(() =>
getWorkloadsDisconnectedState(reconnecting()),
);
diff --git a/frontend-modern/src/stores/__tests__/sessionSettingsCapabilities.test.ts b/frontend-modern/src/stores/__tests__/sessionSettingsCapabilities.test.ts
new file mode 100644
index 0000000000..b4f97d5a4e
--- /dev/null
+++ b/frontend-modern/src/stores/__tests__/sessionSettingsCapabilities.test.ts
@@ -0,0 +1,92 @@
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+import {
+ sessionCanReadInfrastructureSettings,
+ sessionSettingsCapabilities,
+ syncSessionSettingsCapabilities,
+} from '@/stores/sessionSettingsCapabilities';
+import { syncSessionPresentationPolicy } from '@/stores/sessionPresentationPolicy';
+import type { SecurityStatusSettingsCapabilities } from '@/types/config';
+
+function capabilities(
+ overrides: Partial<SecurityStatusSettingsCapabilities>,
+): SecurityStatusSettingsCapabilities {
+ return {
+ infrastructureRead: false,
+ systemSettingsRead: false,
+ apiAccessRead: false,
+ apiAccessWrite: false,
+ authenticationRead: false,
+ authenticationWrite: false,
+ singleSignOnRead: false,
+ singleSignOnWrite: false,
+ roles: false,
+ users: false,
+ auditLog: false,
+ auditWebhooksRead: false,
+ auditWebhooksWrite: false,
+ relayRead: false,
+ relayWrite: false,
+ billingAdmin: false,
+ ...overrides,
+ } as SecurityStatusSettingsCapabilities;
+}
+
+describe('sessionSettingsCapabilities', () => {
+ beforeEach(() => {
+ syncSessionSettingsCapabilities(null);
+ });
+
+ it('keeps infrastructure links available until the capability set resolves', async () => {
+ // The signals live at module scope and every other case resolves them, so
+ // the pre-bootstrap state is only observable through a fresh module.
+ vi.resetModules();
+ const fresh = await import('@/stores/sessionSettingsCapabilities');
+
+ expect(fresh.sessionSettingsCapabilitiesResolved()).toBe(false);
+ expect(fresh.sessionSettingsCapabilities()).toBeNull();
+ // Fail open while unresolved: an admin must not flicker through the
+ // restricted copy if the bootstrap fetch is in flight or has failed.
+ expect(fresh.sessionCanReadInfrastructureSettings()).toBe(true);
+ });
+
+ it('reports infrastructure read access for an admin session', () => {
+ syncSessionSettingsCapabilities({
+ settingsCapabilities: capabilities({ infrastructureRead: true }),
+ });
+
+ expect(sessionCanReadInfrastructureSettings()).toBe(true);
+ expect(sessionSettingsCapabilities()?.infrastructureRead).toBe(true);
+ });
+
+ it('withholds infrastructure read access for a viewer session', () => {
+ syncSessionSettingsCapabilities({
+ settingsCapabilities: capabilities({ infrastructureRead: false }),
+ });
+
+ expect(sessionCanReadInfrastructureSettings()).toBe(false);
+ });
+
+ it('treats a security status without settingsCapabilities as no access', () => {
+ syncSessionSettingsCapabilities({ settingsCapabilities: undefined });
+
+ expect(sessionSettingsCapabilities()).toBeNull();
+ expect(sessionCanReadInfrastructureSettings()).toBe(false);
+ });
+
+ it('is published by the shared presentation-policy sync used at bootstrap', () => {
+ // useAppRuntimeState resolves /api/security/status through
+ // syncSessionPresentationPolicy on mount; piggybacking there is what makes
+ // the capability available to surfaces that never mount Settings.
+ syncSessionPresentationPolicy({
+ settingsCapabilities: capabilities({ infrastructureRead: true }),
+ });
+
+ expect(sessionCanReadInfrastructureSettings()).toBe(true);
+
+ syncSessionPresentationPolicy({
+ settingsCapabilities: capabilities({ infrastructureRead: false }),
+ });
+
+ expect(sessionCanReadInfrastructureSettings()).toBe(false);
+ });
+});
diff --git a/frontend-modern/src/stores/sessionPresentationPolicy.ts b/frontend-modern/src/stores/sessionPresentationPolicy.ts
index d3c633c20e..52012be3ef 100644
--- a/frontend-modern/src/stores/sessionPresentationPolicy.ts
+++ b/frontend-modern/src/stores/sessionPresentationPolicy.ts
@@ -5,6 +5,7 @@ import type {
SecurityStatusSessionCapabilities,
} from '@/types/config';
import { syncSessionCapabilities } from '@/stores/sessionCapabilities';
+import { syncSessionSettingsCapabilities } from '@/stores/sessionSettingsCapabilities';
const DEFAULT_SESSION_PRESENTATION_POLICY: SecurityStatusPresentationPolicy = {
demoMode: false,
@@ -40,9 +41,13 @@ function normalizeSessionPresentationPolicy(
}
export function syncSessionPresentationPolicy(
- status?: Pick<SecurityStatus, 'sessionCapabilities' | 'presentationPolicy'> | null,
+ status?: Pick<
+ SecurityStatus,
+ 'sessionCapabilities' | 'presentationPolicy' | 'settingsCapabilities'
+ > | null,
): SecurityStatusPresentationPolicy {
syncSessionCapabilities(status);
+ syncSessionSettingsCapabilities(status);
const next = normalizeSessionPresentationPolicy(
status?.presentationPolicy,
status?.sessionCapabilities,
diff --git a/frontend-modern/src/stores/sessionSettingsCapabilities.ts b/frontend-modern/src/stores/sessionSettingsCapabilities.ts
new file mode 100644
index 0000000000..9dc3f16773
--- /dev/null
+++ b/frontend-modern/src/stores/sessionSettingsCapabilities.ts
@@ -0,0 +1,43 @@
+import { createSignal } from 'solid-js';
+import type { SecurityStatus, SecurityStatusSettingsCapabilities } from '@/types/config';
+
+const [sessionSettingsCapabilities, setSessionSettingsCapabilities] =
+ createSignal<SecurityStatusSettingsCapabilities | null>(null);
+const [sessionSettingsCapabilitiesResolved, setSessionSettingsCapabilitiesResolved] =
+ createSignal(false);
+
+/**
+ * Publishes the session's Settings capabilities from `/api/security/status` so
+ * surfaces outside Settings can tell whether a Settings destination is actually
+ * reachable. Settings itself resolves the same payload through
+ * `useSettingsAccess`, but that fetch only runs once Settings mounts, which is
+ * no help to a page deciding whether to link there in the first place.
+ */
+export function syncSessionSettingsCapabilities(
+ status?: Pick<SecurityStatus, 'settingsCapabilities'> | null,
+): SecurityStatusSettingsCapabilities | null {
+ const next = status?.settingsCapabilities ?? null;
+ setSessionSettingsCapabilities(next);
+ setSessionSettingsCapabilitiesResolved(true);
+ return next;
+}
+
+/**
+ * Mirrors the Settings nav gate for Infrastructure (`requiredCapability:
+ * 'infrastructureRead'` in settingsNavCatalog), so a surface that links to
+ * Settings → Infrastructure can never offer a destination the nav itself hides.
+ * Reusing the destination's own capability is what keeps the two from drifting.
+ *
+ * Unresolved sessions keep the link, matching how `settingsNavVisibility`
+ * treats an unresolved capability set: the bootstrap fetch is the first request
+ * the app makes, and an admin must not flicker through the restricted copy if
+ * it is briefly in flight or has failed.
+ */
+export function sessionCanReadInfrastructureSettings(): boolean {
+ if (!sessionSettingsCapabilitiesResolved()) {
+ return true;
+ }
+ return sessionSettingsCapabilities()?.infrastructureRead === true;
+}
+
+export { sessionSettingsCapabilities, sessionSettingsCapabilitiesResolved };
diff --git a/frontend-modern/src/utils/__tests__/workloadEmptyStatePresentation.test.ts b/frontend-modern/src/utils/__tests__/workloadEmptyStatePresentation.test.ts
index c3be844f1d..7135728ad5 100644
--- a/frontend-modern/src/utils/__tests__/workloadEmptyStatePresentation.test.ts
+++ b/frontend-modern/src/utils/__tests__/workloadEmptyStatePresentation.test.ts
@@ -86,6 +86,7 @@ describe('workloadEmptyStatePresentation', () => {
'Pulse has infrastructure sources, but no VM, container, or pod inventory is available right now. Review source credentials, permissions, and collection status in Settings → Infrastructure.',
actionLabel: 'Review infrastructure sources',
});
+ expect(getWorkloadsNoInventoryState(true)).toEqual(getWorkloadsNoInventoryState());
expect(getWorkloadsNoResourcesState()).toEqual({
title: 'Connect your first infrastructure source',
description:
@@ -93,4 +94,20 @@ describe('workloadEmptyStatePresentation', () => {
actionLabel: 'Add infrastructure source',
});
});
+
+ it('drops the Settings → Infrastructure call to action without infrastructureRead', () => {
+ const state = getWorkloadsNoInventoryState(false);
+
+ expect(state).toEqual({
+ title: 'No workload inventory available',
+ description:
+ 'Pulse has infrastructure sources, but no VM, container, or pod inventory is available right now. Contact a Pulse administrator to check source credentials, permissions, and collection status.',
+ actionLabel: undefined,
+ });
+ // A viewer cannot open Settings → Infrastructure (the nav item is gated on
+ // infrastructureRead), so neither the link nor the copy may point there.
+ expect(state.actionLabel).toBeUndefined();
+ expect(state.description).not.toContain('Settings → Infrastructure');
+ expect(state.description).not.toContain('Review');
+ });
});
diff --git a/frontend-modern/src/utils/workloadEmptyStatePresentation.ts b/frontend-modern/src/utils/workloadEmptyStatePresentation.ts
index c1d76a8e4f..7a324c0ac3 100644
--- a/frontend-modern/src/utils/workloadEmptyStatePresentation.ts
+++ b/frontend-modern/src/utils/workloadEmptyStatePresentation.ts
@@ -19,12 +19,20 @@ export function getWorkloadsGuestsEmptyState(search: string) {
} as const;
}
-export function getWorkloadsNoInventoryState() {
+/**
+ * `canReviewInfrastructureSources` reflects the session's `infrastructureRead`
+ * capability — the same gate that decides whether Settings → Infrastructure is
+ * in the nav at all. A viewer without it reaches this state (the inventory
+ * source issues that trigger it are served at monitoring:read), so the copy has
+ * to stop naming a page they cannot open and point them at someone who can.
+ */
+export function getWorkloadsNoInventoryState(canReviewInfrastructureSources = true) {
return {
title: 'No workload inventory available',
- description:
- 'Pulse has infrastructure sources, but no VM, container, or pod inventory is available right now. Review source credentials, permissions, and collection status in Settings → Infrastructure.',
- actionLabel: 'Review infrastructure sources',
+ description: canReviewInfrastructureSources
+ ? 'Pulse has infrastructure sources, but no VM, container, or pod inventory is available right now. Review source credentials, permissions, and collection status in Settings → Infrastructure.'
+ : 'Pulse has infrastructure sources, but no VM, container, or pod inventory is available right now. Contact a Pulse administrator to check source credentials, permissions, and collection status.',
+ actionLabel: canReviewInfrastructureSources ? 'Review infrastructure sources' : undefined,
} as const;
}