Skip to content

Commit 44b2463

Browse files
committed
fix(usage): hide the workspace audit link where audit logs are disabled
Usage monitoring and Audit logs share their hosted and enterprise gates, so reaching the usage panel proves both — but their self-hosted overrides are separate flags. An install with usage monitoring on and audit logs off was handed a drill-down action pointing at a section it had switched off. The window is deliberately not carried across the link: the audit feed speaks in rolling ranges and this panel in billing periods, so there is no honest mapping for the current-period preset.
1 parent 13a1894 commit 44b2463

1 file changed

Lines changed: 35 additions & 18 deletions

File tree

apps/sim/ee/organization-usage/components/usage-monitoring.tsx

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
type UsageBreakdownDimension,
2020
} from '@/lib/api/contracts/organization-usage'
2121
import { dollarsToCredits } from '@/lib/billing/credits/conversion'
22-
import { isHosted } from '@/lib/core/config/env-flags'
22+
import { isAuditLogsEnabled, isHosted } from '@/lib/core/config/env-flags'
2323
import {
2424
ManageCreditsModal,
2525
type ManageCreditsTarget,
@@ -187,8 +187,21 @@ export function UsageMonitoring({
187187
// cannot report a different allowance than they do.
188188
const billing = useOrganizationBilling(organizationId)
189189

190-
/** The organization audit feed, narrowed to the workspace being drilled into. */
191-
const auditLogsHref = serializeAuditLogFilters(auditLogsBaseHref, { workspace })
190+
/**
191+
* The organization audit feed, narrowed to the workspace being drilled into.
192+
*
193+
* Only offered where that section exists. Usage and Audit logs carry the same
194+
* hosted and enterprise gates, so reaching this panel already proves both — but
195+
* their self-hosted overrides are separate flags, and an install with usage
196+
* monitoring on and audit logs off would have been handed an action pointing at a
197+
* section it had switched off. The window is deliberately not carried across: the
198+
* audit feed speaks in rolling ranges (`Past 30 days`) and this panel in billing
199+
* periods, so there is no honest mapping for `current-period`.
200+
*/
201+
const auditLogsHref =
202+
isHosted || isAuditLogsEnabled
203+
? serializeAuditLogFilters(auditLogsBaseHref, { workspace })
204+
: null
192205

193206
/**
194207
* The drill-down is the same window, in more detail. Without the params it read its
@@ -288,21 +301,25 @@ export function UsageMonitoring({
288301
onSelect: () => void setState({ workspace: null, expanded: null }),
289302
}}
290303
title={workspaceName ?? 'Workspace usage'}
291-
actions={[
292-
{
293-
/*
294-
The organization's audit feed, scoped to this workspace — not
295-
`/workspace/<id>/logs`. Organization admin is not workspace
296-
membership, and `WorkspaceLayout` answers a non-member with
297-
`WorkspaceAccessDenied`, so the run-logs route was a one-way trip to
298-
a dead end for any workspace the admin had not joined. Audit logs
299-
live in the settings section the admin is already inside.
300-
*/
301-
text: 'Open logs',
302-
onSelect: () => router.push(auditLogsHref),
303-
onPrefetch: () => router.prefetch(auditLogsHref),
304-
},
305-
]}
304+
actions={
305+
auditLogsHref
306+
? [
307+
{
308+
/*
309+
The organization's audit feed, scoped to this workspace — not
310+
`/workspace/<id>/logs`. Organization admin is not workspace
311+
membership, and `WorkspaceLayout` answers a non-member with
312+
`WorkspaceAccessDenied`, so the run-logs route was a one-way trip
313+
to a dead end for any workspace the admin had not joined. Audit
314+
logs live in the settings section the admin is already inside.
315+
*/
316+
text: 'Open logs',
317+
onSelect: () => router.push(auditLogsHref),
318+
onPrefetch: () => router.prefetch(auditLogsHref),
319+
},
320+
]
321+
: []
322+
}
306323
>
307324
{/*
308325
Sources first, because in most workspaces the majority of usage is Chat

0 commit comments

Comments
 (0)