: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(rbac): narrow the access tags to the tools you filtered by (#85469)
Alex Lider9f88c55b280e
diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/AccessControlFilters.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/AccessControlFilters.tsxindex 5260468e061c..63faec7d0174 100644--- a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/AccessControlFilters.tsx+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/AccessControlFilters.tsx@@ -77,6 +77,7 @@ function RolesFilter(props: {<LemonDropdowncloseOnClickInside={false}placement="bottom-start"+ overflowHiddenoverlay={<MultiSelectFilterDropdowntitle="Role"@@ -111,6 +112,7 @@ function MembersFilter(props: {<LemonDropdowncloseOnClickInside={false}placement="bottom-start"+ overflowHiddenoverlay={<MultiSelectFilterDropdowntitle="Member"@@ -140,6 +142,7 @@ function ToolsFilter(props: {<LemonDropdowncloseOnClickInside={false}placement="bottom-start"+ overflowHiddenoverlay={<MultiSelectFilterDropdowntitle="Tool"@@ -166,6 +169,7 @@ function AccessLevelFilter(props: {<LemonDropdowncloseOnClickInside={false}placement="bottom-start"+ overflowHiddenoverlay={<MultiSelectFilterDropdowntitle="Access"diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/AccessControlTable.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/AccessControlTable.tsxindex 49e032fc86c0..a7f1b9954c12 100644--- a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/AccessControlTable.tsx+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/AccessControlTable.tsx@@ -12,7 +12,7 @@ import { APIScopeObject } from '~/types'import { getAccessSummaryTags, getEntryId, isMemberEntry, isRoleEntry } from './helpers'import { AccessControlSettingsEntry, AccessControlsTab } from './types'-const MAX_VISIBLE_RESOURCE_TAGS = 3+const MAX_VISIBLE_TAGS = 4function getScopeColumnsForTab(activeTab: AccessControlsTab): LemonTableColumns<AccessControlSettingsEntry> {switch (activeTab) {@@ -66,13 +66,21 @@ export interface AccessControlTableProps {loading: booleancanEditAny: booleanvisibleResources: Set<APIScopeObject>+ /** The tools selected in the Tool filter. They limit which tags each row shows. */+ filteredResources: Set<APIScopeObject>onEdit: (entry: AccessControlSettingsEntry) => void/** Entry whose detail is currently open, highlighted in the list */selectedEntryId?: string | null}export function AccessControlTable(props: AccessControlTableProps): JSX.Element {- const columns = getColumns(props.activeTab, props.canEditAny, props.visibleResources, props.onEdit)+ const columns = getColumns(+ props.activeTab,+ props.canEditAny,+ props.visibleResources,+ props.filteredResources,+ props.onEdit+ )return (<LemonTable@@ -104,32 +112,31 @@ export function AccessControlTable(props: AccessControlTableProps): JSX.Elementfunction AccessSummary({entry,visibleResources,+ filteredResources,}: {entry: AccessControlSettingsEntryvisibleResources: Set<APIScopeObject>+ filteredResources: Set<APIScopeObject>}): JSX.Element {- const tags = getAccessSummaryTags(entry, visibleResources)+ const tags = getAccessSummaryTags(entry, visibleResources, filteredResources)if (tags.length === 0) {return <span className="text-muted">No access configured</span>}- const projectTag = tags.find((t) => t.resource === 'project')- const resourceTags = tags.filter((t) => t.resource !== 'project')- const visibleResourceTags = resourceTags.slice(0, MAX_VISIBLE_RESOURCE_TAGS)- const hiddenCount = resourceTags.length - MAX_VISIBLE_RESOURCE_TAGS+ // The project tag comes first and counts towards the limit, so a row keeps the same width+ // whether or not the Tool filter removed it+ const visibleTags = tags.slice(0, MAX_VISIBLE_TAGS)+ const hiddenCount = tags.length - visibleTags.lengthreturn (<div className="flex gap-2 flex-wrap items-center">- {projectTag && (- <LemonTag key="project" type="default">- Project: {capitalizeFirstLetter(projectTag.level)}- </LemonTag>- )}- {visibleResourceTags.map(({ resource, level }) => (+ {visibleTags.map(({ resource, level }) => (<LemonTag key={resource} type="default">- {capitalizeFirstLetter(pluralizeResource(resource as APIScopeObject))}:{' '}- {capitalizeFirstLetter(level)}+ {resource === 'project'+ ? 'Project'+ : capitalizeFirstLetter(pluralizeResource(resource as APIScopeObject))}+ : {capitalizeFirstLetter(level)}</LemonTag>))}{hiddenCount > 0 && <span className="text-warning text-xs">+{hiddenCount} more</span>}@@ -141,6 +148,7 @@ function getColumns(activeTab: AccessControlsTab,canEditAny: boolean,visibleResources: Set<APIScopeObject>,+ filteredResources: Set<APIScopeObject>,onEdit: (entry: AccessControlSettingsEntry) => void): LemonTableColumns<AccessControlSettingsEntry> {const scopeColumns = getScopeColumnsForTab(activeTab)@@ -150,8 +158,18 @@ function getColumns({title: 'Access',key: 'resource',+ // This column takes the space that the other columns do not use. The other columns+ // then get the width of their content, and this one starts at the same position for+ // each filter.+ width: '100%',render: function RenderResource(_: any, entry: AccessControlSettingsEntry) {- return <AccessSummary entry={entry} visibleResources={visibleResources} />+ return (+ <AccessSummary+ entry={entry}+ visibleResources={visibleResources}+ filteredResources={filteredResources}+ />+ )},},{diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/AccessControls.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/AccessControls.tsxindex b2de99d247f4..da3e03db6dbb 100644--- a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/AccessControls.tsx+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/AccessControls.tsx@@ -33,6 +33,7 @@ export function AccessControls({ projectId }: { projectId: string }): JSX.Elemenloading,activePanelSubject,visibleResourceKeySet,+ filteredResourceKeySet,accessDetailPanelEnabled,ruleModalState,} = useValues(logic)@@ -89,6 +90,7 @@ export function AccessControls({ projectId }: { projectId: string }): JSX.Elemenloading={loading}canEditAny={canEdit}visibleResources={visibleResourceKeySet}+ filteredResources={filteredResourceKeySet}selectedEntryId={openInPanelId}onEdit={(entry) => {if (!accessDetailPanelEnabled) {diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/MultiselectFilterDropdown.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/MultiselectFilterDropdown.tsxindex 8a3e0e10969b..382e775204df 100644--- a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/MultiselectFilterDropdown.tsx+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/MultiselectFilterDropdown.tsx@@ -2,6 +2,8 @@ import { useMemo, useState } from 'react'import { LemonButton, LemonCheckbox, LemonInput, Link } from '@posthog/lemon-ui'+/** The option list scrolls itself, so give the dropdown that holds it `overflowHidden`. Without+ * that prop the popover wraps this in a second scroller, and the dropdown gets two scrollbars. */export function MultiSelectFilterDropdown<T extends string = string>(props: {title: stringplaceholder: string@@ -16,7 +18,7 @@ export function MultiSelectFilterDropdown<T extends string = string>(props: {}, [props.options, searchTerm])return (- <div className="w-96 flex flex-col min-h-0 overflow-hidden max-h-[80vh]">+ <div className="w-96 flex flex-col min-h-0 overflow-hidden max-h-full"><div className="p-2 border-b space-y-2"><div className="flex justify-between items-center"><span className="font-bold text-xs uppercase tracking-widest text-muted-alt">{props.title}</span>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.tsindex 730b786b06f0..ba726445a959 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@@ -125,6 +125,7 @@ export interface accessControlsLogicValues {defaults: AccessControlDefaultsResponse | nulldefaultsLoading: booleanfilteredMembers: AccessControlMemberEntry[]+ filteredResourceKeySet: Set<APIScopeObject>filteredRoles: AccessControlRoleEntry[]filters: AccessControlFiltersloading: boolean@@ -687,6 +688,7 @@ export interface accessControlsLogicMeta {label: string}[]) => Set<APIScopeObject>+ filteredResourceKeySet: (filters: AccessControlFilters) => Set<APIScopeObject>ruleOptions: (availableProjectLevels: AccessControlLevel[],availableResourceLevels: AccessControlLevel[]@@ -1240,6 +1242,10 @@ export const accessControlsLogic = kea<accessControlsLogicType>([}[]): Set<APIScopeObject> => new Set(resourceKeys.map((r) => r.key)),],+ filteredResourceKeySet: [+ (s) => [s.filters],+ (filters: AccessControlFilters): Set<APIScopeObject> => new Set(filters.resourceKeys),+ ],ruleOptions: [(s) => [s.availableProjectLevels, s.availableResourceLevels],diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/helpers.test.ts b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/helpers.test.tsindex 57335d0b7f96..3ccffc48019e 100644--- a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/helpers.test.ts+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/helpers.test.ts@@ -70,6 +70,14 @@ describe('helpers', () => {])})+ it('keeps only the picked tools, and drops the project tag, while the Tool filter has a selection', () => {+ const visibleResources = new Set<APIScopeObject>(['dashboard', 'tracing', 'insight'])+ const filteredResources = new Set<APIScopeObject>(['tracing'])+ expect(getAccessSummaryTags(roleEntry, visibleResources, filteredResources)).toEqual([+ { resource: 'tracing', level: AccessControlLevel.Viewer },+ ])+ })+it('omits the project tag when there is no effective project access', () => {const entry = { ...roleEntry, project: makeEffectiveEntry(null) }const visibleResources = new Set<APIScopeObject>(['dashboard'])diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/helpers.ts b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/helpers.tsindex f6f480615c98..844a556bb798 100644--- a/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/helpers.ts+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/access_control/ResourceAccessControlsV2/helpers.ts@@ -59,21 +59,30 @@ export interface AccessSummaryTag {}/** Builds the "Access" column tags for a role/member entry, excluding resources whose- * product isn't rolled out to the current user even if a stale access level exists for it. */+ * product isn't rolled out to the current user even if a stale access level exists for it.+ *+ * `filteredResources` are the tools selected in the Tool filter. If the set is not empty, the row+ * shows tags for those tools only, and no project tag. Each tag then answers the question the+ * filter asked. */export function getAccessSummaryTags(entry: AccessControlSettingsEntry,- visibleResources: Set<APIScopeObject>+ visibleResources: Set<APIScopeObject>,+ filteredResources?: Set<APIScopeObject>): AccessSummaryTag[] {const tags: AccessSummaryTag[] = []- if (entry.project.effective_access_level !== null) {+ if (!filteredResources?.size && entry.project.effective_access_level !== null) {tags.push({ resource: 'project', level: entry.project.effective_access_level })}for (const [resource, resourceEntry] of Object.entries(entry.resources)) {- if (resourceEntry.effective_access_level !== null && visibleResources.has(resource as APIScopeObject)) {- tags.push({ resource, level: resourceEntry.effective_access_level })+ if (resourceEntry.effective_access_level === null || !visibleResources.has(resource as APIScopeObject)) {+ continue}+ if (filteredResources?.size && !filteredResources.has(resource as APIScopeObject)) {+ continue+ }+ tags.push({ resource, level: resourceEntry.effective_access_level })}return tags