Skip to content

: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.

fix(customer-analytics): let members manage warehouse properties (#111749)

Jovan Sakovicc0074d88c623
diff --git a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/WarehousePersonPropertiesSetting.test.tsx b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/WarehousePersonPropertiesSetting.test.tsx
new file mode 100644
index 000000000000..2eda1b68c95d
--- /dev/null
+++ b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/WarehousePersonPropertiesSetting.test.tsx
@@ -0,0 +1,139 @@
+import '@testing-library/jest-dom'
+
+import { cleanup, render } from '@testing-library/react'
+import { useActions, useValues } from 'kea'
+
+import { useRestrictedArea } from 'lib/components/RestrictedArea'
+import { TeamMembershipLevel } from 'lib/constants'
+
+import { AccessControlLevel, AccessControlResourceType, AppContext } from '~/types'
+
+import { CustomPropertyDisplayTypeEnumApi } from 'products/customer_analytics/frontend/generated/api.schemas'
+import type {
+ CustomPropertyDefinitionApi,
+ CustomPropertySourceApi,
+} from 'products/customer_analytics/frontend/generated/api.schemas'
+
+import { WarehousePersonPropertiesSetting } from './WarehousePersonPropertiesSetting'
+
+jest.mock('kea', () => ({ ...jest.requireActual('kea'), useActions: jest.fn(), useValues: jest.fn() }))
+jest.mock('lib/components/RestrictedArea', () => ({
+ RestrictionScope: { Project: 'project' },
+ useRestrictedArea: jest.fn(),
+}))
+jest.mock('./CustomPropertyModal', () => ({ CustomPropertyModal: () => null }))
+
+describe('WarehousePersonPropertiesSetting', () => {
+ const EDIT_ACTIONS = [
+ 'add-warehouse-profile-property',
+ 'sync-warehouse-profile-property',
+ 'backfill-warehouse-profile-property',
+ 'edit-warehouse-profile-property',
+ ]
+ const DELETE_ACTION = 'delete-warehouse-profile-property'
+
+ // A source the sync and backfill buttons can act on — without one they're disabled whatever
+ // the caller's access level is, and the permission assertions would pass vacuously.
+ const source: CustomPropertySourceApi = {
+ id: 'source-1',
+ definition: 'definition-1',
+ saved_query: null,
+ external_data_schema: 'schema-1',
+ column_property_map: { plan: 'plan_tier' },
+ key_column: 'distinct_id',
+ is_enabled: true,
+ consecutive_failures: 0,
+ last_synced_at: '2026-01-01T00:00:00Z',
+ last_sync_error: null,
+ created_at: '2026-01-01T00:00:00Z',
+ created_by: 1,
+ updated_at: null,
+ sync_frequency_interval_seconds: 3600,
+ next_sync_at: '2026-01-01T01:00:00Z',
+ latest_run: null,
+ external_data_source: 'warehouse-source-1',
+ table_name: 'stripe_customers',
+ saved_query_name: null,
+ }
+ const propertyDefinition: CustomPropertyDefinitionApi = {
+ id: 'definition-1',
+ name: 'Plan tier',
+ description: null,
+ display_type: CustomPropertyDisplayTypeEnumApi.Text,
+ is_big_number: false,
+ target_type: 'person',
+ group_type_index: null,
+ is_canonical: false,
+ options: null,
+ source,
+ created_at: '2026-01-01T00:00:00Z',
+ created_by: 1,
+ updated_at: null,
+ references: [],
+ has_workflow_reference: false,
+ }
+
+ let previousAppContext: AppContext | undefined
+
+ const isDisabled = (dataAttr: string): boolean =>
+ document.querySelector(`[data-attr="${dataAttr}"]`)!.getAttribute('aria-disabled') === 'true'
+
+ beforeEach(() => {
+ previousAppContext = window.POSTHOG_APP_CONTEXT
+ ;(useValues as jest.Mock).mockReturnValue({
+ definitions: [propertyDefinition],
+ definitionsInitialLoading: false,
+ triggeringSourceIds: [],
+ runsBySourceId: {},
+ runsCountBySourceId: {},
+ runsOffsetBySourceId: {},
+ runsSearchBySourceId: {},
+ runsLoadingBySourceId: {},
+ runsLoadFailedBySourceId: {},
+ })
+ ;(useActions as jest.Mock).mockReturnValue({
+ openCreateModal: jest.fn(),
+ openEditModal: jest.fn(),
+ deleteDefinition: jest.fn(),
+ triggerSync: jest.fn(),
+ triggerBackfill: jest.fn(),
+ setRunsSearch: jest.fn(),
+ loadRuns: jest.fn(),
+ })
+ })
+
+ afterEach(() => {
+ cleanup()
+ window.POSTHOG_APP_CONTEXT = previousAppContext
+ })
+
+ test.each([
+ {
+ caller: 'project member with Customer analytics editor access',
+ membershipLevel: TeamMembershipLevel.Member,
+ resourceLevel: AccessControlLevel.Editor,
+ disabledActions: [DELETE_ACTION],
+ },
+ {
+ // Runs as an admin on purpose: the admin gate would otherwise mask a missing editor
+ // check on delete.
+ caller: 'project admin without Customer analytics editor access',
+ membershipLevel: TeamMembershipLevel.Admin,
+ resourceLevel: AccessControlLevel.Viewer,
+ disabledActions: [...EDIT_ACTIONS, DELETE_ACTION],
+ },
+ ])('gates the warehouse property actions for a $caller', ({ membershipLevel, resourceLevel, disabledActions }) => {
+ ;(useRestrictedArea as jest.Mock).mockImplementation(
+ ({ minimumAccessLevel }: { minimumAccessLevel: TeamMembershipLevel }) =>
+ minimumAccessLevel > membershipLevel ? 'Project admin access is required' : null
+ )
+ window.POSTHOG_APP_CONTEXT = {
+ ...window.POSTHOG_APP_CONTEXT,
+ resource_access_control: { [AccessControlResourceType.CustomerAnalytics]: resourceLevel },
+ } as unknown as AppContext
+
+ render(<WarehousePersonPropertiesSetting />)
+
+ expect([...EDIT_ACTIONS, DELETE_ACTION].filter(isDisabled)).toEqual(disabledActions)
+ })
+})
diff --git a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/WarehousePersonPropertiesSetting.tsx b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/WarehousePersonPropertiesSetting.tsx
index 44155db2389a..985e3f33f7d5 100644
--- a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/WarehousePersonPropertiesSetting.tsx
+++ b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/WarehousePersonPropertiesSetting.tsx
@@ -8,9 +8,12 @@ import { TZLabel } from 'lib/components/TZLabel'
import { TeamMembershipLevel } from 'lib/constants'
import { LemonDialog } from 'lib/lemon-ui/LemonDialog'
import { LemonTag, LemonTagType } from 'lib/lemon-ui/LemonTag'
+import { getAccessControlDisabledReason } from 'lib/utils/accessControlUtils'
import { humanFriendlyNumber } from 'lib/utils/numbers'
import { urls } from 'scenes/urls'
+import { AccessControlLevel, AccessControlResourceType } from '~/types'
+
import type {
CustomPropertyDefinitionApi,
CustomPropertySourceApi,
@@ -69,10 +72,20 @@ function WarehouseProfilePropertiesSetting({ targetType }: { targetType: 'person
} = useValues(customPropertyDefinitionsLogic)
const { openCreateModal, openEditModal, deleteDefinition, triggerSync, triggerBackfill, setRunsSearch, loadRuns } =
useActions(customPropertyDefinitionsLogic)
- const restrictionReason = useRestrictedArea({
+ const memberRestrictionReason = useRestrictedArea({
+ scope: RestrictionScope.Project,
+ minimumAccessLevel: TeamMembershipLevel.Member,
+ })
+ const adminRestrictionReason = useRestrictedArea({
scope: RestrictionScope.Project,
minimumAccessLevel: TeamMembershipLevel.Admin,
})
+ const editorRestrictionReason = getAccessControlDisabledReason(
+ AccessControlResourceType.CustomerAnalytics,
+ AccessControlLevel.Editor
+ )
+ const restrictionReason = memberRestrictionReason ?? editorRestrictionReason
+ const deleteRestrictionReason = adminRestrictionReason ?? editorRestrictionReason
const labels = LABELS_BY_TARGET[targetType]
const profileDefinitions = definitions.filter((definition) => definition.target_type === targetType)
@@ -213,6 +226,7 @@ function WarehouseProfilePropertiesSetting({ targetType }: { targetType: 'person
size="small"
icon={<IconRefresh />}
tooltip="Sync now — re-runs the warehouse sync for this table"
+ data-attr="sync-warehouse-profile-property"
onClick={() => source && triggerSync({ sourceId: source.id })}
loading={triggering || running}
disabledReason={disabledReason}
@@ -220,6 +234,7 @@ function WarehouseProfilePropertiesSetting({ targetType }: { targetType: 'person
<LemonButton
size="small"
tooltip="Backfill — reads the whole table to fill in historical rows"
+ data-attr="backfill-warehouse-profile-property"
onClick={() => source && triggerBackfill({ sourceId: source.id })}
loading={triggering || running}
disabledReason={disabledReason}
@@ -230,6 +245,7 @@ function WarehouseProfilePropertiesSetting({ targetType }: { targetType: 'person
size="small"
icon={<IconPencil />}
tooltip="Edit"
+ data-attr="edit-warehouse-profile-property"
onClick={() => openEditModal(definition)}
disabledReason={restrictionReason}
/>
@@ -238,8 +254,9 @@ function WarehouseProfilePropertiesSetting({ targetType }: { targetType: 'person
status="danger"
icon={<IconTrash />}
tooltip="Delete"
+ data-attr="delete-warehouse-profile-property"
onClick={() => confirmDelete(definition)}
- disabledReason={restrictionReason}
+ disabledReason={deleteRestrictionReason}
/>
</div>
)
@@ -256,6 +273,7 @@ function WarehouseProfilePropertiesSetting({ targetType }: { targetType: 'person
// Lock the target: this page only manages one target, so the modal shouldn't offer
// the "Attach to" switch.
onClick={() => openCreateModal(targetType as CustomPropertyTargetType, true)}
+ data-attr="add-warehouse-profile-property"
disabledReason={restrictionReason}
>
Add {labels.entity} property