: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(settings): explain a gated settings section instead of not found (#103991)
posthog[bot]d1ae875ee9b0
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 39ba707170df..0e94ef17452d 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -11304,6 +11304,14 @@ snapshots:hash: v1.k794b7964.b2de0cd0533566c2406e9c66bcbe6a83c6f7b2bd0e1862027ba36a33a78624d1.D6LgyASNsXWSr98qx80h-brseJENrtIOMEJsSNN9sUoscenes-app-settings-project--settings-project-surveys--light:hash: v1.k794b7964.1dce2d50ae8e763257abefd34003f487df7baa41b6313291544ef850594c67eb.FZ2Kzj3Zzi8EPr4bXptpzNAps-OhQ0Je0kW17u3dXwc+ scenes-app-settings-settingsectionunavailable--admin-only--dark:+ hash: v1.k794b7964.b6580b1a9c7735f0b03e9d5b58954169a1772b47bc2ae449f14771e1c5281a7b.Pp01b8BavwsYTSE4Mo3Q57hwN0X73qsh7JDbp7_DORo+ scenes-app-settings-settingsectionunavailable--admin-only--light:+ hash: v1.k794b7964.7e462c4ab5f42a3a7009504cddfad7bbf1b34f06f55179223819189371f2fb88.8GzqqWh7i9xTHpvCqKwIgIXtub_koGBxpqDOTb_lRX8+ scenes-app-settings-settingsectionunavailable--not-enabled--dark:+ hash: v1.k794b7964.df4991f623bf060ebc92ccee5e33ad3b03f7f14ed7e00e298e5789298c46f821.D_Z6MA0PLkC5eOxoazEB5kCQiYVMkS80XqkfJzm7ycI+ scenes-app-settings-settingsectionunavailable--not-enabled--light:+ hash: v1.k794b7964.06e88a65c54124deb1ddd8236f4473695e5a87d5360ae5ab266779e9fc118f0b.m-LRG6zgQ_Ci4Y8_7H8N1OSIa2-GAzu9ZogXu0IDCdkscenes-app-settings-user--settings-user-api-keys--dark:hash: v1.k794b7964.c2bdcdc0dae9ab40e695772337ae95876f4f65dee34af627210f5af55fa567e9.OrMBp-9yqlfHY7s8HIzZg8R6M2i0lPVY5q9mx__VSjkscenes-app-settings-user--settings-user-api-keys--light:diff --git a/frontend/src/scenes/settings/Settings.tsx b/frontend/src/scenes/settings/Settings.tsxindex f95a1abe9033..c07eb852fc40 100644--- a/frontend/src/scenes/settings/Settings.tsx+++ b/frontend/src/scenes/settings/Settings.tsx@@ -42,6 +42,7 @@ import { userLogic } from 'scenes/userLogic'import { ErrorBoundary } from '~/layout/ErrorBoundary'+import { SettingSectionUnavailable } from './components/SettingSectionUnavailable'import { SearchResult, settingsLogic } from './settingsLogic'import { SettingLevelId, SettingsLogicProps } from './types'@@ -420,6 +421,7 @@ function SettingsRenderer(props: SettingsLogicProps & { handleLocally: boolean }selectedSection,selectedSectionId,selectedSetting,+ unavailableSection,} = useValues(settingsLogic(props))const { selectSetting } = useActions(settingsLogic(props))const { user } = useValues(userLogic)@@ -467,6 +469,8 @@ function SettingsRenderer(props: SettingsLogicProps & { handleLocally: boolean }<ErrorBoundary>{x.component}</ErrorBoundary></div>))+ ) : unavailableSection ? (+ <SettingSectionUnavailable section={unavailableSection} />) : (<NotFound object="setting" />)}diff --git a/frontend/src/scenes/settings/SettingsMap.tsx b/frontend/src/scenes/settings/SettingsMap.tsxindex 89086be9b0fc..f2727b092df8 100644--- a/frontend/src/scenes/settings/SettingsMap.tsx+++ b/frontend/src/scenes/settings/SettingsMap.tsx@@ -2194,6 +2194,7 @@ export const SETTINGS_MAP: SettingSection[] = [// Temporary migration surface: reachable only from the access control// settings banner, never from the settings navigation or searchhideFromNavigation: true,+ unavailableFallback: { sectionId: 'organization-roles', label: 'Go to access control settings' },settings: [{id: 'organization-access-resolution-preview',diff --git a/frontend/src/scenes/settings/components/SettingSectionUnavailable.stories.tsx b/frontend/src/scenes/settings/components/SettingSectionUnavailable.stories.tsxnew file mode 100644index 000000000000..0bceace228b4--- /dev/null+++ b/frontend/src/scenes/settings/components/SettingSectionUnavailable.stories.tsx@@ -0,0 +1,34 @@+import type { Meta, StoryObj } from '@storybook/react'++import { SettingSectionUnavailable } from './SettingSectionUnavailable'++type Story = StoryObj<typeof SettingSectionUnavailable>++const meta: Meta<typeof SettingSectionUnavailable> = {+ title: 'Scenes-App/Settings/SettingSectionUnavailable',+ component: SettingSectionUnavailable,+ parameters: { layout: 'fullscreen' },+}+export default meta++export const NotEnabled: Story = {+ args: {+ section: {+ id: 'organization-access-resolution',+ title: 'Access resolution preview',+ reason: 'not-enabled',+ fallback: { sectionId: 'organization-roles', label: 'Go to access control settings' },+ },+ },+}++export const AdminOnly: Story = {+ args: {+ section: {+ id: 'organization-access-resolution',+ title: 'Access resolution preview',+ reason: 'admin-only',+ fallback: { sectionId: 'organization-roles', label: 'Go to access control settings' },+ },+ },+}diff --git a/frontend/src/scenes/settings/components/SettingSectionUnavailable.tsx b/frontend/src/scenes/settings/components/SettingSectionUnavailable.tsxnew file mode 100644index 000000000000..7b232e36fcfc--- /dev/null+++ b/frontend/src/scenes/settings/components/SettingSectionUnavailable.tsx@@ -0,0 +1,46 @@+import posthog from 'posthog-js'++import { AccessDenied } from 'lib/components/AccessDenied'+import { useOnMountEffect } from 'lib/hooks/useOnMountEffect'+import { Link } from 'lib/lemon-ui/Link'+import { urls } from 'scenes/urls'++import { UnavailableSection } from '../types'++export function SettingSectionUnavailable({ section }: { section: UnavailableSection }): JSX.Element {+ useOnMountEffect(() => {+ // pinned: analytics event name, renaming it breaks dashboards+ posthog.capture('settings_section_unavailable_shown', { section_id: section.id, reason: section.reason })+ })++ const fallbackLink = section.fallback ? (+ <Link to={urls.settings(section.fallback.sectionId)} data-attr="settings-section-unavailable-fallback">+ {section.fallback.label}+ </Link>+ ) : null++ if (section.reason === 'admin-only') {+ return (+ <AccessDenied+ reason={+ <>+ {section.title} is available to organization admins and owners. {fallbackLink}+ </>+ }+ />+ )+ }++ return (+ <div+ className="flex flex-col items-center gap-3 max-w-2xl p-4 mx-auto my-24 text-center"+ data-attr="settings-section-unavailable"+ >+ <h1 className="text-3xl font-bold mb-0">Not available yet</h1>+ <p className="text-sm mb-0">+ {section.title} is not enabled for your organization yet. Contact support if you need it now.+ </p>+ {fallbackLink}+ </div>+ )+}diff --git a/frontend/src/scenes/settings/sectionGating.test.ts b/frontend/src/scenes/settings/sectionGating.test.tsnew file mode 100644index 000000000000..48b26f43eaea--- /dev/null+++ b/frontend/src/scenes/settings/sectionGating.test.ts@@ -0,0 +1,92 @@+import { SettingSection, SettingSectionId } from '~/scenes/settings/types'++import { findUnavailableSection } from './sectionGating'++const section = (id: SettingSectionId, overrides: Partial<SettingSection> = {}): SettingSection => ({+ id,+ title: 'Access resolution preview',+ level: 'organization',+ settings: [],+ ...overrides,+})++describe('findUnavailableSection', () => {+ const gatedSection = section('organization-access-resolution', {+ flag: 'ACCESS_CONTROL_RESOLUTION_PREVIEW',+ unavailableFallback: { sectionId: 'organization-roles', label: 'Go to access control settings' },+ })++ it('explains a section the feature flag hides', () => {+ expect(+ findUnavailableSection({+ sectionId: 'organization-access-resolution',+ visibleSections: [],+ allSections: [gatedSection],+ gatesResolved: true,+ doesMatchFlags: () => false,+ isAdminOrOwner: true,+ })+ ).toEqual({+ id: 'organization-access-resolution',+ title: 'Access resolution preview',+ reason: 'not-enabled',+ fallback: { sectionId: 'organization-roles', label: 'Go to access control settings' },+ })+ })++ it('explains a section only admins can open', () => {+ expect(+ findUnavailableSection({+ sectionId: 'organization-access-resolution',+ visibleSections: [],+ allSections: [gatedSection],+ gatesResolved: true,+ doesMatchFlags: () => true,+ isAdminOrOwner: false,+ })+ ).toMatchObject({ reason: 'admin-only' })+ })++ it('waits for the flags and the membership level before it calls a section admin-only', () => {+ expect(+ findUnavailableSection({+ sectionId: 'organization-access-resolution',+ visibleSections: [],+ allSections: [gatedSection],+ gatesResolved: false,+ doesMatchFlags: () => true,+ isAdminOrOwner: false,+ })+ ).toBeNull()+ })++ it.each([+ ['the section is visible', 'organization-access-resolution' as SettingSectionId, [gatedSection]],+ ['the section does not exist', 'organization-security' as SettingSectionId, []],+ ['no section is requested', null, []],+ ])('returns nothing when %s', (_name, sectionId, visibleSections) => {+ expect(+ findUnavailableSection({+ sectionId,+ visibleSections,+ allSections: [gatedSection],+ gatesResolved: true,+ doesMatchFlags: () => true,+ isAdminOrOwner: false,+ })+ ).toBeNull()+ })++ it('matches an environment section against its project id', () => {+ expect(+ findUnavailableSection({+ sectionId: 'project-replay',+ visibleSections: [],+ allSections: [section('environment-replay', { flag: 'ACCESS_CONTROL_RESOLUTION_PREVIEW' })],+ gatesResolved: true,+ doesMatchFlags: () => false,+ isAdminOrOwner: true,+ })+ ).toMatchObject({ id: 'environment-replay', reason: 'not-enabled' })+ })+})diff --git a/frontend/src/scenes/settings/sectionGating.ts b/frontend/src/scenes/settings/sectionGating.tsnew file mode 100644index 000000000000..8cb5a93f40dc--- /dev/null+++ b/frontend/src/scenes/settings/sectionGating.ts@@ -0,0 +1,63 @@+import { SettingSection, SettingSectionId, UnavailableSection } from '~/scenes/settings/types'++/**+ * Sections the settings navigation drops for everyone below organization admin. Kept here so the+ * navigation filter and the unavailable-section explanation stay in step.+ */+export const ADMIN_ONLY_SECTION_IDS: SettingSectionId[] = [+ 'organization-legal-documents',+ 'organization-access-resolution',+]++interface FindUnavailableSectionInput {+ /** Section the reader asked for, already mapped from environment to project. */+ sectionId: SettingSectionId | null+ /** Sections the reader can open. */+ visibleSections: SettingSection[]+ /** Every section the app defines, gated or not. */+ allSections: SettingSection[]+ /** False while the feature flags or the organization membership level are still on their way. */+ gatesResolved: boolean+ doesMatchFlags: (flagDefinition: Pick<SettingSection, 'flag'>) => boolean+ isAdminOrOwner: boolean | null+}++/**+ * Works out why a section the reader asked for is missing, so a deep link into a gated section can+ * explain itself instead of falling through to the generic not-found state.+ */+export const findUnavailableSection = ({+ sectionId,+ visibleSections,+ allSections,+ gatesResolved,+ doesMatchFlags,+ isAdminOrOwner,+}: FindUnavailableSectionInput): UnavailableSection | null => {+ if (!gatesResolved || !sectionId || visibleSections.some((section) => section.id === sectionId)) {+ return null+ }++ const definition = allSections.find(+ (section) => section.id === sectionId || section.id.replace(/^environment/, 'project') === sectionId+ )+ if (!definition) {+ return null+ }++ const reason = !doesMatchFlags(definition)+ ? 'not-enabled'+ : ADMIN_ONLY_SECTION_IDS.includes(definition.id) && !isAdminOrOwner+ ? 'admin-only'+ : null+ if (!reason) {+ return null+ }++ return {+ id: definition.id,+ title: definition.title,+ reason,+ fallback: definition.unavailableFallback ?? null,+ }+}diff --git a/frontend/src/scenes/settings/settingsLogic.ts b/frontend/src/scenes/settings/settingsLogic.tsindex c68a4490f37f..088970c3efea 100644--- a/frontend/src/scenes/settings/settingsLogic.ts+++ b/frontend/src/scenes/settings/settingsLogic.ts@@ -19,6 +19,7 @@ import type { FeatureFlagsSet } from '../../lib/logic/featureFlagLogic'import type { IntegrationType, PreflightStatus, TeamPublicType, TeamType } from '../../types'import type { AvailableFeature, OrganizationType } from '../../types'import { matchesFlagDefinition } from './flagGating'+import { ADMIN_ONLY_SECTION_IDS, findUnavailableSection } from './sectionGating'import { SETTINGS_MAP } from './SettingsMap'import {FUSE_THRESHOLD,@@ -27,7 +28,15 @@ import {createSettingsSearchFuse,searchSettingsIndex,} from './settingsSearch'-import { Setting, SettingId, SettingLevelId, SettingSection, SettingSectionId, SettingsLogicProps } from './types'+import {+ Setting,+ SettingId,+ SettingLevelId,+ SettingSection,+ SettingSectionId,+ SettingsLogicProps,+ UnavailableSection,+} from './types'// Helping kea-typegen navigate the exported default class for Fuseexport interface SettingsFuse extends FuseClass<Setting & { searchValue: string }> {}@@ -74,6 +83,7 @@ const getSectionStringValue = (section: SettingSection): string => {export interface settingsLogicValues {billingEntryUrl: string | null // billingLogicfeatureFlags: FeatureFlagsSet // featureFlagLogic+ receivedFeatureFlags: boolean // featureFlagLogicorganizationIntegrations: IntegrationType[] | null // organizationIntegrationsLogiccurrentOrganization: OrganizationType | null // organizationLogicisAdminOrOwner: boolean | null // organizationLogic@@ -106,6 +116,7 @@ export interface settingsLogicValues {settingsFuse: SettingsFusesettingsSnapshot: Record<string, any> | nullsettingsSnapshotLoading: boolean+ unavailableSection: UnavailableSection | null}// Generated by kea-typegen. Update if you're an agent, ignore if you're human.@@ -207,6 +218,14 @@ export interface settingsLogicMeta {selectedSectionId: SettingSectionId | null,defaultSectionId: SettingSectionId | null) => SettingSection | null+ unavailableSection: (+ sections: SettingSection[],+ selectedSectionId: SettingSectionId | null,+ doesMatchFlags: (flagDefinition: Pick<Setting, 'flag'>) => boolean,+ isAdminOrOwner: boolean | null,+ receivedFeatureFlags: boolean,+ currentOrganization: OrganizationType | null+ ) => UnavailableSection | nullsettings: (selectedLevel: 'environment' | 'organization' | 'project' | 'user',selectedSectionId: SettingSectionId | null,@@ -255,7 +274,7 @@ export const settingsLogic = kea<settingsLogicType>([connect(() => ({values: [featureFlagLogic,- ['featureFlags'],+ ['featureFlags', 'receivedFeatureFlags'],userLogic,['hasAvailableFeature'],preflightLogic,@@ -496,10 +515,7 @@ export const settingsLogic = kea<settingsLogicType>([if (section.id === 'organization-billing' && !billingEntryUrl) {return false}- if (section.id === 'organization-legal-documents' && !isAdminOrOwner) {- return false- }- if (section.id === 'organization-access-resolution' && !isAdminOrOwner) {+ if (ADMIN_ONLY_SECTION_IDS.includes(section.id) && !isAdminOrOwner) {return false}@@ -590,6 +606,32 @@ export const settingsLogic = kea<settingsLogicType>([return sections.find((x) => x.id === effectiveId) ?? null},],+ unavailableSection: [+ (s) => [+ s.sections,+ s.selectedSectionId,+ s.doesMatchFlags,+ s.isAdminOrOwner,+ s.receivedFeatureFlags,+ s.currentOrganization,+ ],+ (+ sections: SettingSection[],+ selectedSectionId: SettingSectionId | null,+ doesMatchFlags: (flagDefinition: Pick<Setting, 'flag'>) => boolean,+ isAdminOrOwner: boolean | null,+ receivedFeatureFlags: boolean,+ currentOrganization: null | import('../../types').OrganizationType+ ): UnavailableSection | null =>+ findUnavailableSection({+ sectionId: selectedSectionId,+ visibleSections: sections,+ allSections: SETTINGS_MAP,+ gatesResolved: receivedFeatureFlags && !!currentOrganization?.membership_level,+ doesMatchFlags,+ isAdminOrOwner,+ }),+ ],settings: [(s) => [s.selectedLevel,diff --git a/frontend/src/scenes/settings/types.ts b/frontend/src/scenes/settings/types.tsindex 435e31d38e7e..3dad234807f7 100644--- a/frontend/src/scenes/settings/types.ts+++ b/frontend/src/scenes/settings/types.ts@@ -400,6 +400,20 @@ export interface SettingSection extends Pick<Setting, 'flag'> {* setting's component, which stacks one identical upsell card per setting on the page.*/payGate?: SettingSectionPayGate++ /**+ * Where to send a reader who cannot open this section, shown as the next step when the section+ * is gated off. `label` is user-facing copy.+ */+ unavailableFallback?: { sectionId: SettingSectionId; label: string }+}++/** Why a section the reader asked for is not there, and where to go instead. */+export interface UnavailableSection {+ id: SettingSectionId+ title: JSX.Element | string+ reason: 'not-enabled' | 'admin-only'+ fallback: { sectionId: SettingSectionId; label: string } | null}export interface SettingSectionPayGate {