: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(homepage): show the legal dialog before approving ai (#111055)
Matt Brookerb791032ae232
diff --git a/frontend/src/scenes/project-homepage/ai-first/HomepageInput.test.tsx b/frontend/src/scenes/project-homepage/ai-first/HomepageInput.test.tsxindex 10265ee90d0f..6a36dfb5d794 100644--- a/frontend/src/scenes/project-homepage/ai-first/HomepageInput.test.tsx+++ b/frontend/src/scenes/project-homepage/ai-first/HomepageInput.test.tsx@@ -19,6 +19,7 @@ jest.mock('scenes/max/components/SidebarQuestionInput', () => ({describe('HomepageAiInput', () => {const APPROVE_LABEL = 'I allow AI analysis in this organization'+ const patchOrganization = jest.fn()function renderInput(membershipLevel: OrganizationMembershipLevel): HTMLElement {initKeaTests(true, undefined, undefined, {@@ -36,15 +37,19 @@ describe('HomepageAiInput', () => {}beforeEach(() => {+ patchOrganization.mockClear()useMocks({patch: {- '/api/organizations/:id': async ({ request }) => [- 200,- {- ...MOCK_DEFAULT_ORGANIZATION,- ...((await request.json()) as Partial<typeof MOCK_DEFAULT_ORGANIZATION>),- },- ],+ '/api/organizations/:id': async ({ request }) => {+ patchOrganization()+ return [+ 200,+ {+ ...MOCK_DEFAULT_ORGANIZATION,+ ...((await request.json()) as Partial<typeof MOCK_DEFAULT_ORGANIZATION>),+ },+ ]+ },},post: {'/api/organizations/:id/request_ai_access/': () => [200, { success: true }],@@ -54,14 +59,24 @@ describe('HomepageAiInput', () => {afterEach(cleanup)- it('approves AI data processing and swaps in the composer when the button is clicked', async () => {+ it('approves AI data processing once, and only after the admin confirms the BAA disclaimer', async () => {const container = renderInput(OrganizationMembershipLevel.Admin)fireEvent.click(screen.getByText(APPROVE_LABEL))+ fireEvent.click(await screen.findByText('Cancel'))+ await waitFor(() => expect(screen.queryByText(/Business Associate Agreement/)).toBeNull())+ expect(patchOrganization).not.toHaveBeenCalled()++ fireEvent.click(screen.getByText(APPROVE_LABEL))+ expect(await screen.findByText(/Business Associate Agreement/)).toBeTruthy()+ const confirmButton = screen.getByText('Enable AI analysis')+ fireEvent.click(confirmButton)+ fireEvent.click(confirmButton)await waitFor(() =>expect(organizationLogic.values.currentOrganization?.is_ai_data_processing_approved).toBe(true))+ expect(patchOrganization).toHaveBeenCalledTimes(1)expect(container.querySelector('[data-attr="mock-question-input"]')).toBeTruthy()})diff --git a/frontend/src/scenes/project-homepage/ai-first/HomepageInput.tsx b/frontend/src/scenes/project-homepage/ai-first/HomepageInput.tsxindex de1eb21a1868..92c5f427fc5e 100644--- a/frontend/src/scenes/project-homepage/ai-first/HomepageInput.tsx+++ b/frontend/src/scenes/project-homepage/ai-first/HomepageInput.tsx@@ -24,6 +24,7 @@ import { maxLogic } from 'scenes/max/maxLogic'import { MaxThreadLogicProps, maxThreadLogic } from 'scenes/max/maxThreadLogic'import { HOMEPAGE_SUGGESTION_TOPICS } from 'scenes/max/suggestionTopics'import { AIAccessRequest } from 'scenes/settings/organization/AIAccessRequest'+import { openAIConsentLegalDialog } from 'scenes/settings/organization/aiConsentCopy'import { aiConsentLogic } from 'scenes/settings/organization/aiConsentLogic'import { userLogic } from 'scenes/userLogic'@@ -199,7 +200,6 @@ export function HomepageAiInput(): JSX.Element {const { threadLogicKey, conversation } = useValues(maxLogic)const { dataProcessingAccepted, dataProcessingApprovalDisabledReason } = useValues(maxGlobalLogic)const { acceptDataProcessing } = useAsyncActions(aiConsentLogic)- const [approving, setApproving] = useState(false)const fallbackConversationId = useMemo(() => uuid(), [])const threadProps: MaxThreadLogicProps = {@@ -222,13 +222,7 @@ export function HomepageAiInput(): JSX.Element {<LemonButtontype="primary"size="small"- loading={approving}- onClick={() => {- setApproving(true)- void acceptDataProcessing()- .catch(console.error)- .finally(() => setApproving(false))- }}+ onClick={() => openAIConsentLegalDialog({ onConfirm: () => acceptDataProcessing() })}sideIcon={<IconArrowRight />}>I allow AI analysis in this organizationdiff --git a/frontend/src/scenes/settings/organization/AIConsentPopoverWrapper.tsx b/frontend/src/scenes/settings/organization/AIConsentPopoverWrapper.tsxindex babacc921dd7..bdad5cbf7f88 100644--- a/frontend/src/scenes/settings/organization/AIConsentPopoverWrapper.tsx+++ b/frontend/src/scenes/settings/organization/AIConsentPopoverWrapper.tsx@@ -16,7 +16,7 @@ export function AIConsentPopoverContent({approvalDisabledReason,hideTrainingDisclaimer,}: {- onApprove: () => void+ onApprove: () => void | Promise<void>onDismiss: () => voidapprovalDisabledReason: string | null/** Omit the "won't be used for training third-party models" line where it doesn't apply. */@@ -116,7 +116,7 @@ export function AIConsentPopoverWrapper({<AIConsentPopoverContentapprovalDisabledReason={dataProcessingApprovalDisabledReason}hideTrainingDisclaimer={hideTrainingDisclaimer}- onApprove={() => {+ onApprove={async () => {if (pendingRedirectUrl && currentOrganization) {// Cleared by the acceptDataProcessing listener on success or failure.setPendingApprovalRedirect({@@ -125,9 +125,8 @@ export function AIConsentPopoverWrapper({setAt: Date.now(),})}- void acceptDataProcessing()- .then(() => onApprove?.())- .catch(console.error)+ await acceptDataProcessing()+ onApprove?.()}}onDismiss={handleDismiss}/>diff --git a/frontend/src/scenes/settings/organization/aiConsentCopy.tsx b/frontend/src/scenes/settings/organization/aiConsentCopy.tsxindex 873f1cd2d62a..128931bcfb74 100644--- a/frontend/src/scenes/settings/organization/aiConsentCopy.tsx+++ b/frontend/src/scenes/settings/organization/aiConsentCopy.tsx@@ -17,10 +17,11 @@ export function AIHipaaDisclaimer(): JSX.Element {)}-export function aiConsentLegalDialogProps({ onConfirm }: { onConfirm: () => void }): LemonDialogProps {+export function aiConsentLegalDialogProps({ onConfirm }: { onConfirm: () => void | Promise<void> }): LemonDialogProps {return {title: 'The legal bits',maxWidth: '65ch',+ shouldAwaitSubmit: true,content: (<div className="flex flex-col gap-2"><p className="mb-0">@@ -37,7 +38,7 @@ export function aiConsentLegalDialogProps({ onConfirm }: { onConfirm: () => voidprimaryButton: {children: 'Enable AI analysis','data-attr': 'ai-consent-legal-confirm',- onClick: onConfirm,+ onClick: () => onConfirm(),},secondaryButton: {children: 'Cancel',@@ -46,6 +47,6 @@ export function aiConsentLegalDialogProps({ onConfirm }: { onConfirm: () => void}}-export function openAIConsentLegalDialog(args: { onConfirm: () => void }): void {+export function openAIConsentLegalDialog(args: { onConfirm: () => void | Promise<void> }): void {LemonDialog.open(aiConsentLegalDialogProps(args))}