Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(taxonomic-filter): explain 403 instead of offering a retry (#115515)

posthog[bot]430656627569
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 7cfd85faa277..7519495e3b94 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -3636,6 +3636,10 @@ snapshots:
hash: v1.k794b7964.10a15792b243817d48e633c341785bb53c61190855cdaaedbf1d998b63e2eeae.mTmd_ahFm4OUQSDwoQZQYsO3FpPuFvIv4TvR1YqBMz0
filters-taxonomic-filter--failed-fetch-offers-retry--light:
hash: v1.k794b7964.bb9f77210fc46675e7920c1b21c7a158e4eb39c85a08d4b0cde7c286595f469d.y8Rs6NZrklaloeqgzT466bxafKhL6pW6tLDQxQjgd9o
+ filters-taxonomic-filter--forbidden-fetch-explains-access--dark:
+ hash: v1.k794b7964.fc8abf7ec927b8a20b70cc98847b42a319c5d0a0ee8dca3d5a5de579bd020f59.xGOVZVwX7RfOVGIRV6Hp99UlIQj7CAfKsnssx197U0E
+ filters-taxonomic-filter--forbidden-fetch-explains-access--light:
+ hash: v1.k794b7964.42f276a4dc8528c8a600268fb9297535a060bd540a6209c6f252f5d50afc3669.jMCHVqQmG06MgsRXhZaWL3p4RGPFtQXjs8xHDg290zo
filters-taxonomic-filter--mcp-tool-call-context-leads-with-mcp-properties--dark:
hash: v1.k794b7964.ff551492bfcfe81fa1d7c1101a3fd258808066e0088d7804e36f80b827d2937c.rXfu9_gG7W0hdSyTAvM6fftG8tkEk7ayHbQCk9RXseA
filters-taxonomic-filter--mcp-tool-call-context-leads-with-mcp-properties--light:
diff --git a/frontend/src/lib/components/FlagSelector.tsx b/frontend/src/lib/components/FlagSelector.tsx
index cd4ab4477b87..107ed9f24676 100644
--- a/frontend/src/lib/components/FlagSelector.tsx
+++ b/frontend/src/lib/components/FlagSelector.tsx
@@ -5,9 +5,10 @@ import { TaxonomicFilter } from 'lib/components/TaxonomicFilter/TaxonomicFilter'
import { TaxonomicFilterGroupType, TaxonomicFilterLogicProps } from 'lib/components/TaxonomicFilter/types'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { Popover } from 'lib/lemon-ui/Popover'
+import { productHasEffectiveNoneAccess } from 'lib/utils/accessControlUtils'
import { featureFlagLogic } from 'scenes/feature-flags/featureFlagLogic'
-import { FeatureFlagBasicType } from '~/types'
+import { AccessControlResourceType, FeatureFlagBasicType } from '~/types'
interface FlagSelectorProps {
value: number | undefined
@@ -76,6 +77,11 @@ export function FlagSelector({
selectingKeyOnly: true,
}
+ // The flag list returns 403 without view access, so opening the picker can only show an error.
+ const noFlagAccessReason = productHasEffectiveNoneAccess(AccessControlResourceType.FeatureFlag)
+ ? "You don't have access to feature flags in this project"
+ : undefined
+
const buttonLabel = flagSelectorButtonLabel({
flagKey: featureFlag.key,
value,
@@ -94,7 +100,7 @@ export function FlagSelector({
<LemonButton
type="secondary"
onClick={() => setVisible(!visible)}
- disabledReason={readOnly && (disabledReason || "I'm read-only")}
+ disabledReason={(readOnly && (disabledReason || "I'm read-only")) || noFlagAccessReason}
>
{buttonLabel}
</LemonButton>
diff --git a/frontend/src/lib/components/TaxonomicFilter/InfiniteList.tsx b/frontend/src/lib/components/TaxonomicFilter/InfiniteList.tsx
index ee635c24283f..1ce23a0cd163 100644
--- a/frontend/src/lib/components/TaxonomicFilter/InfiniteList.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/InfiniteList.tsx
@@ -6,7 +6,16 @@ import { BindLogic, useActions, useValues } from 'kea'
import { CSSProperties, useEffect, useState } from 'react'
import { List, useListRef } from 'react-window'
-import { IconArchive, IconCheck, IconPin, IconPinFilled, IconPlus, IconSearch, IconWarning } from '@posthog/icons'
+import {
+ IconArchive,
+ IconCheck,
+ IconLock,
+ IconPin,
+ IconPinFilled,
+ IconPlus,
+ IconSearch,
+ IconWarning,
+} from '@posthog/icons'
import { LemonButton, LemonDivider, LemonTag } from '@posthog/lemon-ui'
import { AutoSizer } from 'lib/components/AutoSizer'
@@ -862,21 +871,34 @@ function InfiniteListEmptyState(): JSX.Element {
}
function InfiniteListErrorState(): JSX.Element {
+ const { group, remoteFetchForbidden } = useValues(infiniteListLogic)
const { retryRemoteItems } = useActions(infiniteListLogic)
return (
<div className="no-infinite-results flex flex-col gap-y-1 items-center">
- <IconWarning className="text-5xl text-tertiary" />
- <span className="text-center">Couldn't load results</span>
- <LemonButton
- type="secondary"
- size="xsmall"
- data-attr="taxonomic-retry-remote-items"
- onClick={retryRemoteItems}
- >
- Try again
- </LemonButton>
- <span className="text-center text-secondary italic">If it keeps happening, contact support.</span>
+ {remoteFetchForbidden ? (
+ <>
+ <IconLock className="text-5xl text-tertiary" />
+ <span className="text-center">
+ You don't have access to {group?.searchPlaceholder || 'these results'} in this project.
+ </span>
+ <span className="text-center text-secondary">Ask a project admin for access.</span>
+ </>
+ ) : (
+ <>
+ <IconWarning className="text-5xl text-tertiary" />
+ <span className="text-center">Couldn't load results</span>
+ <LemonButton
+ type="secondary"
+ size="xsmall"
+ data-attr="taxonomic-retry-remote-items"
+ onClick={retryRemoteItems}
+ >
+ Try again
+ </LemonButton>
+ <span className="text-center text-secondary italic">If it keeps happening, contact support.</span>
+ </>
+ )}
</div>
)
}
diff --git a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.stories.tsx b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.stories.tsx
index acc03ca08fa7..dab5b3b615ae 100644
--- a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.stories.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.stories.tsx
@@ -731,6 +731,32 @@ export const FailedFetchOffersRetry: Story = {
},
}
+export const ForbiddenFetchExplainsAccess: Story = {
+ args: {
+ taxonomicFilterLogicKey: 'feature-flags-forbidden',
+ taxonomicGroupTypes: [TaxonomicFilterGroupType.FeatureFlags],
+ groupType: TaxonomicFilterGroupType.FeatureFlags,
+ },
+ decorators: [
+ mswDecorator({
+ get: {
+ '/api/projects/:team_id/feature_flags': () => [
+ 403,
+ { detail: 'permission denied', code: 'permission_denied' },
+ ],
+ },
+ }),
+ ],
+ parameters: {
+ testOptions: { waitForSelector: '.no-infinite-results' },
+ docs: {
+ description: {
+ story: 'When the list returns 403, the list explains the missing access and offers no retry, because a retry cannot succeed.',
+ },
+ },
+ },
+}
+
export const CustomEventName: Story = {
render: (args) => {
const { setSearchQuery } = useActions(
diff --git a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.test.ts b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.test.ts
index f5c23ef8a9fa..8ee8f4b9015d 100644
--- a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.test.ts
+++ b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.test.ts
@@ -752,6 +752,7 @@ describe('infiniteListLogic', () => {
// hunting for a tracking bug instead of retrying.
showEmptyState: false,
showErrorState: true,
+ remoteFetchForbidden: false,
})
const failedCalls = captureSpy.mock.calls.filter((c) => c[0] === 'taxonomic filter fetch failed')
@@ -759,6 +760,43 @@ describe('infiniteListLogic', () => {
expect(failedCalls[0][1]).toMatchObject({
groupType: TaxonomicFilterGroupType.Events,
searchQuery: 'user_signed_up',
+ forbidden: false,
+ })
+ })
+
+ it.each([
+ { code: 'permission_denied', forbidden: true },
+ { code: 'feature_flag_required', forbidden: false },
+ ])('marks a 403 with code $code as forbidden: $forbidden', async ({ code, forbidden }) => {
+ useMocks({
+ get: {
+ '/api/projects/:team/feature_flags': () => [403, { detail: 'denied', code }],
+ },
+ })
+ initKeaTests()
+ const captureSpy = jest.spyOn(posthog, 'capture')
+ const forbiddenLogic = infiniteListLogic({
+ taxonomicFilterLogicKey: 'forbiddenList',
+ listGroupType: TaxonomicFilterGroupType.FeatureFlags,
+ taxonomicGroupTypes: [TaxonomicFilterGroupType.FeatureFlags],
+ showNumericalPropsOnly: false,
+ })
+ forbiddenLogic.mount()
+ await expectLogic(forbiddenLogic, () => {
+ forbiddenLogic.actions.setSearchQuery('my-flag')
+ })
+ .toDispatchActions(['setSearchQuery', 'loadRemoteItems', 'loadRemoteItemsFailure'])
+ .toFinishAllListeners()
+ .toMatchValues({
+ showErrorState: true,
+ remoteFetchForbidden: forbidden,
+ })
+
+ const failedCalls = captureSpy.mock.calls.filter((c) => c[0] === 'taxonomic filter fetch failed')
+ expect(failedCalls).toHaveLength(1)
+ expect(failedCalls[0][1]).toMatchObject({
+ groupType: TaxonomicFilterGroupType.FeatureFlags,
+ forbidden,
})
})
diff --git a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts
index 720dd1605b40..722f1a45fb50 100644
--- a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts
+++ b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts
@@ -17,6 +17,7 @@ import { combineUrl } from 'kea-router'
import posthog from 'posthog-js'
import api, { ApiMethodOptions } from 'lib/api'
+import { isAccessDeniedError } from 'lib/api-error'
import { formatPropertyLabel } from 'lib/components/PropertyFilters/utils'
import {
hasRecentContext,
@@ -321,6 +322,7 @@ export interface infiniteListLogicValues {
rawLocalItems: (CohortType | EventDefinition)[]
remoteEndpoint: string | null
remoteFetchFailed: string | null
+ remoteFetchForbidden: boolean
remoteItems: ListStorage
remoteItemsLoading: boolean
remoteResultsAreFresh: boolean
@@ -480,7 +482,11 @@ export interface infiniteListLogicActions {
reconcilePinnedRowState: () => {
value: true
}
- remoteItemsFetchFailedForQuery: (searchQuery: string) => {
+ remoteItemsFetchFailedForQuery: (
+ searchQuery: string,
+ forbidden?: boolean
+ ) => {
+ forbidden: boolean
searchQuery: string
}
resetPinnedRowState: () => {
@@ -877,7 +883,10 @@ export const infiniteListLogic = kea<infiniteListLogicType>([
expand: true,
abortAnyRunningQuery: true,
setHasMore: (hasMore: boolean) => ({ hasMore }),
- remoteItemsFetchFailedForQuery: (searchQuery: string) => ({ searchQuery }),
+ remoteItemsFetchFailedForQuery: (searchQuery: string, forbidden: boolean = false) => ({
+ searchQuery,
+ forbidden,
+ }),
retryRemoteItems: true,
}),
loaders(({ actions, values, cache, props }) => ({
@@ -991,7 +1000,7 @@ export const infiniteListLogic = kea<infiniteListLogicType>([
if (!isBreakpoint(error) && !aborted) {
// Carry the query that was in flight when this run errored so the
// reducer can attribute the failure to the right query string.
- actions.remoteItemsFetchFailedForQuery(searchQuery)
+ actions.remoteItemsFetchFailedForQuery(searchQuery, isAccessDeniedError(error))
}
throw error
} finally {
@@ -1139,6 +1148,16 @@ export const infiniteListLogic = kea<infiniteListLogicType>([
remoteItemsFetchFailedForQuery: (_, { searchQuery }) => searchQuery,
},
],
+ // A permission_denied 403 means the user lacks access to this list, so a retry can never succeed.
+ // Other 403s, such as feature_flag_required, can clear on their own, so they keep the retry.
+ remoteFetchForbidden: [
+ false,
+ {
+ loadRemoteItems: () => false,
+ loadRemoteItemsSuccess: () => false,
+ remoteItemsFetchFailedForQuery: (_, { forbidden }) => forbidden,
+ },
+ ],
})),
selectors({
listGroupType: [(_, p) => [p.listGroupType], (listGroupType: TaxonomicFilterGroupType) => listGroupType],
@@ -2345,7 +2364,7 @@ export const infiniteListLogic = kea<infiniteListLogicType>([
}
}
},
- remoteItemsFetchFailedForQuery: ({ searchQuery }) => {
+ remoteItemsFetchFailedForQuery: ({ searchQuery, forbidden }) => {
// Failures land on the same empty state as genuine no-matches, so without this
// capture the "event exists but the backend blipped" case is invisible in prod.
// The empty-query load that runs when the picker opens counts too: it hits the same
@@ -2366,6 +2385,7 @@ export const infiniteListLogic = kea<infiniteListLogicType>([
surface: legacyTaxonomicSurface(),
groupType: props.listGroupType,
searchQuery: trimmedQuery,
+ forbidden,
})
}
},
diff --git a/frontend/src/lib/utils/accessControlUtils.ts b/frontend/src/lib/utils/accessControlUtils.ts
index c5ef89f4a052..d165084525c4 100644
--- a/frontend/src/lib/utils/accessControlUtils.ts
+++ b/frontend/src/lib/utils/accessControlUtils.ts
@@ -295,7 +295,7 @@ const ENTRY_TYPE_TO_RESOURCE_TYPE: Record<string, AccessControlResourceType> = {
session_recording_playlist: AccessControlResourceType.SessionRecording,
}
-const productHasEffectiveNoneAccess = (resourceType: AccessControlResourceType): boolean => {
+export const productHasEffectiveNoneAccess = (resourceType: AccessControlResourceType): boolean => {
return getAppContext()?.effective_resource_access_control?.[resourceType] === AccessControlLevel.None
}