: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(integrations): gate connecting an integration on project admin (#102998)
Tom Owers2ab60d3099f4
diff --git a/frontend/src/lib/components/CyclotronJob/integrations/IntegrationChoice.test.tsx b/frontend/src/lib/components/CyclotronJob/integrations/IntegrationChoice.test.tsxindex 6b9cf621b88f..dfc6cfb54cbd 100644--- a/frontend/src/lib/components/CyclotronJob/integrations/IntegrationChoice.test.tsx+++ b/frontend/src/lib/components/CyclotronJob/integrations/IntegrationChoice.test.tsx@@ -1,8 +1,12 @@+import { MOCK_DEFAULT_TEAM } from 'lib/api.mock'+import '@testing-library/jest-dom'import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'import { Provider } from 'kea'+import { OrganizationMembershipLevel } from 'lib/constants'+import { useMocks } from '~/mocks/jest'import { initKeaTests } from '~/test/init'import { IntegrationType } from '~/types'@@ -126,6 +130,26 @@ describe('IntegrationChoice', () => {expect(onChangeSecond).not.toHaveBeenCalled()})+ it('disables connecting for a member who cannot create integrations', async () => {+ // Creating an integration needs project admin, which is stricter than the access a product+ // needs to reach this picker. Members used to be sent through the provider's whole OAuth+ // flow only to have the callback fail to save the connection.+ initKeaTests(true, {+ ...MOCK_DEFAULT_TEAM,+ effective_membership_level: OrganizationMembershipLevel.Member,+ })++ render(+ <Provider>+ <IntegrationChoice integration="google-ads" onChange={jest.fn()} />+ </Provider>+ )++ fireEvent.click(await screen.findByText('Choose Google Ads connection'))+ const connect = await screen.findByText('Connect to Google Ads')+ expect(connect.closest('[aria-disabled]')).toHaveAttribute('aria-disabled', 'true')+ })+it('still warns when the stored id matches no integration', async () => {// Regression guard: a genuinely dangling reference must keep surfacing the banner.render(diff --git a/frontend/src/lib/components/CyclotronJob/integrations/IntegrationChoice.tsx b/frontend/src/lib/components/CyclotronJob/integrations/IntegrationChoice.tsxindex 880becd83f2b..764d75376c94 100644--- a/frontend/src/lib/components/CyclotronJob/integrations/IntegrationChoice.tsx+++ b/frontend/src/lib/components/CyclotronJob/integrations/IntegrationChoice.tsx@@ -8,6 +8,7 @@ import { IconExternal, IconTrash, IconX } from '@posthog/icons'import { LemonBanner, LemonButton, LemonMenu, LemonSkeleton } from '@posthog/lemon-ui'import api from 'lib/api'+import { useIntegrationManagementRestriction } from 'lib/integrations/integrationPermissions'import { integrationsLogic } from 'lib/integrations/integrationsLogic'import { IntegrationView } from 'lib/integrations/IntegrationView'import { getIntegrationNameFromKind } from 'lib/integrations/utils'@@ -41,6 +42,10 @@ export function IntegrationChoice({const { newGoogleCloudKey, openNewIntegrationModal, closeNewIntegrationModal, deleteIntegration } =useActions(integrationsLogic)const { reportIntegrationConnectClicked } = useActions(eventUsageLogic)+ // Creating an integration needs project admin, a stricter bar than the access a product needs+ // to reach this picker. Without the gate a member is sent through the provider's whole OAuth+ // flow and only finds out when the callback fails to save the connection.+ const integrationManagementRestriction = useIntegrationManagementRestriction()const kind = integration// Identifies this specific picker. Several IntegrationChoice pickers can share a kind (a@@ -105,7 +110,14 @@ export function IntegrationChoice({// 400s with "Kind not configured". Send users to the settings page instead.const oauthUnavailable = kind === 'slack' && !slackAvailableconst setupMenuItem = setupDef- ? setupDef.menuItem({ kind, openModal: (modalKind) => openNewIntegrationModal(modalKind, modalId), uploadKey })+ ? {+ ...setupDef.menuItem({+ kind,+ openModal: (modalKind) => openNewIntegrationModal(modalKind, modalId),+ uploadKey,+ }),+ disabledReason: integrationManagementRestriction ?? undefined,+ }: oauthUnavailable? {to: urls.settings('project-integrations'),@@ -123,6 +135,7 @@ export function IntegrationChoice({label: integrationsOfKind?.length? `Connect to a different integration for ${kindName}`: `Connect to ${kindName}`,+ disabledReason: integrationManagementRestriction ?? undefined,}const button = (