: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): let members connect setup-modal integrations (#105835)
Rossf87d083bf6ad
diff --git a/frontend/src/lib/components/CyclotronJob/integrations/IntegrationChoice.test.tsx b/frontend/src/lib/components/CyclotronJob/integrations/IntegrationChoice.test.tsxindex dfc6cfb54cbd..f1bfe8a4b62d 100644--- a/frontend/src/lib/components/CyclotronJob/integrations/IntegrationChoice.test.tsx+++ b/frontend/src/lib/components/CyclotronJob/integrations/IntegrationChoice.test.tsx@@ -130,10 +130,13 @@ 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.+ it.each([+ // An OAuth connect can land on an account that is already connected. That is an overwrite,+ // which the backend rejects for members after the whole provider flow.+ { kind: 'google-ads', kindName: 'Google Ads', connectLabel: 'Connect to Google Ads', disabled: true },+ // A setup-modal kind like S3 creates a new named integration, which members are allowed to do.+ { kind: 'aws-s3', kindName: 'AWS S3', connectLabel: 'Configure new AWS S3 connection', disabled: false },+ ])('for a member, connecting $kind is disabled: $disabled', async ({ kind, kindName, connectLabel, disabled }) => {initKeaTests(true, {...MOCK_DEFAULT_TEAM,effective_membership_level: OrganizationMembershipLevel.Member,@@ -141,13 +144,13 @@ describe('IntegrationChoice', () => {render(<Provider>- <IntegrationChoice integration="google-ads" onChange={jest.fn()} />+ <IntegrationChoice integration={kind} 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')+ fireEvent.click(await screen.findByText(`Choose ${kindName} connection`))+ const connect = await screen.findByText(connectLabel)+ expect(connect.closest('[aria-disabled="true"]') !== null).toBe(disabled)})it('still warns when the stored id matches no integration', async () => {diff --git a/frontend/src/lib/components/CyclotronJob/integrations/IntegrationChoice.tsx b/frontend/src/lib/components/CyclotronJob/integrations/IntegrationChoice.tsxindex 764d75376c94..b34afb03e761 100644--- a/frontend/src/lib/components/CyclotronJob/integrations/IntegrationChoice.tsx+++ b/frontend/src/lib/components/CyclotronJob/integrations/IntegrationChoice.tsx@@ -42,9 +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.+ // A project member can create an integration, but only a project admin can overwrite one. An+ // OAuth connect upserts on the provider account id, so a member who picks an account that is+ // already connected goes through the provider's whole flow and then gets a 403 at the callback.+ // Setup-modal kinds report the same error inside the modal, so they stay open to members.const integrationManagementRestriction = useIntegrationManagementRestriction()const kind = integration@@ -110,14 +111,7 @@ 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,- }),- disabledReason: integrationManagementRestriction ?? undefined,- }+ ? setupDef.menuItem({ kind, openModal: (modalKind) => openNewIntegrationModal(modalKind, modalId), uploadKey }): oauthUnavailable? {to: urls.settings('project-integrations'),diff --git a/frontend/src/lib/integrations/integrationPermissions.ts b/frontend/src/lib/integrations/integrationPermissions.tsindex a162a6a0a5ed..3954a00ad01c 100644--- a/frontend/src/lib/integrations/integrationPermissions.ts+++ b/frontend/src/lib/integrations/integrationPermissions.ts@@ -1,11 +1,12 @@import { RestrictionScope, useRestrictedArea } from 'lib/components/RestrictedArea'import { TeamMembershipLevel } from 'lib/constants'-// Single source of truth for "can the current user connect/reconnect integrations" on the frontend.-// Mirrors the backend IntegrationViewSet permission (TeamMemberStrictManagementPermission, which-// requires project-admin for writes). Returns a disabledReason string when the user lacks access,-// else null — wire it into the disabledReason of any connect/reconnect affordance so every-// integration gate stays in sync with the backend and with each other.+// Single source of truth for "can the current user overwrite an existing integration" on the frontend.+// The backend lets any project member create an integration, but IntegrationSerializer.create requires+// project admin to overwrite one (the creator of a Google Calendar connection is the only exception).+// Returns a disabledReason string when the user lacks access, else null. Wire it into the+// disabledReason of any affordance that can overwrite an integration, such as a reconnect or an OAuth+// connect that can land on an account that is already connected, so these gates stay in sync.export function useIntegrationManagementRestriction(): string | null {return useRestrictedArea({scope: RestrictionScope.Project,