: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
feat: add access control for sharing (#69779)
Reece Jones7762b36989d4
diff --git a/common/storybook/.storybook/app-context.ts b/common/storybook/.storybook/app-context.tsindex b304115bff84..f1ca7fd5d2fa 100644--- a/common/storybook/.storybook/app-context.ts+++ b/common/storybook/.storybook/app-context.ts@@ -80,6 +80,7 @@ export const getStorybookAppContext = (): AppContext => ({insight: 'manager',notebook: 'manager',session_recording: 'manager',+ sharing_configuration: 'manager',revenue_analytics: 'manager',survey: 'manager',experiment: 'manager',diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex b9e2ef9d926e..5d8119d64439 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -6951,9 +6951,9 @@ snapshots:scenes-app-settings-authentication-domains--one-unverified-domain--light:hash: v1.k794b7964.b1ae6dbc8feb673159fcc13f4a8fd5ee856c63ad1204e839a1b55ef70d109c81.W5sqRIJDHcdkKlYg4ghfwpbKS2FmlQKF_N-1C83h9Mgscenes-app-settings-environment--settings-environment-access-control--dark:- hash: v1.k794b7964.b6467d3776787ff057f1eb4bdacc9093c2415dcffef48ea980adea4be8c43e82.MXGJGAjp2dstD7m6u3YyazpHV123edio0s6w2Y0KLeo+ hash: v1.k794b7964.35ab1c3442aaccdbb00253b12ad6089831b2209787d912bfc01f1a5abf755143.vVggYZAeyiGeJdZ8z_TKe4kK28uMUWsAJAMcPlkWalgscenes-app-settings-environment--settings-environment-access-control--light:- hash: v1.k794b7964.817a72022842741f5c0f2b753f5b8c4848e2a2dede3769c7765d50c4759a1cb2.zOYPokzZ1HMKazbAJst9k2K_GdUiHauNqJ8Bx3rm9VY+ hash: v1.k794b7964.3978b710d289d946d4edc8d7f40937b8c9150a6d8bbe8a4bdeb146f6fd407392.MuAto5ws3gu7dkA9fPauGjGoIrDkKuOE12h_D7DBoQQscenes-app-settings-environment--settings-environment-autocapture--dark:hash: v1.k794b7964.2183cf0082a1556d6df553572df4ab3813c96288a8b9a80e669c005908230c3e.-ybX8d6KyxaSa-yJDVccZm2CkK8Fl8qLSbw9jGhSIx4scenes-app-settings-environment--settings-environment-autocapture--light:diff --git a/frontend/src/generated/core/api.schemas.ts b/frontend/src/generated/core/api.schemas.tsindex 9f5924ee1b1b..00130c7cfd1b 100644--- a/frontend/src/generated/core/api.schemas.ts+++ b/frontend/src/generated/core/api.schemas.ts@@ -2710,6 +2710,9 @@ export interface SharePasswordApi {readonly is_active: boolean}+/**+ * Mixin for serializers to add user access control fields+ */export interface SharingConfigurationApi {readonly created_at: stringenabled?: boolean@@ -2718,6 +2721,11 @@ export interface SharingConfigurationApi {settings?: unknownpassword_required?: booleanreadonly share_passwords: readonly SharePasswordApi[]+ /**+ * The effective access level the user has for this object+ * @nullable+ */+ readonly user_access_level: string | null}export interface FileSystemApi {diff --git a/frontend/src/generated/core/api.zod.ts b/frontend/src/generated/core/api.zod.tsindex 04503059b989..5a5fc3dc22bb 100644--- a/frontend/src/generated/core/api.zod.ts+++ b/frontend/src/generated/core/api.zod.ts@@ -8913,17 +8913,21 @@ export const OrganizationsProjectsRotateSecretTokenPartialUpdateBody = /* @__PUR/*** Create a new password for the sharing configuration.*/-export const DashboardsSharingPasswordsCreateBody = /* @__PURE__ */ zod.object({- enabled: zod.boolean().optional(),- settings: zod.unknown().optional(),- password_required: zod.boolean().optional(),-})+export const DashboardsSharingPasswordsCreateBody = /* @__PURE__ */ zod+ .object({+ enabled: zod.boolean().optional(),+ settings: zod.unknown().optional(),+ password_required: zod.boolean().optional(),+ })+ .describe('Mixin for serializers to add user access control fields')-export const DashboardsSharingRefreshCreateBody = /* @__PURE__ */ zod.object({- enabled: zod.boolean().optional(),- settings: zod.unknown().optional(),- password_required: zod.boolean().optional(),-})+export const DashboardsSharingRefreshCreateBody = /* @__PURE__ */ zod+ .object({+ enabled: zod.boolean().optional(),+ settings: zod.unknown().optional(),+ password_required: zod.boolean().optional(),+ })+ .describe('Mixin for serializers to add user access control fields')/*** The file tree for the desktop product surface. Reuses all FileSystemViewSet behaviour but is@@ -9528,32 +9532,40 @@ export const FileSystemShortcutReorderCreateBody = /* @__PURE__ */ zod.object({/*** Create a new password for the sharing configuration.*/-export const InsightsSharingPasswordsCreateBody = /* @__PURE__ */ zod.object({- enabled: zod.boolean().optional(),- settings: zod.unknown().optional(),- password_required: zod.boolean().optional(),-})+export const InsightsSharingPasswordsCreateBody = /* @__PURE__ */ zod+ .object({+ enabled: zod.boolean().optional(),+ settings: zod.unknown().optional(),+ password_required: zod.boolean().optional(),+ })+ .describe('Mixin for serializers to add user access control fields')-export const InsightsSharingRefreshCreateBody = /* @__PURE__ */ zod.object({- enabled: zod.boolean().optional(),- settings: zod.unknown().optional(),- password_required: zod.boolean().optional(),-})+export const InsightsSharingRefreshCreateBody = /* @__PURE__ */ zod+ .object({+ enabled: zod.boolean().optional(),+ settings: zod.unknown().optional(),+ password_required: zod.boolean().optional(),+ })+ .describe('Mixin for serializers to add user access control fields')/*** Create a new password for the sharing configuration.*/-export const NotebooksSharingPasswordsCreateBody = /* @__PURE__ */ zod.object({- enabled: zod.boolean().optional(),- settings: zod.unknown().optional(),- password_required: zod.boolean().optional(),-})+export const NotebooksSharingPasswordsCreateBody = /* @__PURE__ */ zod+ .object({+ enabled: zod.boolean().optional(),+ settings: zod.unknown().optional(),+ password_required: zod.boolean().optional(),+ })+ .describe('Mixin for serializers to add user access control fields')-export const NotebooksSharingRefreshCreateBody = /* @__PURE__ */ zod.object({- enabled: zod.boolean().optional(),- settings: zod.unknown().optional(),- password_required: zod.boolean().optional(),-})+export const NotebooksSharingRefreshCreateBody = /* @__PURE__ */ zod+ .object({+ enabled: zod.boolean().optional(),+ settings: zod.unknown().optional(),+ password_required: zod.boolean().optional(),+ })+ .describe('Mixin for serializers to add user access control fields')export const ProductEnablementCreateBody = /* @__PURE__ */ zod.object({products: zod@@ -9680,17 +9692,21 @@ export const PropertyDefinitionsBulkUpdateTagsCreateBody = /* @__PURE__ */ zod.o/*** Create a new password for the sharing configuration.*/-export const SessionRecordingsSharingPasswordsCreateBody = /* @__PURE__ */ zod.object({- enabled: zod.boolean().optional(),- settings: zod.unknown().optional(),- password_required: zod.boolean().optional(),-})+export const SessionRecordingsSharingPasswordsCreateBody = /* @__PURE__ */ zod+ .object({+ enabled: zod.boolean().optional(),+ settings: zod.unknown().optional(),+ password_required: zod.boolean().optional(),+ })+ .describe('Mixin for serializers to add user access control fields')-export const SessionRecordingsSharingRefreshCreateBody = /* @__PURE__ */ zod.object({- enabled: zod.boolean().optional(),- settings: zod.unknown().optional(),- password_required: zod.boolean().optional(),-})+export const SessionRecordingsSharingRefreshCreateBody = /* @__PURE__ */ zod+ .object({+ enabled: zod.boolean().optional(),+ settings: zod.unknown().optional(),+ password_required: zod.boolean().optional(),+ })+ .describe('Mixin for serializers to add user access control fields')/*** Replace the authenticated user's profile and settings. Pass `@me` as the UUID to update the authenticated user. Prefer the PATCH endpoint for partial updates — PUT requires every writable field to be provided.diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/ScopeIcon.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/ScopeIcon.tsxindex 40c0344409bb..51881391a672 100644--- a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/ScopeIcon.tsx+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/ScopeIcon.tsx@@ -22,6 +22,7 @@ import {IconPulse,IconRewindPlay,IconRocket,+ IconShare,IconScatter,IconSpotlight,IconToggle,@@ -88,6 +89,8 @@ export function ScopeIcon(props: { scope: APIScopeObject }): JSX.Element | nullreturn <IconPiggyBank />case 'session_recording':return <IconRewindPlay />+ case 'sharing_configuration':+ return <IconShare />case 'survey':return <IconMessage />case 'task':diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/resourcesAccessControlLogic.ts b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/resourcesAccessControlLogic.tsindex 070d33a8dd23..50189b089a21 100644--- a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/resourcesAccessControlLogic.ts+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/resourcesAccessControlLogic.ts@@ -186,6 +186,7 @@ export const resourcesAccessControlLogic = kea<resourcesAccessControlLogicType>(AccessControlResourceType.Notebook,AccessControlResourceType.RevenueAnalytics,AccessControlResourceType.SessionRecording,+ AccessControlResourceType.SharingConfiguration,AccessControlResourceType.ErrorTracking,AccessControlResourceType.ReplayScanner,AccessControlResourceType.Survey,diff --git a/frontend/src/lib/components/Sharing/SharePasswordsTable.tsx b/frontend/src/lib/components/Sharing/SharePasswordsTable.tsxindex 69b36d0ac3a9..fd0295cbb44d 100644--- a/frontend/src/lib/components/Sharing/SharePasswordsTable.tsx+++ b/frontend/src/lib/components/Sharing/SharePasswordsTable.tsx@@ -15,6 +15,7 @@ interface SharePasswordsTableProps {insightId?: numberrecordingId?: stringnotebookShortId?: string+ disabledReason?: string | null}// Export a hook to get password count for the parent component@@ -29,6 +30,7 @@ export function SharePasswordsTable({insightId,recordingId,notebookShortId,+ disabledReason,}: SharePasswordsTableProps): JSX.Element {const logicProps = { dashboardId, insightId, recordingId, notebookShortId }const logic = sharePasswordsLogic(logicProps)@@ -78,6 +80,7 @@ export function SharePasswordsTable({size="xsmall"icon={<IconPlus />}onClick={() => setNewPasswordModalOpen(true)}+ disabledReason={disabledReason}>Add</LemonButton>@@ -125,8 +128,9 @@ export function SharePasswordsTable({},})}}- tooltip="Remove password"+ tooltip={disabledReason ? undefined : 'Remove password'}tooltipPlacement="left"+ disabledReason={disabledReason}/></div></div>diff --git a/frontend/src/lib/components/Sharing/SharingModal.tsx b/frontend/src/lib/components/Sharing/SharingModal.tsxindex 3dc913db9688..7ee5ee212900 100644--- a/frontend/src/lib/components/Sharing/SharingModal.tsx+++ b/frontend/src/lib/components/Sharing/SharingModal.tsx@@ -28,7 +28,7 @@ import { Spinner } from 'lib/lemon-ui/Spinner/Spinner'import { Tooltip } from 'lib/lemon-ui/Tooltip'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { preflightLogic } from 'lib/logic/preflightLogic'-import { accessLevelSatisfied } from 'lib/utils/accessControlUtils'+import { getAccessControlDisabledReason } from 'lib/utils/accessControlUtils'import { copyToClipboard } from 'lib/utils/copyToClipboard'import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'import { projectLogic } from 'scenes/projectLogic'@@ -48,7 +48,6 @@ import {} from '~/types'import { InsightType } from '~/types'-import { AccessControlAction } from '../AccessControlAction'import { upgradeModalLogic } from '../UpgradeModal/upgradeModalLogic'import { SharePasswordsTable } from './SharePasswordsTable'import { sharingLogic } from './sharingLogic'@@ -184,9 +183,26 @@ export function SharingModalContent({: notebookShortId? 'notebook': 'this'- const hasEditAccess = userAccessLevel- ? accessLevelSatisfied(resource as AccessControlResourceType, userAccessLevel, AccessControlLevel.Editor)- : true+ // Sharing requires editor access to the underlying resource being shared (enforced via+ // `userAccessLevel`, the object's own access level) AND editor access to the independent+ // `sharing_configuration` resource, which lets an org restrict who may manage public sharing+ // at all, regardless of how much access they have to the resource itself.+ const underlyingResourceDisabledReason = userAccessLevel+ ? getAccessControlDisabledReason(+ getResourceType(dashboardId, insightShortId, recordingId, notebookShortId),+ AccessControlLevel.Editor,+ userAccessLevel+ )+ : null+ const sharingConfigDisabledReason = sharingConfiguration?.user_access_level+ ? getAccessControlDisabledReason(+ AccessControlResourceType.SharingConfiguration,+ AccessControlLevel.Editor,+ sharingConfiguration.user_access_level+ )+ : null+ const sharingManageDisabledReason = underlyingResourceDisabledReason ?? sharingConfigDisabledReason+ const hasEditAccess = !sharingManageDisabledReasonuseEffect(() => {setIframeLoaded(false)@@ -229,27 +245,17 @@ export function SharingModalContent({{!sharingAllowed ? (<LemonBanner type="warning">Public sharing is disabled for this organization.</LemonBanner>) : (- <AccessControlAction- resourceType={getResourceType(- dashboardId,- insightShortId,- recordingId,- notebookShortId- )}- minAccessLevel={AccessControlLevel.Editor}- userAccessLevel={userAccessLevel}- >- <LemonSwitch- id="sharing-switch"- label={`Share ${resource} publicly`}- checked={sharingConfiguration.enabled}- data-attr="sharing-switch"- onChange={(active) => setIsEnabled(active)}- bordered- fullWidth- loading={sharingConfigurationLoading}- />- </AccessControlAction>+ <LemonSwitch+ id="sharing-switch"+ label={`Share ${resource} publicly`}+ checked={sharingConfiguration.enabled}+ data-attr="sharing-switch"+ onChange={(active) => setIsEnabled(active)}+ bordered+ fullWidth+ loading={sharingConfigurationLoading}+ disabledReason={sharingManageDisabledReason}+ />)}{sharingAllowed && sharingConfiguration.enabled && sharingConfiguration.access_token ? (@@ -280,6 +286,7 @@ export function SharingModalContent({}}}checked={sharingConfiguration.password_required}+ disabledReason={sharingManageDisabledReason}/>{sharingConfiguration.password_required && (<div className="mt-1 w-full">@@ -288,6 +295,7 @@ export function SharingModalContent({insightId={insight?.id}recordingId={recordingId}notebookShortId={notebookShortId}+ disabledReason={sharingManageDisabledReason}/></div>)}diff --git a/frontend/src/lib/utils/accessControlUtils.ts b/frontend/src/lib/utils/accessControlUtils.tsindex 9aedfe33c0dc..5f59c382b469 100644--- a/frontend/src/lib/utils/accessControlUtils.ts+++ b/frontend/src/lib/utils/accessControlUtils.ts@@ -82,6 +82,8 @@ export const pluralizeResource = (resource: APIScopeObject): string => {return 'metrics'} else if (resource === AccessControlResourceType.Tracing) {return 'tracing'+ } else if (resource === AccessControlResourceType.SharingConfiguration) {+ return 'sharing'} else if (resource === AccessControlResourceType.Toolbar) {return 'toolbar'} else if (resource === AccessControlResourceType.Workflow) {@@ -304,6 +306,9 @@ export const getAccessControlTooltip = (resource: APIScopeObject): string | nullif (resource === AccessControlResourceType.WarehouseObjects) {return 'Viewer is required to query a table or view via SQL. Editor and above also control creating, editing, and deleting tables, views (aka "models"), folders, and joins.'}+ if (resource === AccessControlResourceType.SharingConfiguration) {+ return 'Controls whether users can share resources like dashboards, insights, etc. with anyone via a public link.'+ }if (resource === AccessControlResourceType.Metrics) {return 'Controls access to the metrics product and its API. It does not restrict querying the underlying metrics tables with SQL.'}diff --git a/frontend/src/scenes/dashboard/DashboardHeaderActions.tsx b/frontend/src/scenes/dashboard/DashboardHeaderActions.tsxindex 713eff1f6196..f9aeedf062fa 100644--- a/frontend/src/scenes/dashboard/DashboardHeaderActions.tsx+++ b/frontend/src/scenes/dashboard/DashboardHeaderActions.tsx@@ -9,6 +9,7 @@ import { keyBinds } from 'lib/components/Shortcuts/shortcuts'import { FEATURE_FLAGS } from 'lib/constants'import { LemonButton } from 'lib/lemon-ui/LemonButton'import { LemonMenu, LemonMenuItem } from 'lib/lemon-ui/LemonMenu'+import { getAccessControlDisabledReason } from 'lib/utils/accessControlUtils'import { DashboardEventSource } from 'lib/utils/eventUsageLogic'import { MaxTool } from 'scenes/max/MaxTool'import { Scene } from 'scenes/sceneTypes'@@ -247,6 +248,11 @@ export function ViewModeActions(): JSX.Element {return <></>}+ const sharingDisabledReason = getAccessControlDisabledReason(+ AccessControlResourceType.SharingConfiguration,+ AccessControlLevel.Viewer+ )+return (<><DashboardSubscribeButton />@@ -256,7 +262,11 @@ export function ViewModeActions(): JSX.Element {onClick={() => push(urls.dashboardSharing(dashboard.id))}size="small"icon={<IconShare fontSize="16" />}- disabledReason={tiles.length === 0 ? 'Add at least one tile before sharing this dashboard' : undefined}+ disabledReason={+ tiles.length === 0+ ? 'Add at least one tile before sharing this dashboard'+ : (sharingDisabledReason ?? undefined)+ }>Share</LemonButton>diff --git a/frontend/src/scenes/insights/SidePanel/InsightPanelActions.tsx b/frontend/src/scenes/insights/SidePanel/InsightPanelActions.tsxindex e040822c5575..baf39595cef1 100644--- a/frontend/src/scenes/insights/SidePanel/InsightPanelActions.tsx+++ b/frontend/src/scenes/insights/SidePanel/InsightPanelActions.tsx@@ -64,6 +64,10 @@ export function InsightPanelActions({ insightLogicProps }: { insightLogicProps:AccessControlResourceType.Endpoint,AccessControlLevel.Editor)+ const sharingDisabledReason = getAccessControlDisabledReason(+ AccessControlResourceType.SharingConfiguration,+ AccessControlLevel.Viewer+ )const canExport = exportContext != null && insight.short_id != nullconst showCohort =hogQL != null &&@@ -139,11 +143,10 @@ export function InsightPanelActions({ insightLogicProps }: { insightLogicProps:onClick: () => push(urls.insightSharing(insight.short_id!)),}}dataAttrKey={RESOURCE_TYPE}- disabledReasons={- !isSavedInsight- ? { 'You must save the insight first before sharing it as a template': true }- : undefined- }+ disabledReasons={{+ 'You must save the insight first before sharing it as a template': !isSavedInsight,+ ...(sharingDisabledReason ? { [sharingDisabledReason]: true } : {}),+ }}/>{canExport ? (diff --git a/frontend/src/scenes/insights/SidePanel/InsightSceneMenuBar.tsx b/frontend/src/scenes/insights/SidePanel/InsightSceneMenuBar.tsxindex 113ca5dc8320..bb8c5f04d03c 100644--- a/frontend/src/scenes/insights/SidePanel/InsightSceneMenuBar.tsx+++ b/frontend/src/scenes/insights/SidePanel/InsightSceneMenuBar.tsx@@ -113,6 +113,10 @@ function InsightSceneMenuBarInner({ insightLogicProps }: { insightLogicProps: InAccessControlResourceType.Export,AccessControlLevel.Editor)+ const sharingDisabledReason = getAccessControlDisabledReason(+ AccessControlResourceType.SharingConfiguration,+ AccessControlLevel.Viewer+ )const isSavedInsight = hasDashboardItemId && !!insight?.id && !!insight?.short_idconst canExport = exportContext != null && insight.short_id != null@@ -230,6 +234,8 @@ function InsightSceneMenuBarInner({ insightLogicProps }: { insightLogicProps: In<SceneMenuBarItemonClick={() => push(urls.insightSharing(insight.short_id!))}data-attr={`${RESOURCE_TYPE}-menubar-share`}+ disabled={!!sharingDisabledReason}+ tooltip={sharingDisabledReason ?? undefined}><IconShare />Share or embeddiff --git a/frontend/src/scenes/notebooks/NotebookMenu.tsx b/frontend/src/scenes/notebooks/NotebookMenu.tsxindex 8cceac631cce..25dedbaeba73 100644--- a/frontend/src/scenes/notebooks/NotebookMenu.tsx+++ b/frontend/src/scenes/notebooks/NotebookMenu.tsx@@ -11,9 +11,11 @@ import {DropdownMenuItem,DropdownMenuTrigger,} from 'lib/ui/DropdownMenu/DropdownMenu'+import { getAccessControlDisabledReason } from 'lib/utils/accessControlUtils'import { urls } from 'scenes/urls'import { notebooksModel } from '~/models/notebooksModel'+import { AccessControlLevel, AccessControlResourceType } from '~/types'import { NotebookLogicProps, notebookLogic } from './Notebook/notebookLogic'@@ -22,6 +24,10 @@ export function NotebookMenu({ shortId, inPanel }: NotebookLogicProps & { inPaneconst { openShareModal, duplicateNotebook, downloadMarkdown, copyMarkdown, setShowHistory } = useActions(notebookLogic({ shortId }))+ const sharingDisabledReason = getAccessControlDisabledReason(+ AccessControlResourceType.SharingConfiguration,+ AccessControlLevel.Viewer+ )return (<DropdownMenu>@@ -57,7 +63,11 @@ export function NotebookMenu({ shortId, inPanel }: NotebookLogicProps & { inPane</ButtonPrimitive></DropdownMenuItem><DropdownMenuItem asChild>- <ButtonPrimitive onClick={() => openShareModal()} menuItem>+ <ButtonPrimitive+ onClick={() => openShareModal()}+ menuItem+ disabledReasons={sharingDisabledReason ? { [sharingDisabledReason]: true } : undefined}+ ><IconShare />Share</ButtonPrimitive>diff --git a/frontend/src/scenes/notebooks/NotebookSceneMenuBar.tsx b/frontend/src/scenes/notebooks/NotebookSceneMenuBar.tsxindex 7ed1ca570d36..c014134dfa12 100644--- a/frontend/src/scenes/notebooks/NotebookSceneMenuBar.tsx+++ b/frontend/src/scenes/notebooks/NotebookSceneMenuBar.tsx@@ -5,6 +5,7 @@ import { IconCopy, IconDownload, IconOpenSidebar, IconShare, IconTrash } from '@import { FEATURE_FLAGS } from 'lib/constants'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'+import { getAccessControlDisabledReason } from 'lib/utils/accessControlUtils'import { urls } from 'scenes/urls'import {@@ -16,6 +17,7 @@ import {SceneMenuBarSubMenu,} from '~/layout/scenes/components/SceneMenuBar'import { notebooksModel } from '~/models/notebooksModel'+import { AccessControlLevel, AccessControlResourceType } from '~/types'import { isMarkdownNotebookContent } from './Notebook/markdownNotebookV2'import { notebookLogic } from './Notebook/notebookLogic'@@ -44,6 +46,10 @@ function NotebookSceneMenuBarInner({ shortId }: { shortId: string }): JSX.Elemenconst canDelete = !isLocalOnly && !notebook?.is_template// The kernel info panel only renders for markdown (V2) notebooks, so hide the toggle elsewhereconst showKernelToggle = isKernelUiEnabled(featureFlags) && isMarkdownNotebookContent(content)+ const sharingDisabledReason = getAccessControlDisabledReason(+ AccessControlResourceType.SharingConfiguration,+ AccessControlLevel.Viewer+ )return (<SceneMenuBar>@@ -68,6 +74,8 @@ function NotebookSceneMenuBarInner({ shortId }: { shortId: string }): JSX.ElemenopensFloatingUionClick={() => openShareModal()}data-attr={`${RESOURCE_TYPE}-menubar-share`}+ disabled={!!sharingDisabledReason}+ tooltip={sharingDisabledReason ?? undefined}><IconShare />Sharediff --git a/frontend/src/scenes/session-recordings/player/share/PlayerShareMenu.tsx b/frontend/src/scenes/session-recordings/player/share/PlayerShareMenu.tsxindex 33e39fd0aac7..8c56e59a3cf0 100644--- a/frontend/src/scenes/session-recordings/player/share/PlayerShareMenu.tsx+++ b/frontend/src/scenes/session-recordings/player/share/PlayerShareMenu.tsx@@ -3,6 +3,7 @@ import { useActions, useValues } from 'kea'import { IconExternal, IconGlobe, IconShare, IconShield } from '@posthog/icons'import { LemonButton, LemonMenu } from '@posthog/lemon-ui'+import { getAccessControlDisabledReason } from 'lib/utils/accessControlUtils'import { newInternalTab } from 'lib/utils/newInternalTab'import { sessionPlayerModalLogic } from 'scenes/session-recordings/player/modal/sessionPlayerModalLogic'import { sessionRecordingPlayerLogic } from 'scenes/session-recordings/player/sessionRecordingPlayerLogic'@@ -10,10 +11,16 @@ import { openPlayerShareDialog } from 'scenes/session-recordings/player/share/Plimport { PlayerShareLogicProps } from 'scenes/session-recordings/player/share/playerShareLogic'import { urls } from 'scenes/urls'+import { AccessControlLevel, AccessControlResourceType } from '~/types'+export function PlayerShareMenu(): JSX.Element {const { sessionRecordingId, logicProps } = useValues(sessionRecordingPlayerLogic)const { setPause, setIsFullScreen } = useActions(sessionRecordingPlayerLogic)const { closeSessionPlayer } = useActions(sessionPlayerModalLogic())+ const sharingDisabledReason = getAccessControlDisabledReason(+ AccessControlResourceType.SharingConfiguration,+ AccessControlLevel.Viewer+ )const getCurrentPlayerTime = (): number => {// NOTE: We pull this value at call time as otherwise it would trigger re-renders if pulled from the hook@@ -79,6 +86,7 @@ export function PlayerShareMenu(): JSX.Element {label: 'Share public link',icon: <IconGlobe />,onClick: () => onShare('public'),+ disabledReason: sharingDisabledReason ?? undefined,'data-attr': 'share-public-link',},]}diff --git a/frontend/src/scenes/settings/organization/OrganizationSecuritySettings.tsx b/frontend/src/scenes/settings/organization/OrganizationSecuritySettings.tsxindex b1de45f35a76..18261d1c49b7 100644--- a/frontend/src/scenes/settings/organization/OrganizationSecuritySettings.tsx+++ b/frontend/src/scenes/settings/organization/OrganizationSecuritySettings.tsx@@ -32,7 +32,7 @@ export function OrganizationSecuritySettings(): JSX.Element | null {<LemonSwitchlabel={<span>- Allow publicly shared resources{' '}+ Enable publicly shared resources{' '}<Tooltip title="When disabled, sharing links and public dashboards will be blocked for this organization."><IconInfo className="mr-1" /></Tooltip>diff --git a/frontend/src/types.ts b/frontend/src/types.tsindex 3d8dbd7209a6..4afdf9f7e692 100644--- a/frontend/src/types.ts+++ b/frontend/src/types.ts@@ -295,6 +295,7 @@ export enum AccessControlResourceType {AiObservabilityClusters = 'ai_observability_clusters',Notebook = 'notebook',SessionRecording = 'session_recording',+ SharingConfiguration = 'sharing_configuration',RevenueAnalytics = 'revenue_analytics',Survey = 'survey',Logs = 'logs',@@ -5564,6 +5565,7 @@ export interface SharingConfigurationType {password_required: booleansettings?: SharingConfigurationSettingsshare_passwords?: SharePasswordType[]+ user_access_level?: AccessControlLevel}export enum ExporterFormat {diff --git a/posthog/api/sharing.py b/posthog/api/sharing.pyindex 2e51f79ccba8..8f51d3d6245b 100644--- a/posthog/api/sharing.py+++ b/posthog/api/sharing.py@@ -41,7 +41,12 @@ from posthog.models import SessionRecording, SharePassword, SharingConfigurationfrom posthog.models.activity_logging.activity_log import Change, Detail, log_activityfrom posthog.models.resource_transfer.visitors.insight import InsightVisitorfrom posthog.models.user import User-from posthog.rbac.user_access_control import UserAccessControl, access_level_satisfied_for_resource+from posthog.rbac.access_control_api_mixin import AccessControlViewSetMixin+from posthog.rbac.user_access_control import (+ UserAccessControl,+ UserAccessControlSerializerMixin,+ access_level_satisfied_for_resource,+)from posthog.scopes import APIScopeObjectfrom posthog.security.url_validation import is_url_allowedfrom posthog.session_recordings.session_recording_api import SessionRecordingSerializer@@ -313,14 +318,22 @@ class SharePasswordCreateSerializer(serializers.Serializer):return value-class SharingConfigurationSerializer(serializers.ModelSerializer):+class SharingConfigurationSerializer(UserAccessControlSerializerMixin, serializers.ModelSerializer):settings = serializers.JSONField(required=False, allow_null=True)share_passwords = serializers.SerializerMethodField()class Meta:model = SharingConfiguration- fields = ["created_at", "enabled", "access_token", "settings", "password_required", "share_passwords"]- read_only_fields = ["created_at", "access_token", "share_passwords"]+ fields = [+ "created_at",+ "enabled",+ "access_token",+ "settings",+ "password_required",+ "share_passwords",+ "user_access_level",+ ]+ read_only_fields = ["created_at", "access_token", "share_passwords", "user_access_level"]def validate_settings(self, value: Optional[dict[str, Any]]) -> Optional[dict[str, Any]]:if value is None:@@ -346,7 +359,9 @@ class SharingConfigurationSerializer(serializers.ModelSerializer):@extend_schema(extensions={"x-product": "core"})-class SharingConfigurationViewSet(TeamAndOrgViewSetMixin, mixins.ListModelMixin, viewsets.GenericViewSet):+class SharingConfigurationViewSet(+ TeamAndOrgViewSetMixin, AccessControlViewSetMixin, mixins.ListModelMixin, viewsets.GenericViewSet+):scope_object = "sharing_configuration"scope_object_write_actions = ["create",diff --git a/posthog/api/test/test_sharing.py b/posthog/api/test/test_sharing.pyindex f16263a3f098..73ae7d914ab9 100644--- a/posthog/api/test/test_sharing.py+++ b/posthog/api/test/test_sharing.py@@ -153,6 +153,7 @@ class TestSharing(APIBaseTest):"password_required": False,"settings": None,"share_passwords": [],+ "user_access_level": "editor",}@parameterized.expand(@@ -195,6 +196,7 @@ class TestSharing(APIBaseTest):"password_required": False,"settings": None,"share_passwords": [],+ "user_access_level": "editor",}response = self.client.patch(@@ -208,6 +210,7 @@ class TestSharing(APIBaseTest):"password_required": False,"settings": None,"share_passwords": [],+ "user_access_level": "editor",}@patch("products.exports.backend.api.exports.ExportedAssetSerializer._start_export_workflow")diff --git a/posthog/rbac/user_access_control.py b/posthog/rbac/user_access_control.pyindex 52e41b86fe92..8d1d8e6ac1fd 100644--- a/posthog/rbac/user_access_control.py+++ b/posthog/rbac/user_access_control.py@@ -75,6 +75,7 @@ ACCESS_CONTROL_RESOURCES: tuple[APIScopeObject, ...] = ("notebook","revenue_analytics","session_recording",+ "sharing_configuration","survey","web_analytics","activity_log",@@ -314,6 +315,8 @@ def model_to_resource(model: Model) -> Optional[APIScopeObject]:return "plugin"if name == "sessionrecording":return "session_recording"+ if name == "sharingconfiguration":+ return "sharing_configuration"if name == "exportedasset":return "export"if name == "sessionrecordingplaylist":diff --git a/posthog/session_recordings/test/test_session_recordings_sharing.py b/posthog/session_recordings/test/test_session_recordings_sharing.pyindex 5c1f48873bd3..5a371263364d 100644--- a/posthog/session_recordings/test/test_session_recordings_sharing.py+++ b/posthog/session_recordings/test/test_session_recordings_sharing.py@@ -177,6 +177,16 @@ class TestSessionRecordingsSharingAccessControl(APIBaseTest, ClickhouseTestMixinorganization_member=membership,)+ def _grant_sharing_configuration_access(self, access_level: str) -> None:+ membership = OrganizationMembership.objects.get(user=self.member_user, organization=self.organization)+ AccessControl.objects.create(+ team=self.team,+ resource="sharing_configuration",+ resource_id=None,+ access_level=access_level,+ organization_member=membership,+ )+@parameterized.expand([("viewer", status.HTTP_403_FORBIDDEN),@@ -194,3 +204,36 @@ class TestSessionRecordingsSharingAccessControl(APIBaseTest, ClickhouseTestMixin)assert response.status_code == expected_status, response.json()++ @parameterized.expand(+ [+ ("viewer", status.HTTP_403_FORBIDDEN),+ ("editor", status.HTTP_200_OK),+ ]+ )+ @freeze_time("2023-01-01T12:00:00Z")+ def test_enable_sharing_requires_editor_access_to_sharing_configuration_resource(+ self, access_level: str, expected_status: int+ ) -> None:+ # Editor access to the recording itself must not be sufficient on its own - the+ # sharing_configuration resource is gated independently, so an org can restrict who is+ # allowed to manage sharing without touching who can edit the underlying recording.+ self._grant_recording_access("editor")+ self._grant_sharing_configuration_access(access_level)+ self.client.force_login(self.member_user)++ response = self.client.patch(+ f"/api/projects/{self.team.id}/session_recordings/{self.session_id}/sharing",+ {"enabled": True},+ )++ assert response.status_code == expected_status, response.json()++ @freeze_time("2023-01-01T12:00:00Z")+ def test_sharing_response_exposes_user_access_level(self) -> None:+ self.client.force_login(self.member_user)++ response = self.client.get(f"/api/projects/{self.team.id}/session_recordings/{self.session_id}/sharing")++ assert response.status_code == status.HTTP_200_OK+ assert response.json()["user_access_level"] == "editor"diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 24c1f349bfbf..e832a54bdd00 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -60624,6 +60624,9 @@ export namespace Schemas {interview_url: string;}+ /**+ * Mixin for serializers to add user access control fields+ */export interface SharingConfiguration {readonly created_at: string;enabled?: boolean;@@ -60632,6 +60635,11 @@ export namespace Schemas {settings?: unknown;password_required?: boolean;readonly share_passwords: readonly SharePassword[];+ /**+ * The effective access level the user has for this object+ * @nullable+ */+ readonly user_access_level: string | null;}export interface ShipVariant {