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.

feat: allow removing an object-level access override (#74399)

Alex Lider911ae471ba05
diff --git a/ee/api/rbac/access_control.py b/ee/api/rbac/access_control.py
index 5abf469ea71d..efeb81a732da 100644
--- a/ee/api/rbac/access_control.py
+++ b/ee/api/rbac/access_control.py
@@ -1,4 +1,4 @@
-from typing import TYPE_CHECKING, cast
+from typing import TYPE_CHECKING, Any, cast
from rest_framework import exceptions, serializers, status
from rest_framework.decorators import action
@@ -14,6 +14,8 @@ from posthog.rbac.user_access_control import (
ACCESS_CONTROL_LEVELS_RESOURCE,
ACCESS_CONTROL_MAX_OBJECTS_PER_RESOURCE,
ACCESS_CONTROL_RESOURCES,
+ RESOURCE_INHERITANCE_MAP,
+ RESOURCES_WITHOUT_RESOURCE_LEVEL_CONTROLS,
AccessControlLevel,
AccessSource,
UserAccessControl,
@@ -283,20 +285,49 @@ class AccessControlViewSetMixin(_GenericViewSet):
serializer = self._get_access_control_serializer(instance=access_controls, many=True)
user_access_level = user_access_control.get_user_access_level(obj)
- return Response(
- {
- "access_controls": serializer.data,
- # NOTE: For resource level based controls we are always configuring resource level items
- "available_access_levels": ACCESS_CONTROL_LEVELS_RESOURCE
- if is_resource_level
- else ordered_access_levels(resource),
- "default_access_level": "editor" if is_resource_level else default_access_level(resource),
- "minimum_access_level": minimum_access_level(resource) if not is_resource_level else "none",
- "maximum_access_level": highest_access_level(resource) if not is_resource_level else "manager",
- "user_access_level": user_access_level,
- "user_can_edit_access_levels": user_access_control.check_can_modify_access_levels_for_object(obj),
- }
- )
+ payload: dict[str, Any] = {
+ "access_controls": serializer.data,
+ # NOTE: For resource level based controls we are always configuring resource level items
+ "available_access_levels": ACCESS_CONTROL_LEVELS_RESOURCE
+ if is_resource_level
+ else ordered_access_levels(resource),
+ "default_access_level": "editor" if is_resource_level else default_access_level(resource),
+ "minimum_access_level": minimum_access_level(resource) if not is_resource_level else "none",
+ "maximum_access_level": highest_access_level(resource) if not is_resource_level else "manager",
+ "user_access_level": user_access_level,
+ "user_can_edit_access_levels": user_access_control.check_can_modify_access_levels_for_object(obj),
+ }
+
+ if not is_resource_level:
+ # The level this object falls back to when it carries no default of its own, so the UI
+ # can spell out what removing the override means. Follows RESOURCE_INHERITANCE_MAP
+ # because that's the resource the runtime check consults — a warehouse view is gated by
+ # the warehouse_objects rules, not by its own.
+ #
+ # None for a project is load-bearing: it is what stops the UI offering "No override" on
+ # a project's own default, which has nothing above it to fall back to. "No override"
+ # belongs to object defaults only — project-level access is configured in its own
+ # panel, which has no inherited tier to fall back to.
+ inherited_resource = (
+ None
+ if resource in RESOURCES_WITHOUT_RESOURCE_LEVEL_CONTROLS
+ else RESOURCE_INHERITANCE_MAP.get(resource, resource)
+ )
+ payload["inherited_resource"] = inherited_resource
+ payload["inherited_access_level"] = None
+ if inherited_resource:
+ everyone_rule = AccessControl.objects.filter(
+ team=team,
+ resource=inherited_resource,
+ resource_id=None,
+ organization_member=None,
+ role=None,
+ ).first()
+ payload["inherited_access_level"] = (
+ everyone_rule.access_level if everyone_rule else default_access_level(inherited_resource)
+ )
+
+ return Response(payload)
def _get_users_with_access(self, request: Request):
"""
diff --git a/ee/api/rbac/test/test_access_control.py b/ee/api/rbac/test/test_access_control.py
index 7e5182fa4724..7214974619a4 100644
--- a/ee/api/rbac/test/test_access_control.py
+++ b/ee/api/rbac/test/test_access_control.py
@@ -10,6 +10,7 @@ from posthog.models.personal_api_key import PersonalAPIKey
from posthog.models.team.team import Team
from posthog.models.utils import generate_random_token_personal, hash_key_value
from posthog.rbac.user_access_control import AccessSource
+from posthog.session_recordings.models.session_recording_playlist import SessionRecordingPlaylist
from posthog.utils import render_template
from products.cohorts.backend.models.cohort import Cohort
@@ -264,8 +265,50 @@ class TestAccessControlResourceLevelAPI(BaseAccessControlTest):
"user_can_edit_access_levels": True,
"minimum_access_level": "none",
"maximum_access_level": "manager",
+ "inherited_resource": "notebook",
+ # No project-wide rule for notebooks, so the resource's built-in default applies
+ "inherited_access_level": "editor",
}
+ def test_get_access_controls_resolves_the_project_wide_level_it_falls_back_to(self):
+ self._org_membership(OrganizationMembership.Level.ADMIN)
+ role = Role.objects.create(name="Engineering", organization=self.organization)
+ for payload in [
+ {"resource": "notebook", "access_level": "viewer"},
+ # Role rules grant to role members only — they must not be reported as the everyone-level
+ {"resource": "notebook", "access_level": "editor", "role": str(role.id)},
+ # A rule on another resource must not leak into this notebook's fallback
+ {"resource": "dashboard", "access_level": "none"},
+ ]:
+ res = self._put_global_access_control(payload)
+ assert res.status_code == status.HTTP_200_OK, res.json()
+
+ res = self._get_access_controls()
+ assert res.status_code == status.HTTP_200_OK, res.json()
+ assert res.json()["inherited_resource"] == "notebook"
+ assert res.json()["inherited_access_level"] == "viewer"
+
+ def test_inherited_resource_follows_the_resource_it_actually_inherits_from(self):
+ self._org_membership(OrganizationMembership.Level.ADMIN)
+ res = self._put_global_access_control({"resource": "session_recording", "access_level": "viewer"})
+ assert res.status_code == status.HTTP_200_OK, res.json()
+ playlist = SessionRecordingPlaylist.objects.create(team=self.team, created_by=self.user, short_id="abc123")
+
+ res = self.client.get(f"/api/projects/@current/session_recording_playlists/{playlist.short_id}/access_controls")
+ assert res.status_code == status.HTTP_200_OK, res.json()
+ # Playlists are gated by the session_recording rules, so that's what "no override" falls back to
+ assert res.json()["inherited_resource"] == "session_recording"
+ assert res.json()["inherited_access_level"] == "viewer"
+
+ def test_project_reports_no_inherited_level(self):
+ self._org_membership(OrganizationMembership.Level.ADMIN)
+ res = self.client.get("/api/projects/@current/access_controls")
+ assert res.status_code == status.HTTP_200_OK, res.json()
+ # Nothing sits above a project, so it must report no inherited level — that absence is what
+ # keeps "No override" an object-default affordance rather than a project-level one
+ assert res.json()["inherited_resource"] is None
+ assert res.json()["inherited_access_level"] is None
+
def test_change_rejected_if_not_org_admin(self):
self._org_membership(OrganizationMembership.Level.MEMBER)
res = self._put_access_control(notebook_id=self.other_user_notebook.short_id)
diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/AccessControlObject.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/AccessControlObject.tsx
index 2193ce5300d7..01fc70d6943b 100644
--- a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/AccessControlObject.tsx
+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/AccessControlObject.tsx
@@ -9,6 +9,7 @@ import {
LemonInputSelect,
LemonModal,
LemonSelect,
+ LemonSelectOption,
LemonSelectProps,
LemonTable,
Tooltip,
@@ -21,7 +22,7 @@ import { LemonTableColumns } from 'lib/lemon-ui/LemonTable'
import { LemonTableLink } from 'lib/lemon-ui/LemonTable/LemonTableLink'
import { ProfileBubbles, ProfilePicture } from 'lib/lemon-ui/ProfilePicture'
import { getAccessControlTooltip } from 'lib/utils/accessControlUtils'
-import { capitalizeFirstLetter, fullName } from 'lib/utils/strings'
+import { fullName } from 'lib/utils/strings'
import { urls } from 'scenes/urls'
import { userLogic } from 'scenes/userLogic'
@@ -36,7 +37,8 @@ import {
RoleType,
} from '~/types'
-import { AccessControlLogicProps, accessControlLogic } from './accessControlLogic'
+import { AccessControlLogicProps, InheritedAccess, accessControlLogic } from './accessControlLogic'
+import { humanizeAccessControlLevel } from './ResourceAccessControlsV2/helpers'
export function AccessControlObject(props: AccessControlLogicProps): JSX.Element | null {
const { canEditAccessControls, humanReadableResource, resource } = useValues(accessControlLogic(props))
@@ -87,25 +89,28 @@ export function AccessControlObject(props: AccessControlLogicProps): JSX.Element
}
function AccessControlObjectDefaults(): JSX.Element | null {
- const { accessControlDefault, accessControlDefaultOptions, accessControlsLoading, canEditAccessControls } =
+ const { accessControlDefault, accessControls, accessControlsLoading, availableLevelsWithNone, inheritedAccess } =
useValues(accessControlLogic)
const { updateAccessControlDefault } = useActions(accessControlLogic)
const { guardAvailableFeature } = useValues(upgradeModalLogic)
+ if (!accessControls) {
+ // A null level is a real state ("No override") for this select, so it can't double as
+ // the loading state the way it does elsewhere — loading needs its own placeholder
+ return <LemonSelect placeholder="Loading..." disabledReason="Loading…" options={[]} />
+ }
+
return (
- <LemonSelect
- placeholder="Loading..."
- value={accessControlDefault?.access_level ?? undefined}
+ <SimplLevelComponent
+ level={accessControlDefault?.access_level ?? null}
+ levels={availableLevelsWithNone}
+ inherited={inheritedAccess}
+ disabledReason={accessControlsLoading ? 'Loading…' : undefined}
onChange={(newValue) => {
guardAvailableFeature(AvailableFeature.ACCESS_CONTROL, () => {
- updateAccessControlDefault(newValue as AccessControlLevel)
+ updateAccessControlDefault(newValue)
})
}}
- disabledReason={
- accessControlsLoading ? 'Loading…' : !canEditAccessControls ? 'You cannot edit this' : undefined
- }
- dropdownMatchSelectWidth={false}
- options={accessControlDefaultOptions}
/>
)
}
@@ -374,28 +379,80 @@ function SimplLevelComponent(props: {
size?: LemonSelectProps<any>['size']
level: AccessControlLevel | null
levels: AccessControlLevel[]
- onChange: (newValue: AccessControlLevel) => void
+ onChange: (newValue: AccessControlLevel | null) => void
disabled?: boolean
+ disabledReason?: string
+ /**
+ * What applies once the rule is removed. Passing it offers "No override" as a way back, so
+ * only the object default sets it — member and role rows are removed with their own button.
+ */
+ inherited?: InheritedAccess | null
}): JSX.Element | null {
const { canEditAccessControls, minimumAccessLevel } = useValues(accessControlLogic)
+ const { inherited } = props
+
+ // The trigger and the menu entry read identically, so what you pick is what you end up looking at.
+ // The inherited half drops to the button's normal weight so it reads as a consequence, not a second value.
+ const noOverrideLabel = inherited ? (
+ <span className="whitespace-nowrap">
+ No override <span className="font-normal text-tertiary">· {inherited.label}</span>
+ </span>
+ ) : null
+
+ const levelOptions: LemonSelectOption<AccessControlLevel | null>[] = props.levels.map((level) => {
+ const isDisabled = minimumAccessLevel
+ ? props.levels.indexOf(level) < props.levels.indexOf(minimumAccessLevel)
+ : false
+ return {
+ value: level,
+ label: humanizeAccessControlLevel(level),
+ disabledReason: isDisabled ? 'Not available for this resource type' : undefined,
+ }
+ })
return (
- <LemonSelect
+ <LemonSelect<AccessControlLevel | null>
size={props.size}
placeholder="Select level..."
value={props.level}
- onChange={(newValue) => props.onChange(newValue as AccessControlLevel)}
- disabledReason={!canEditAccessControls || props.disabled ? 'You cannot edit this' : undefined}
- options={props.levels.map((level) => {
- const isDisabled = minimumAccessLevel
- ? props.levels.indexOf(level) < props.levels.indexOf(minimumAccessLevel)
- : false
- return {
- value: level,
- label: capitalizeFirstLetter(level ?? ''),
- disabledReason: isDisabled ? 'Not available for this resource type' : undefined,
- }
- })}
+ onChange={props.onChange}
+ // The permission gate wins over any caller-supplied reason, so a reason passed for
+ // some other purpose can never re-enable the control for someone who cannot edit
+ disabledReason={!canEditAccessControls || props.disabled ? 'You cannot edit this' : props.disabledReason}
+ dropdownMatchSelectWidth={false}
+ tooltip={
+ inherited
+ ? props.level === null
+ ? inherited.reason
+ : `Overrides ${inherited.label}. ${inherited.reason}.`
+ : undefined
+ }
+ renderButtonContent={
+ noOverrideLabel ? (leaf) => (props.level === null ? noOverrideLabel : (leaf?.label ?? '')) : undefined
+ }
+ options={
+ inherited
+ ? [
+ {
+ options: [
+ {
+ value: null,
+ label: 'No override',
+ labelInMenu: (
+ <div className="flex flex-col items-start gap-1 py-1">
+ {noOverrideLabel}
+ <span className="text-xs font-normal text-tertiary whitespace-nowrap">
+ {inherited.reason}
+ </span>
+ </div>
+ ),
+ },
+ ],
+ },
+ { options: levelOptions },
+ ]
+ : levelOptions
+ }
/>
)
}
@@ -442,7 +499,7 @@ function AddItemsControlsModal(props: {
const { availableLevels, canEditAccessControls } = useValues(accessControlLogic)
// TODO: Move this into a form logic
const [items, setItems] = useState<string[]>([])
- const [level, setLevel] = useState<AccessControlLevel>(availableLevels[0] ?? null)
+ const [level, setLevel] = useState<AccessControlLevel | null>(availableLevels[0] ?? null)
useEffect(() => {
setLevel(availableLevels[0] ?? null)
diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/accessControlsLogic.ts b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/accessControlsLogic.ts
index 4ec99cd30b6c..6a9fad5e23a8 100644
--- a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/accessControlsLogic.ts
+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/accessControlsLogic.ts
@@ -129,24 +129,24 @@ export interface accessControlsLogicValues {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface accessControlsLogicActions {
updateAccessControlDefault: (
- level: AccessControlLevel,
+ level: AccessControlLevel | null,
source?: AccessControlUIVersion | undefined
) => {
- level: AccessControlLevel
+ level: AccessControlLevel | null
source: AccessControlUIVersion
} // accessControlLogic
updateAccessControlDefaultSuccess: (
accessControls: AccessControlResponseType | null,
payload?:
| {
- level: AccessControlLevel
+ level: AccessControlLevel | null
source: AccessControlUIVersion
}
| undefined
) => {
accessControls: AccessControlResponseType | null
payload?: {
- level: AccessControlLevel
+ level: AccessControlLevel | null
source: AccessControlUIVersion
}
} // accessControlLogic
diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/accessControlLogic.ts b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/accessControlLogic.ts
index 5139367a1605..e64c4af6e32c 100644
--- a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/accessControlLogic.ts
+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/accessControlLogic.ts
@@ -1,13 +1,10 @@
import { MakeLogicType, actions, afterMount, connect, kea, key, listeners, path, props, selectors } from 'kea'
import { loaders } from 'kea-loaders'
-import { LemonSelectOption } from '@posthog/lemon-ui'
-
import api from 'lib/api'
import { upgradeModalLogic } from 'lib/components/UpgradeModal/upgradeModalLogic'
import { OrganizationMembershipLevel } from 'lib/constants'
-import { AccessControlUIVersion, captureAccessControlEvent } from 'lib/utils/accessControlUtils'
-import { toSentenceCase } from 'lib/utils/strings'
+import { AccessControlUIVersion, captureAccessControlEvent, pluralizeResource } from 'lib/utils/accessControlUtils'
import { membersLogic } from 'scenes/organization/membersLogic'
import { teamLogic } from 'scenes/teamLogic'
@@ -26,6 +23,7 @@ import {
} from '~/types'
import type { GuardAvailableFeatureFn } from '../../../../../lib/components/UpgradeModal/upgradeModalLogic'
+import { humanizeAccessControlLevel } from './ResourceAccessControlsV2/helpers'
import { roleAccessControlLogic } from './roleAccessControlLogic'
export type AccessControlLogicProps = {
@@ -35,15 +33,21 @@ export type AccessControlLogicProps = {
description: string
}
+/** The access level that applies while a rule carries no override, and where it comes from. */
+export type InheritedAccess = {
+ /** The inherited level as shown to a user, e.g. "No access" rather than "none". */
+ label: string
+ /** One line naming the rule the level comes from, shown in the tooltip and the menu entry. */
+ reason: string
+}
+
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface accessControlLogicValues {
sortedMembers: OrganizationMemberType[] | null // membersLogic
roles: RoleType[] // roleAccessControlLogic
currentProjectId: number | string // teamLogic
guardAvailableFeature: GuardAvailableFeatureFn // upgradeModalLogic
- accessControlDefault: AccessControlTypeProject
- accessControlDefaultLevel: string | null
- accessControlDefaultOptions: LemonSelectOption<string>[]
+ accessControlDefault: AccessControlTypeProject | null
accessControlMembers: (AccessControlTypeMember | AccessControlTypeOrganizationAdmins)[]
accessControlRoles: AccessControlTypeRole[]
accessControls: AccessControlResponseType | null
@@ -55,6 +59,7 @@ export interface accessControlLogicValues {
canEditAccessControls: boolean | null
endpoint: string
humanReadableResource: string
+ inheritedAccess: InheritedAccess | null
membersById: Record<string, OrganizationMemberType>
minimumAccessLevel: AccessControlLevel | null
organizationAdmins: OrganizationMemberType[]
@@ -189,10 +194,10 @@ export interface accessControlLogicActions {
accessControl: Pick<AccessControlType, 'access_level' | 'organization_member' | 'role'>
}
updateAccessControlDefault: (
- level: AccessControlLevel,
+ level: AccessControlLevel | null,
source?: AccessControlUIVersion
) => {
- level: AccessControlLevel
+ level: AccessControlLevel | null
source: AccessControlUIVersion
}
updateAccessControlDefaultFailure: (
@@ -205,13 +210,13 @@ export interface accessControlLogicActions {
updateAccessControlDefaultSuccess: (
accessControls: AccessControlResponseType | null,
payload?: {
- level: AccessControlLevel
+ level: AccessControlLevel | null
source: AccessControlUIVersion
}
) => {
accessControls: AccessControlResponseType | null
payload?: {
- level: AccessControlLevel
+ level: AccessControlLevel | null
source: AccessControlUIVersion
}
}
@@ -740,16 +745,8 @@ export interface accessControlLogicMeta {
availableLevelsWithNone: (accessControls: AccessControlResponseType | null) => AccessControlLevel[]
availableLevels: (availableLevelsWithNone: AccessControlLevel[]) => AccessControlLevel[]
canEditAccessControls: (accessControls: AccessControlResponseType | null) => boolean | null
- accessControlDefaultLevel: (accessControls: AccessControlResponseType | null) => string | null
- accessControlDefaultOptions: (
- availableLevelsWithNone: AccessControlLevel[],
- minimumAccessLevel: AccessControlLevel | null,
- arg: any
- ) => LemonSelectOption<string>[]
- accessControlDefault: (
- accessControls: AccessControlResponseType | null,
- accessControlDefaultLevel: string | null
- ) => AccessControlTypeProject
+ accessControlDefault: (accessControls: AccessControlResponseType | null) => AccessControlTypeProject | null
+ inheritedAccess: (accessControls: AccessControlResponseType | null) => InheritedAccess | null
organizationAdmins: (sortedMembers: OrganizationMemberType[] | null) => OrganizationMemberType[]
organizationAdminsAsAccessControlMember: (
organizationAdmins: OrganizationMemberType[]
@@ -798,7 +795,7 @@ export const accessControlLogic = kea<accessControlLogicType>([
updateAccessControl: (
accessControl: Pick<AccessControlType, 'access_level' | 'organization_member' | 'role'>
) => ({ accessControl }),
- updateAccessControlDefault: (level: AccessControlLevel, source: AccessControlUIVersion = 'v1') => ({
+ updateAccessControlDefault: (level: AccessControlLevel | null, source: AccessControlUIVersion = 'v1') => ({
level,
source,
}),
@@ -1281,49 +1278,37 @@ export const accessControlLogic = kea<accessControlLogicType>([
},
],
- accessControlDefaultLevel: [
+ // The object's own default rule, or null when the object has no override and therefore
+ // falls back to the project-wide rules (see inheritedAccess).
+ accessControlDefault: [
(s) => [s.accessControls],
- (accessControls: AccessControlResponseType | null): string | null => {
- return accessControls?.default_access_level ?? null
- },
- ],
-
- accessControlDefaultOptions: [
- (s) => [s.availableLevelsWithNone, s.minimumAccessLevel, (_, props) => props.resource],
- (
- availableLevelsWithNone: AccessControlLevel[],
- minimumAccessLevel: AccessControlLevel | null
- ): LemonSelectOption<string>[] => {
- const options = availableLevelsWithNone.map((level) => {
- const isDisabled = minimumAccessLevel
- ? availableLevelsWithNone.indexOf(level) < availableLevelsWithNone.indexOf(minimumAccessLevel)
- : false
- return {
- value: level,
- // TODO: Correct "a" and "an"
- label: level === 'none' ? 'No access' : toSentenceCase(level),
- disabledReason: isDisabled ? 'Not available for this resource type' : undefined,
- }
- })
-
- return options
+ (accessControls: AccessControlResponseType | null): AccessControlTypeProject | null => {
+ return (
+ (accessControls?.access_controls?.find(
+ (accessControl) => !accessControl.organization_member && !accessControl.role
+ ) as AccessControlTypeProject) ?? null
+ )
},
],
- accessControlDefault: [
- (s) => [s.accessControls, s.accessControlDefaultLevel],
- (
- accessControls: AccessControlResponseType | null,
- accessControlDefaultLevel: string | null
- ): AccessControlTypeProject => {
- const found = accessControls?.access_controls?.find(
- (accessControl) => !accessControl.organization_member && !accessControl.role
- ) as AccessControlTypeProject
- return (
- found ?? {
- access_level: accessControlDefaultLevel,
- }
- )
+ // What the object falls back to with no default of its own: the project's rule for
+ // everyone, or the resource's built-in level when the project sets no rule at all.
+ // A null inherited_resource means nothing sits above this object, so there is no
+ // "No override" to offer — a project's own default is the case that hits.
+ inheritedAccess: [
+ (s) => [s.accessControls],
+ (accessControls: AccessControlResponseType | null): InheritedAccess | null => {
+ const inheritedResource = accessControls?.inherited_resource
+ const inheritedLevel = accessControls?.inherited_access_level
+ if (!inheritedResource || !inheritedLevel) {
+ return null
+ }
+ return {
+ label: humanizeAccessControlLevel(inheritedLevel),
+ // A configured project rule and the built-in fallback are both "the default
+ // for <resource>", so one reason covers them without claiming someone set it
+ reason: `Based on the default for ${pluralizeResource(inheritedResource)}`,
+ }
},
],
diff --git a/frontend/src/types.ts b/frontend/src/types.ts
index d2230f2c7a8f..08791d9cffe1 100644
--- a/frontend/src/types.ts
+++ b/frontend/src/types.ts
@@ -5894,6 +5894,11 @@ export type AccessControlResponseType = {
default_access_level: AccessControlLevel
minimum_access_level?: AccessControlLevel
user_can_edit_access_levels: boolean
+ /** Resource whose project-wide rules apply while the object carries no override of its own. */
+ inherited_resource?: APIScopeObject | null
+ /** The level that applies while the object carries no override: the project-wide rule for
+ * `inherited_resource`, or its built-in default when no rule is set. */
+ inherited_access_level?: AccessControlLevel | null
}
export type InheritedAccessLevelReason = 'project_default' | 'role_override' | 'organization_admin'
diff --git a/posthog/rbac/user_access_control.py b/posthog/rbac/user_access_control.py
index e81a4a3a1483..defe6caf8820 100644
--- a/posthog/rbac/user_access_control.py
+++ b/posthog/rbac/user_access_control.py
@@ -94,6 +94,10 @@ ACCESS_CONTROL_RESOURCES: tuple[APIScopeObject, ...] = (
"llm_playground",
)
+# Resources whose access comes from membership rather than resource-level AccessControl rows,
+# so nothing sits above an object of this type to fall back to
+RESOURCES_WITHOUT_RESOURCE_LEVEL_CONTROLS: frozenset[APIScopeObject] = frozenset({"organization", "project", "plugin"})
+
# Resource inheritance mapping - child resources inherit access from parent resources
RESOURCE_INHERITANCE_MAP: dict[APIScopeObject, APIScopeObject] = {
"session_recording_playlist": "session_recording",
@@ -954,8 +958,7 @@ class UserAccessControl:
# Use parent resource for access control checks
return self.access_level_for_resource(parent_resource)
- # These are resources which we don't have resource level access controls for
- if resource == "organization" or resource == "project" or resource == "plugin":
+ if resource in RESOURCES_WITHOUT_RESOURCE_LEVEL_CONTROLS:
return default_access_level(resource)
org_membership = self._organization_membership