: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(data-warehouse): tell members without access why the source list won't load (#125243)
Tom Owers88af524d6d14
diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/NewSourceScene.tsx b/products/data_warehouse/frontend/scenes/NewSourceScene/NewSourceScene.tsxindex c095c10b5e1e..9994bdd6b3a4 100644--- a/products/data_warehouse/frontend/scenes/NewSourceScene/NewSourceScene.tsx+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/NewSourceScene.tsx@@ -129,8 +129,18 @@ export function NewSourceScene(): JSX.Element {// access). Without this the scene keeps rendering a bare skeleton indefinitely, which reads// as a permanently stuck loading state.export function AvailableSourcesError(): JSX.Element {+ const { availableSourcesForbidden } = useValues(availableSourcesLogic)const { load } = useActions(availableSourcesLogic)+ if (availableSourcesForbidden) {+ return (+ <LemonBanner type="info">+ You don't have permission to connect a data warehouse source. Ask a project admin for editor access to+ data warehouse sources.+ </LemonBanner>+ )+ }+return (<LemonBannertype="error"@@ -142,10 +152,7 @@ export function AvailableSourcesError(): JSX.Element {}}><p className="font-semibold mb-1">Couldn't load the list of available sources</p>- <p className="m-0">- This can happen if the request timed out or you don't have permission to manage data sources in this- project. Try again, or ask an organization admin to check your access.- </p>+ <p className="m-0">The request may have timed out. Try again, and contact support if it keeps failing.</p></LemonBanner>)}diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/availableSourcesLogic.test.ts b/products/data_warehouse/frontend/scenes/NewSourceScene/availableSourcesLogic.test.tsnew file mode 100644index 000000000000..bd45bf089805--- /dev/null+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/availableSourcesLogic.test.ts@@ -0,0 +1,44 @@+import { expectLogic } from 'kea-test-utils'++import api from 'lib/api'++import { initKeaTests } from '~/test/init'++import { availableSourcesLogic } from './availableSourcesLogic'++jest.mock('lib/api')++describe('availableSourcesLogic', () => {+ beforeEach(() => {+ initKeaTests()+ })++ it.each([+ [403, true],+ [500, false],+ ])('marks a %s from the wizard endpoint as forbidden: %s', async (status, forbidden) => {+ jest.spyOn(api.externalDataSources, 'wizard').mockRejectedValue({ status })++ const logic = availableSourcesLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners().toMatchValues({+ availableSources: null,+ availableSourcesLoading: false,+ availableSourcesForbidden: forbidden,+ })+ logic.unmount()+ })++ it('clears forbidden when a later load succeeds', async () => {+ jest.spyOn(api.externalDataSources, 'wizard').mockRejectedValueOnce({ status: 403 })++ const logic = availableSourcesLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners().toMatchValues({ availableSourcesForbidden: true })++ jest.spyOn(api.externalDataSources, 'wizard').mockResolvedValueOnce({} as any)+ logic.actions.load()+ await expectLogic(logic).toFinishAllListeners().toMatchValues({ availableSourcesForbidden: false })+ logic.unmount()+ })+})diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/availableSourcesLogic.ts b/products/data_warehouse/frontend/scenes/NewSourceScene/availableSourcesLogic.tsindex 0f0f4f341b05..9caa6d5c5619 100644--- a/products/data_warehouse/frontend/scenes/NewSourceScene/availableSourcesLogic.ts+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/availableSourcesLogic.ts@@ -1,4 +1,4 @@-import { MakeLogicType, afterMount, kea, path } from 'kea'+import { MakeLogicType, actions, afterMount, kea, path, reducers } from 'kea'import { loaders } from 'kea-loaders'import api from 'lib/api'@@ -10,6 +10,7 @@ import type { SourceConfigMapResponseApi } from '../../../../warehouse_sources/f// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface availableSourcesLogicValues {availableSources: Record<string, SourceConfigResponseApi> | null+ availableSourcesForbidden: booleanavailableSourcesLoading: boolean}@@ -30,13 +31,19 @@ export interface availableSourcesLogicActions {availableSources: SourceConfigMapResponseApi | nullpayload?: any}+ setAvailableSourcesForbidden: (forbidden: boolean) => {+ forbidden: boolean+ }}export type availableSourcesLogicType = MakeLogicType<availableSourcesLogicValues, availableSourcesLogicActions>export const availableSourcesLogic = kea<availableSourcesLogicType>([path(['products', 'dataWarehouse', 'availableSourcesLogic']),- loaders({+ actions({+ setAvailableSourcesForbidden: (forbidden: boolean) => ({ forbidden }),+ }),+ loaders(({ actions }) => ({availableSources: [null as Record<string, SourceConfigResponseApi> | null,{@@ -45,6 +52,7 @@ export const availableSourcesLogic = kea<availableSourcesLogicType>([return await api.externalDataSources.wizard()} catch (e: any) {if (e.status === 403) {+ actions.setAvailableSourcesForbidden(true)return null}throw e@@ -52,6 +60,16 @@ export const availableSourcesLogic = kea<availableSourcesLogicType>([},},],+ })),+ reducers({+ // Retrying can't fix a 403, so the error state needs to tell it apart from a timeout or 5xx.+ availableSourcesForbidden: [+ false,+ {+ setAvailableSourcesForbidden: (_, { forbidden }) => forbidden,+ load: () => false,+ },+ ],}),afterMount(({ actions }) => {actions.load()