: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(posthog-ai): unblock non-admins at the AI consent gate (#92249)
Georgiy Tarasov00baf9b66a2d
diff --git a/frontend/src/scenes/project-homepage/ai-first/HomepageInput.test.tsx b/frontend/src/scenes/project-homepage/ai-first/HomepageInput.test.tsxindex a42c0936b0fc..238580526e3c 100644--- a/frontend/src/scenes/project-homepage/ai-first/HomepageInput.test.tsx+++ b/frontend/src/scenes/project-homepage/ai-first/HomepageInput.test.tsx@@ -3,6 +3,7 @@ import { MOCK_DEFAULT_ORGANIZATION } from 'lib/api.mock'import { fireEvent, render, screen, waitFor } from '@testing-library/react'import { BindLogic } from 'kea'+import { OrganizationMembershipLevel } from 'lib/constants'import { maxLogic } from 'scenes/max/maxLogic'import { organizationLogic } from 'scenes/organizationLogic'@@ -28,6 +29,14 @@ describe('HomepageAiInput', () => {return container}+ function setUpOrganization(membershipLevel: OrganizationMembershipLevel): void {+ initKeaTests(true, undefined, undefined, {+ ...MOCK_DEFAULT_ORGANIZATION,+ is_ai_data_processing_approved: false,+ membership_level: membershipLevel,+ })+ }+beforeEach(() => {useMocks({patch: {@@ -39,11 +48,11 @@ describe('HomepageAiInput', () => {},],},+ post: {+ '/api/organizations/:id/request_ai_access/': () => [200, { success: true }],+ },})- initKeaTests(true, undefined, undefined, {- ...MOCK_DEFAULT_ORGANIZATION,- is_ai_data_processing_approved: false,- })+ setUpOrganization(OrganizationMembershipLevel.Admin)})it('approves AI data processing and swaps in the composer when the button is clicked', async () => {@@ -56,4 +65,14 @@ describe('HomepageAiInput', () => {)expect(container.querySelector('[data-attr="mock-question-input"]')).toBeTruthy()})++ it('lets a member ask an admin to approve, instead of dead-ending on the disabled reason', async () => {+ setUpOrganization(OrganizationMembershipLevel.Member)+ renderInput()++ expect(screen.queryByText(APPROVE_LABEL)).toBeNull()+ fireEvent.click(screen.getByText('Request access'))++ await waitFor(() => expect(screen.getByText(/Request sent\./)).toBeTruthy())+ })})diff --git a/frontend/src/scenes/project-homepage/ai-first/HomepageInput.tsx b/frontend/src/scenes/project-homepage/ai-first/HomepageInput.tsxindex a5f36a39578a..a8e002150c3f 100644--- a/frontend/src/scenes/project-homepage/ai-first/HomepageInput.tsx+++ b/frontend/src/scenes/project-homepage/ai-first/HomepageInput.tsx@@ -3,7 +3,7 @@ import { router } from 'kea-router'import posthog from 'posthog-js'import { useCallback, useEffect, useMemo, useRef, useState } from 'react'-import { IconArrowRight, IconClock, IconInfo, IconLock, IconMicrophone, IconPin, IconStar } from '@posthog/icons'+import { IconArrowRight, IconClock, IconInfo, IconMicrophone, IconPin, IconStar } from '@posthog/icons'import { LemonButton, LemonSkeleton, Tooltip } from '@posthog/lemon-ui'import { Search } from 'lib/components/Search/Search'@@ -27,6 +27,7 @@ import { HOMEPAGE_CAPABILITIES } from 'scenes/max/maxCapabilities'import { maxGlobalLogic } from 'scenes/max/maxGlobalLogic'import { maxLogic } from 'scenes/max/maxLogic'import { MaxThreadLogicProps, maxThreadLogic } from 'scenes/max/maxThreadLogic'+import { AIAccessRequest } from 'scenes/settings/organization/AIAccessRequest'import { aiConsentLogic } from 'scenes/settings/organization/aiConsentLogic'import { userLogic } from 'scenes/userLogic'@@ -208,8 +209,9 @@ export function HomepageAiInput(): JSX.Element {return (<div className="border border-primary rounded-lg bg-surface-primary p-4 flex flex-col gap-2"><p className="font-medium text-pretty m-0">- PostHog AI needs your approval to potentially process identifying user data with external AI- providers.+ {isAdmin+ ? 'PostHog AI needs your approval to potentially process identifying user data with external AI providers.'+ : 'PostHog AI needs an organization admin to approve processing identifying user data with external AI providers.'}</p><p className="text-muted text-xs m-0">Your data won't be used for training third-party models.</p>{isAdmin ? (@@ -228,9 +230,9 @@ export function HomepageAiInput(): JSX.Element {I allow AI analysis in this organization</LemonButton>) : (- <LemonButton type="secondary" size="small" disabled sideIcon={<IconLock />}>- {dataProcessingApprovalDisabledReason}- </LemonButton>+ <div className="flex">+ <AIAccessRequest size="small" />+ </div>)}</div>)diff --git a/frontend/src/scenes/settings/organization/AIAccessRequest.tsx b/frontend/src/scenes/settings/organization/AIAccessRequest.tsxnew file mode 100644index 000000000000..85b35de21849--- /dev/null+++ b/frontend/src/scenes/settings/organization/AIAccessRequest.tsx@@ -0,0 +1,39 @@+import { useActions, useValues } from 'kea'++import { IconArrowRight, IconCheck } from '@posthog/icons'+import { LemonButton } from '@posthog/lemon-ui'++import { aiConsentLogic } from './aiConsentLogic'++/**+ * The path forward for a member who cannot approve AI data processing themselves: ask an+ * organization admin to do it. Shared by every surface that gates on consent, so a non-admin gets+ * the same working affordance wherever the gate appears.+ */+export function AIAccessRequest({ size = 'xsmall' }: { size?: 'xsmall' | 'small' }): JSX.Element {+ const { requestingAiAccess, aiAccessRequested } = useValues(aiConsentLogic)+ const { requestAiAccess } = useActions(aiConsentLogic)++ // An inline confirmation rather than a spent button, so a repeat visit reads as "already asked".+ if (aiAccessRequested) {+ return (+ <p className="flex items-start gap-1.5 m-0 text-xs text-muted">+ <IconCheck className="shrink-0 mt-0.5 text-success" />+ <span>Request sent. Your organization admins have been notified and can enable PostHog AI.</span>+ </p>+ )+ }++ return (+ <LemonButton+ data-attr="ai-access-request"+ type="primary"+ size={size}+ onClick={() => requestAiAccess()}+ loading={requestingAiAccess}+ sideIcon={<IconArrowRight />}+ >+ Request access+ </LemonButton>+ )+}diff --git a/frontend/src/scenes/settings/organization/AIConsentPopoverWrapper.tsx b/frontend/src/scenes/settings/organization/AIConsentPopoverWrapper.tsxindex 7f67bde41f3d..babacc921dd7 100644--- a/frontend/src/scenes/settings/organization/AIConsentPopoverWrapper.tsx+++ b/frontend/src/scenes/settings/organization/AIConsentPopoverWrapper.tsx@@ -1,11 +1,12 @@import { useActions, useAsyncActions, useValues } from 'kea'import { useCallback } from 'react'-import { IconArrowRight, IconCheck, IconLock } from '@posthog/icons'+import { IconArrowRight, IconLock } from '@posthog/icons'import { LemonButton, Popover, PopoverProps, Tooltip } from '@posthog/lemon-ui'import { organizationLogic } from 'scenes/organizationLogic'+import { AIAccessRequest } from './AIAccessRequest'import { getExternalAIProvidersTooltipTitle, openAIConsentLegalDialog } from './aiConsentCopy'import { aiConsentLogic } from './aiConsentLogic'@@ -57,9 +58,6 @@ export function AIConsentPopoverContent({}function AIAccessRequestPopoverContent(): JSX.Element {- const { requestingAiAccess, aiAccessRequested } = useValues(aiConsentLogic)- const { requestAiAccess } = useActions(aiConsentLogic)-return (<div className="flex flex-col gap-2 m-1.5 max-w-prose"><p className="font-medium text-pretty">@@ -67,17 +65,7 @@ function AIAccessRequestPopoverContent(): JSX.Element {organization owner or admin.</p><div className="flex self-end">- <LemonButton- data-attr="ai-access-request"- type="primary"- size="xsmall"- onClick={() => requestAiAccess()}- loading={requestingAiAccess}- disabledReason={aiAccessRequested ? 'Your request has been sent' : undefined}- sideIcon={aiAccessRequested ? <IconCheck /> : <IconArrowRight />}- >- {aiAccessRequested ? 'Request sent' : 'Request access'}- </LemonButton>+ <AIAccessRequest /></div></div>)diff --git a/frontend/src/scenes/settings/organization/aiConsentLogic.ts b/frontend/src/scenes/settings/organization/aiConsentLogic.tsindex 66247d880022..b12b780d745a 100644--- a/frontend/src/scenes/settings/organization/aiConsentLogic.ts+++ b/frontend/src/scenes/settings/organization/aiConsentLogic.ts@@ -1,5 +1,6 @@import { MakeLogicType, actions, connect, events, kea, listeners, path, reducers, selectors } from 'kea'import { router } from 'kea-router'+import posthog from 'posthog-js'import { LOOKAHEAD_EXPIRY_SECONDS } from 'lib/components/TimeSensitiveAuthentication/timeSensitiveAuthenticationLogic'import { OrganizationMembershipLevel } from 'lib/constants'@@ -135,6 +136,9 @@ export const aiConsentLogic = kea<aiConsentLogicType>([}),listeners(({ actions, values }) => ({acceptDataProcessing: async ({ testOnlyOverride, resumeUrl }) => {+ // Attempt and outcome are captured separately so a gate that accepts clicks but never+ // approves shows up as a gap between the two, rather than only in a session recording.+ posthog.capture('ai_consent_approval_submitted', { is_resumed: !!resumeUrl })try {await organizationLogic.asyncActions.updateOrganization({is_ai_data_processing_approved: testOnlyOverride ?? true,@@ -142,9 +146,11 @@ export const aiConsentLogic = kea<aiConsentLogicType>([} catch (error) {// A real failure (a lost SSO redirect unloads the page instead of rejecting).actions.setPendingApprovalRedirect(null)+ posthog.capture('ai_consent_approval_failed')throw error}actions.setPendingApprovalRedirect(null)+ posthog.capture('ai_consent_approved')lemonToast.success('AI data processing approved')if (resumeUrl) {router.actions.push(resumeUrl)@@ -156,14 +162,17 @@ export const aiConsentLogic = kea<aiConsentLogicType>([actions.requestAiAccessError()return}+ posthog.capture('ai_access_request_submitted')try {// Backend notifies the org admins/owners via a customer.io email — keeps the// recipient resolution server-side so it can't be tampered with from the client.await requestAiAccessCreate(organization.id)actions.markAiAccessRequested(organization.id)+ posthog.capture('ai_access_requested')lemonToast.success('Request sent to your organization admins')} catch {actions.requestAiAccessError()+ posthog.capture('ai_access_request_failed')lemonToast.error('Could not send your request. Please try again.')}},diff --git a/products/replay_vision/frontend/replay_scanners/ScannerEditorScene.tsx b/products/replay_vision/frontend/replay_scanners/ScannerEditorScene.tsxindex 32e6ca89458e..1b8743186e58 100644--- a/products/replay_vision/frontend/replay_scanners/ScannerEditorScene.tsx+++ b/products/replay_vision/frontend/replay_scanners/ScannerEditorScene.tsx@@ -479,11 +479,12 @@ function EditorFooter({const { scanner, durationValidationError, hasUnsavedChanges } = useValues(replayScannerLogic({ id: scannerId }))const { searchParams } = useValues(router)const { discardScannerDraft } = useActions(replayScannerLogic({ id: scannerId }))- const { dataProcessingAccepted } = useValues(aiConsentLogic)+ const { dataProcessingAccepted, dataProcessingApprovalDisabledReason } = useValues(aiConsentLogic)const [consentRequested, setConsentRequested] = useState(false)// The backend rejects scanner creation without org AI consent, so the popover interposes at// Save instead of letting the request 400.const needsConsent = isNew && !dataProcessingAccepted+ const canApproveConsent = !dataProcessingApprovalDisabledReasonconst stepIndex = SCANNER_EDITOR_STEPS.indexOf(step)const previous = stepIndex > 0 ? SCANNER_EDITOR_STEPS[stepIndex - 1] : nullconst prevStep = previous === 'template' && !isNew ? null : previous@@ -594,7 +595,9 @@ function EditorFooter({data-ph-capture-attribute-scanner-type={scanner?.scanner_type}>{needsConsent- ? 'Allow AI analysis and create scanner'+ ? canApproveConsent+ ? 'Allow AI analysis and create scanner'+ : 'Ask an admin to enable AI analysis': isNew? 'Create scanner': 'Save changes'}diff --git a/products/replay_vision/frontend/replay_scanners/components/CreateScannerButton.tsx b/products/replay_vision/frontend/replay_scanners/components/CreateScannerButton.tsxindex b797b4381863..e5d1bd59bbd9 100644--- a/products/replay_vision/frontend/replay_scanners/components/CreateScannerButton.tsx+++ b/products/replay_vision/frontend/replay_scanners/components/CreateScannerButton.tsx@@ -25,21 +25,30 @@ export function CreateScannerButton({dataAttr: stringsize?: 'small' | 'medium'}): JSX.Element {- const { dataProcessingAccepted } = useValues(aiConsentLogic)+ const { dataProcessingAccepted, dataProcessingApprovalDisabledReason } = useValues(aiConsentLogic)const { push } = useActions(router)const [consentRequested, setConsentRequested] = useState(false)const goToCreate = (): void => push(urls.replayVisionTemplates())+ // A member cannot allow anything, so don't label the CTA as if they can. Clicking still opens+ // the popover, where their actual next step is to ask an admin.+ const canApproveConsent = !dataProcessingApprovalDisabledReason+ const label = dataProcessingAccepted+ ? acceptedLabel+ : canApproveConsent+ ? 'Allow AI analysis and create scanner'+ : 'Ask an admin to enable AI analysis'+const button = (<LemonButtontype="primary"size={size}- icon={<IconPlus />}+ icon={dataProcessingAccepted || canApproveConsent ? <IconPlus /> : undefined}disabledReason={getReplayVisionEditDisabledReason()}data-attr={dataAttr}onClick={() => (dataProcessingAccepted ? goToCreate() : setConsentRequested(true))}>- {dataProcessingAccepted ? acceptedLabel : 'Allow AI analysis and create scanner'}+ {label}</LemonButton>)