: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(impersonation): surface read-only block reason in toast (#66662)
Jovan Sakovic48575b8267c1
diff --git a/frontend/src/lib/logic/apiStatusLogic.test.ts b/frontend/src/lib/logic/apiStatusLogic.test.tsindex c26742896847..326055518bda 100644--- a/frontend/src/lib/logic/apiStatusLogic.test.ts+++ b/frontend/src/lib/logic/apiStatusLogic.test.ts@@ -2,6 +2,8 @@ import { MOCK_DEFAULT_ORGANIZATION, MOCK_DEFAULT_USER } from 'lib/api.mock'import { expectLogic } from 'kea-test-utils'+import { lemonToast } from '@posthog/lemon-ui'+import { userLogic } from 'scenes/userLogic'import { useMocks } from '~/mocks/jest'@@ -74,4 +76,48 @@ describe('apiStatusLogic', () => {logoutSpy.mockRestore()})})++ describe('read-only impersonation 403 handling', () => {+ const READ_ONLY_DETAIL = 'This action is not allowed during read-only user impersonation.'++ it('surfaces the block reason as a toast', async () => {+ initKeaTests()+ logic = apiStatusLogic()+ logic.mount()++ const errorSpy = jest.spyOn(lemonToast, 'error').mockReturnValue('toast-id')+ const mockResponse = {+ status: 403,+ ok: false,+ json: () => Promise.resolve({ code: 'impersonation_read_only', detail: READ_ONLY_DETAIL }),+ } as unknown as Response++ await expectLogic(logic, () => {+ logic.actions.onApiResponse(mockResponse)+ }).toFinishAllListeners()++ expect(errorSpy).toHaveBeenCalledWith(READ_ONLY_DETAIL, { hideButton: true })+ errorSpy.mockRestore()+ })++ it('does not toast for unrelated 403s', async () => {+ initKeaTests()+ logic = apiStatusLogic()+ logic.mount()++ const errorSpy = jest.spyOn(lemonToast, 'error').mockReturnValue('toast-id')+ const mockResponse = {+ status: 403,+ ok: false,+ json: () => Promise.resolve({ code: 'permission_denied', detail: 'Nope' }),+ } as unknown as Response++ await expectLogic(logic, () => {+ logic.actions.onApiResponse(mockResponse)+ }).toFinishAllListeners()++ expect(errorSpy).not.toHaveBeenCalled()+ errorSpy.mockRestore()+ })+ })})diff --git a/frontend/src/lib/logic/apiStatusLogic.ts b/frontend/src/lib/logic/apiStatusLogic.tsindex 4354922d3c21..9c276e08e3c1 100644--- a/frontend/src/lib/logic/apiStatusLogic.ts+++ b/frontend/src/lib/logic/apiStatusLogic.ts@@ -85,6 +85,13 @@ export const apiStatusLogic = kea<apiStatusLogicType>([autoClose: false,})+ } else if (responseData.code === 'impersonation_read_only') {+ lemonToast.error(+ typeof responseData.detail === 'string' && responseData.detail+ ? responseData.detail+ : 'This action is not allowed during read-only user impersonation.',+ { hideButton: true }+ )}}} catch {